我正在开发一个项目,其中在程序中单击按钮,并且打印出SSRS中的双页双面报告。我已经把它弄到两个页面中的一个要打印而不是双面打印页面。我知道我需要将e.HasMorePages设置为true并放入索引。问题是因为元文件导致第二页出错。我不确定如何解决这个问题。
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports Microsoft.Reporting.WinForms
Public Class Printing
Dim pages As New List(Of Metafile)
Dim pageIndex As Integer = 0
Dim doc As New System.Drawing.Printing.PrintDocument()
Dim ReportViewer1 As New ReportViewer
Dim TotalQTY As Int32
Dim data() As Byte
Dim receiveText As String
Private Sub Printing_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'receiveText = Command()
receiveText = "08NFA-0000"
With ReportViewer1
.Visible = False
.ProcessingMode = ProcessingMode.Remote
.ServerReport.ReportPath = "/Traveler/Traveler"
.ServerReport.ReportServerUrl = New _
Uri("http://sql01/ReportServer_MADE2MANAGE")
End With
Me.Controls.Add(ReportViewer1)
Dim doc As New System.Drawing.Printing.PrintDocument()
doc = New System.Drawing.Printing.PrintDocument()
AddHandler doc.PrintPage, AddressOf PrintPageHandler
Dim dialog As New PrintDialog()
dialog.Document = doc
doc.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical
Dim deviceInfo As String =
"<DeviceInfo>" &
"<OutputFormat>emf</OutputFormat>" &
" <PageWidth>8.5in</PageWidth>" &
" <PageHeight>11in</PageHeight>" &
" <MarginTop>0.125in</MarginTop>" &
" <MarginLeft>0.125in</MarginLeft>" &
" <MarginRight>0.125in</MarginRight>" &
" <MarginBottom>0.125in</MarginBottom>" &
"</DeviceInfo>"
Dim warnings() As Microsoft.Reporting.WinForms.Warning
Dim streamids() As String
Dim mimeType, encoding, filenameExtension As String
mimeType = "" : encoding = "" : filenameExtension = ""
Dim Parm As New ReportParameter("JobOrder", receiveText)
Dim parmSO1(0) As ReportParameter
parmSO1(0) = Parm
ReportViewer1.ServerReport.SetParameters(parmSO1)
data = ReportViewer1.ServerReport.Render("Image",
deviceInfo, mimeType, encoding, filenameExtension,
streamids, warnings)
pages.Add(New Metafile(New MemoryStream(data)))
For Each pageName As String In streamids
data = ReportViewer1.ServerReport.RenderStream("Image",
pageName, deviceInfo, mimeType, encoding)
pages.Add(New Metafile(New MemoryStream(data)))
Next
doc.Print()
Me.ReportViewer1.RefreshReport()
Me.Close()
End Sub
Private Sub PrintPageHandler(ByVal sender As Object,
ByVal e As PrintPageEventArgs)
Dim page As Metafile = pages(pageIndex)
pageIndex += 1
Dim pWidth As Integer = 910
Dim pHeight As Integer = 1500
e.Graphics.DrawImage(page, 0, 0, pWidth, pHeight)
e.HasMorePages = pageIndex < pages.Count
End Sub
End Class