Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, Finally figured out.</p> <p>check this link: <a href="http://theruntime.com/blogs/jacob/archive/2007/12/07/printing-reporting-services-2005-reports.aspx" rel="noreferrer">Printing Reporting Services 2005 Reports</a></p> <p>That blog post has almost everything that I needed, but I'm going to post the full answer here for references.</p> <p>I ended up using the report viewer object behind the scenes, but only for convenience, since it's not required.</p> <p>The first step is asking the user for the printer settings:</p> <pre><code>Dim doc As New Printing.PrintDocument() AddHandler doc.PrintPage, AddressOf PrintPageHandler Dim dialog As New PrintDialog() dialog.Document = doc Dim print As DialogResult print = dialog.ShowDialog() doc.PrinterSettings = dialog.PrinterSettings </code></pre> <p>Having that, we proceed to configure our report call: Modifying this string, you can get to print on any paper size and any orientation (switching height and width for landscape), but the report itself must be configured in the same page layout.</p> <pre><code>Dim deviceInfo As String = _ "&lt;DeviceInfo&gt;" + _ "&lt;OutputFormat&gt;emf&lt;/OutputFormat&gt;" + _ " &lt;PageWidth&gt;8.5in&lt;/PageWidth&gt;" + _ " &lt;PageHeight&gt;11in&lt;/PageHeight&gt;" + _ " &lt;MarginTop&gt;0.25in&lt;/MarginTop&gt;" + _ " &lt;MarginLeft&gt;0.25in&lt;/MarginLeft&gt;" + _ " &lt;MarginRight&gt;0.25in&lt;/MarginRight&gt;" + _ " &lt;MarginBottom&gt;0.25in&lt;/MarginBottom&gt;" + _ "&lt;/DeviceInfo&gt;" Dim warnings() As Warning Dim streamids() As String Dim mimeType, encoding, filenameExtension, path As String mimeType = "" : encoding = "" : filenameExtension = "" </code></pre> <p>Finally, we render the report with all its pages. </p> <p>Note that if the report has only one page, the renderStream method is never used.</p> <p>rpt_control is the report viewer control, previously configured and aiming at a server report.</p> <p>Note allso that in this code we add pages to a list. This list is a global variable, since it's needed in the PrintPageHandler method.</p> <pre><code>Dim data() As Byte rpt_control.ServerReport.SetParameters(_parametros) data = rpt_control.ServerReport.Render("Image", deviceInfo, mimeType, encoding, filenameExtension, streamids, warnings) pages.Add(New Metafile(New MemoryStream(data))) For Each pageName As String In streamids data = rpt_control.ServerReport.RenderStream("Image", pageName, deviceInfo, mimeType, encoding) pages.Add(New Metafile(New MemoryStream(data))) Next doc.Print() </code></pre> <p>Until now, we haven't done any printing at all, this is actually handled by the PrintPageHandler method that we referenced earlier.</p> <pre><code>Dim pages As New List(Of Metafile) Dim pageIndex As Integer = 0 Private Sub PrintPageHandler(ByVal sender As Object, ByVal e As PrintPageEventArgs) Dim page As Metafile = pages(pageIndex) pageIndex += 1 e.Graphics.DrawImage(page, 0, 0, page.Width, page.Height) e.HasMorePages = pageIndex &lt; pages.Count End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload