This document contains code for generating a report from a dataset using Microsoft Reporting Services, exporting the report to multiple image streams, and printing the images. It loads a report from a file, populates it with data from a dataset, then exports the rendered report pages to multiple streams. It implements printing by drawing each image stream onto a print page.
This document contains code for generating a report from a dataset using Microsoft Reporting Services, exporting the report to multiple image streams, and printing the images. It loads a report from a file, populates it with data from a dataset, then exports the rendered report pages to multiple streams. It implements printing by drawing each image stream onto a print page.
This document contains code for generating a report from a dataset using Microsoft Reporting Services, exporting the report to multiple image streams, and printing the images. It loads a report from a file, populates it with data from a dataset, then exports the rendered report pages to multiple streams. It implements printing by drawing each image stream onto a print page.
Data Imports Microsoft.Reporting.WebForms Imports System.IO Imports System.Drawing.Imaging Imports System.Drawing.Printing
Dim pageIndex As Integer = 0
Dim streams As IList(Of Stream) Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then ReportViewer1.ProcessingMode = ProcessingMode.Local ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc") Dim dsCustomers As Customers = GetData() Dim datasource As ReportDataSource = New ReportDataSource("Customers", dsCustomers.Tables(0)) ReportViewer1.LocalReport.DataSources.Clear() ReportViewer1.LocalReport.DataSources.Add(datasource) End If
End Sub
Private Function GetData() As Customers
Dim dsCustomers As Customers = New Customers Dim dt As DataTable = dsCustomers.Tables("DataTable1") dt.Rows.Add("ALFKI", "Maria", "Boise", "Germany") dt.Rows.Add("ANATR", "Ana Trujillo", "México D.F.", "Mexico") dt.Rows.Add("ANTON", "Antonio Moreno", "Montréal", "Mexico") dt.Rows.Add("AROUT", "Thomas Hardy", "Mannheim", "Sweden") dt.Rows.Add("BERGS", "Christina Berglund", "Luleå", "Sweden") Return dsCustomers End Function
Protected Overloads Sub Print(ByVal sender As Object, ByVal e As EventArgs)
Export(ReportViewer1.LocalReport) pageIndex = 0 Print() End Sub
Private Sub Export(ByVal report As LocalReport)
Dim deviceInfo As String = "<DeviceInfo>" + _ " <OutputFormat>EMF</OutputFormat>" + _ " <PageWidth>8.5in</PageWidth>" + _ " <PageHeight>11in</PageHeight>" + _ " <MarginTop>0.25in</MarginTop>" + _ " <MarginLeft>0.25in</MarginLeft>" + _ " <MarginRight>0.25in</MarginRight>" + _ " <MarginBottom>0.25in</MarginBottom>" + _ "</DeviceInfo>" Dim warnings() As Warning streams = New List(Of Stream) report.Render("Image", deviceInfo, AddressOf CreateStream, warnings) For Each stream As Stream In streams stream.Position = 0 Next End Sub Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream Dim stream As Stream = New FileStream((Server.MapPath("~/Files/") _ + (name + ("." + fileNameExtension))), FileMode.Create) streams.Add(stream) Return stream End Function
Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim pageImage As Metafile = New Metafile(streams(pageIndex)) ev.Graphics.DrawImage(pageImage, ev.PageBounds) pageIndex = (pageIndex + 1) ev.HasMorePages = (pageIndex < streams.Count) End Sub
Private Overloads Sub Print()
If ((streams Is Nothing) _ OrElse (streams.Count = 0)) Then Return End If
Dim printDoc As PrintDocument = New PrintDocument
AddHandler printDoc.PrintPage, AddressOf Me.PrintPage printDoc.Print() End Sub
Learn Python Programming for Beginners: Best Step-by-Step Guide for Coding with Python, Great for Kids and Adults. Includes Practical Exercises on Data Analysis, Machine Learning and More.
The Advanced Roblox Coding Book: An Unofficial Guide, Updated Edition: Learn How to Script Games, Code Objects and Settings, and Create Your Own World!