Knowledgebase: Developer
VB.NET example
Posted by Craig Lebakken on 16 May 2009 10:12 PM
|
|
Question:
Do you have an example for printing to Win2PDF from VB.NET?
Answer:
You can set the PDF file name in .NET using the information in the following article: Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs) Static i As Integer = 0
i = i + 1 ' Print a line on this page args.Graphics.DrawString("Printed a Line on page " & i.ToString, New Font(Me.Font, FontStyle.Regular), Brushes.Black, 50, 50) ' Have we printed enough pages? If i >= 5 Then ' Done all the pages i = 0 args.HasMorePages = False Else ' Not finished, yet args.HasMorePages = True End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim prn As New Printing.PrintDocument ' Select the Win2PDF Printer prn.PrinterSettings.PrinterName = "Win2PDF" ' Set the PDF file name prn.PrinterSettings.PrintFileName = "C:\Users\craig\AppData\Local\Temp\aFile.pdf" prn.PrinterSettings.PrintToFile = True ' Handle the page events AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler ' Do the print (Printing handled by the print page handler) prn.Print() ' Remove the page handler RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler End Sub
| |
|
Comments (0)
Copyright 2000-2018 © Dane Prairie Systems LLC. All Rights Reserved. About Us | Privacy Policy | PDF Blog | Site Map