Please enable JavaScript to view this site.

Navigation: Developer Information > Programming Environments

.NET Framework

Scroll Prev Top Next More

You can set the PDF file name from VB.NET or C# using the .NET framework Printersettings.PrintFileName property as documented by Microsoft at:

 

https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printersettings.printfilename

 

You should also set the PrinterSettings.PrintToFile property to TRUE:

 

PrintDocument.PrinterSettings.PrintFileName = "C:\Users\test\AppData\Local\Temp\aFile.pdf"

PrintDocument.PrinterSettings.PrintToFile = true;

 

You can set any Win2PDF string registry settings using the VB.NET "SaveSetting" function.

 

SaveSetting "Dane Prairie Systems", "Win2PDF", ValueName, Value

 

From C#, you can use the same fully qualified SaveSetting function name:

 

Microsoft.VisualBasic.Interaction.SaveSetting("Dane Prairie Systems", "Win2PDF", ValueName, Value)

 

 

Win2PDF behaves the same as a paper printer for all other .NET interfaces.  Here's an example for creating a PDF from VB.NET:

 

 

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\test\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