arcgis开发笔记【打印】

Web打印

从网上找了一些关于asp.net打印的资料,参考“关于Web打印”,参考

http://cid-56b433ad3d1871e3.skydrive.live.com/self.aspx/.Public/%e5%85%b3%e4%ba%8eWEB%e6%89%93%e5%8d%b0.docx

最后选择了使用ReportViewer实现打印功能

arcgis silverlight内容的打印

实现思路:

silveilight程序中把页面中需要打印的对象转换成图形base64编码的字符流,提交到服务端

服务端处理程序把这些二进制字符流邦定到ReportViewer控件上,然后由ReportViewer实现打印的展现功能,具体如下:

HOST silverlight的页面

 

SilverLight提交打印请求

private void Button_Click(object sender, RoutedEventArgs e)    
{        
  WriteableBitmap bitmap = new WriteableBitmap(this.gridTest, new TranslateTransform());             EditableImage image = new EditableImage(bitmap.PixelWidth, bitmap.PixelHeight);       
 for (int i = 0; i < bitmap.PixelHeight; i++)       
 {           
 for (int j = 0; j < bitmap.PixelWidth; j++)            
{              
  int num3 = bitmap.Pixels[(bitmap.PixelWidth * i) + j];           
     image.SetPixel(j, i, (byte) ((num3 >> 0x10) & 0xff), (byte) ((num3 >> 8) & 0xff), (byte) (num3 & 0xff), (byte) ((num3 >> 0x18) & 0xff));           
 }     
   }    
    Stream stream = image.GetStream();      
  byte[] buffer = new byte[stream.Length];  
      long num4 = stream.Read(buffer, 0, (int) stream.Length);    
    string str = Convert.ToBase64String(buffer, 0, buffer.Length);        HtmlPage.Document.GetElementById("prText").SetProperty("value", str);        HtmlPage.Document.GetElementById("prBtn").Invoke("click", null);  
  }


  打印页面和处理逻辑:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="print.aspx.cs" Inherits="GisSite.Rpt.PrintPreview" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%" Height="600px">

</rsweb:ReportViewer>

</form>

</body>

</html>

// Methods    
private void FillReport(string bytes64)    
{     
   byte[] imageBytes = Convert.FromBase64String(bytes64);    
    printImg.ImageDataDataTable dt = new printImg.ImageDataDataTable();   
     dt.AddImageDataRow(0, "print", imageBytes);        
     this.ReportViewer1.LocalReport.ReportPath ="Rpt/print.rdlc";    
    ReportDataSource src = new ReportDataSource("DSReportPrintImage_ImageData", dt);    
    this.ReportViewer1.LocalReport.DataSources.Add(src);        
    this.ReportViewer1.LocalReport.Refresh();    
}    
 protected void Page_Load(object sender, EventArgs e)   
 {       
 if (!this.Page.IsPostBack)     
   {           
       string bytes64 = base.Request["prText"];     
       if (!string.IsNullOrEmpty(bytes64))           
      {               
           this.FillReport(bytes64);            
      }       
 }   
 }

 

print .RDLC文件

<?xml version="1.0" encoding="utf-8"?>

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">

<DataSources>

<DataSource Name="DummyDataSource">

<rd:DataSourceID>6dde20a2-6fdf-4054-a23d-0135e6a9e8a4</rd:DataSourceID>

<ConnectionProperties>

<DataProvider>SQL</DataProvider>

<ConnectString />

</ConnectionProperties>

</DataSource>

</DataSources>

<InteractiveHeight>11in</InteractiveHeight>

<rd:DrawGrid>true</rd:DrawGrid>

<InteractiveWidth>8.5in</InteractiveWidth>

<rd:SnapToGrid>true</rd:SnapToGrid>

<RightMargin>1in</RightMargin>

<LeftMargin>1in</LeftMargin>

<BottomMargin>1in</BottomMargin>

<rd:ReportID>66b0e21f-4a8d-4b4e-b652-d28cb44e05e4</rd:ReportID>

<DataSets>

<DataSet Name="DSReportPrintImage_ImageData">

<Fields>

<Field Name="ImageId">

<DataField>ImageId</DataField>

<rd:TypeName>System.Int32</rd:TypeName>

</Field>

<Field Name="ImageName">

<DataField>ImageName</DataField>

<rd:TypeName>System.String</rd:TypeName>

</Field>

<Field Name="ImageBytes">

<DataField>ImageBytes</DataField>

<rd:TypeName>System.Byte[]</rd:TypeName>

</Field>

</Fields>

<Query>

<DataSourceName>DummyDataSource</DataSourceName>

<CommandText />

<rd:UseGenericDesigner>true</rd:UseGenericDesigner>

</Query>

<rd:DataSetInfo>

<rd:DataSetName>DSReportPrintImage</rd:DataSetName>

<rd:TableName>ImageData</rd:TableName>

</rd:DataSetInfo>

</DataSet>

</DataSets>

<Width>6.5in</Width>

<Body>

<ReportItems>

<List Name="list1">

<Left>0.125in</Left>

<DataSetName>DSReportPrintImage_ImageData</DataSetName>

<ReportItems>

<Image Name="image1">

<Sizing>AutoSize</Sizing>

<Top>0.125in</Top>

<Width>5.875in</Width>

<MIMEType>image/png</MIMEType>

<Source>Database</Source>

<Style />

<Left>0.125in</Left>

<Height>1.625in</Height>

<Value>=Fields!ImageBytes.Value</Value>

</Image>

</ReportItems>

<Width>6.125in</Width>

<Height>1.875in</Height>

</List>

</ReportItems>

<Height>2in</Height>

</Body>

<Language>en-US</Language>

<TopMargin>1in</TopMargin>

</Report>

 

posted @ 2010-05-13 08:17  2012  阅读(1183)  评论(0编辑  收藏  举报