How to Print a VB.NET Form to PDF
Let's be real: converting Windows Forms to PDF documents in VB.NET is a requirement that constantly comes up, but the .NET Framework just doesn't offer native PDF printing. You need a reliable way to generate PDF files from reports, save form data, or create printable documents.
Luckily, IronPDF offers a quick and streamlined solution. This tool lets you print forms to PDF files without the hassle of Adobe Reader installs or complex PDF printer setup. This complete article will show you how to do it in minutes.
Why Use IronPDF for Form-to-PDF File Conversion?
IronPDF is a comprehensive .NET PDF library that simplifies the process of converting Windows Forms and web forms (including ASPX pages) to PDF documents. Unlike traditional approaches that rely on PDF printers or complex drawing operations, IronPDF uses a Chrome rendering engine to generate PDF files with pixel-perfect accuracy from your VB .NET projects.
The library handles all aspects of PDF content creation, from rendering form controls to managing page layouts, making it ideal for both Windows Forms applications and ASP.NET web applications. With IronPDF's HTML to PDF conversion capabilities, developers can create professional documents efficiently. This powerful resource is key to speeding up development.
Installing IronPDF in Your VB.NET Project
Getting started with IronPDF takes just minutes. The simplest installation method uses the NuGet Package Manager in Visual Studio:
- Right-click your project in Solution Explorer
- Select "Manage NuGet Packages"
- Search for "IronPDF"
- Click Install to add the latest version
Alternatively, use the Package Manager Console with the following command:
Install-Package IronPdf
For detailed setup instructions, visit the IronPDF installation guide link. Once installed, add Imports IronPDF to start using the library's powerful features.
Converting a Windows Forms to PDF: Step-by-Step Code
The follow code example shows how to capture and convert a Windows Form to a new PDFDocument object:
Imports IronPdf
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Private Sub btnPrintToPDF_Click(sender As Object, e As EventArgs) Handles btnPrintToPDF.Click
' Capture the form as HTML content
Dim htmlContent As String = GenerateFormHTML()
' Initialize IronPDF's ChromePdfRenderer instance
Dim renderer As New ChromePdfRenderer()
' Configure rendering options for better output
renderer.RenderingOptions.MarginTop = 10
renderer.RenderingOptions.MarginBottom = 10
renderer.RenderingOptions.MarginLeft = 10
renderer.RenderingOptions.MarginRight = 10
' Generate PDF from HTML content
Dim pdfDocument As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
' Save the PDF file
Dim fileName As String = "FormOutput.pdf"
pdfDocument.SaveAs(fileName)
' Optional: Open the generated PDF
Process.Start(fileName)
End Sub
Private Function GenerateFormHTML() As String
' Build HTML representation of your form
Dim html As New System.Text.StringBuilder()
html.Append("<html><head>")
html.Append("<style>")
html.Append("body { font-family: Arial, sans-serif; }")
html.Append("table { width: 100%; border-collapse: collapse; }")
html.Append("td { padding: 8px; border: 1px solid #ddd; }")
html.Append("</style>")
html.Append("</head><body>")
html.Append("<h1>Hello World</h1>")
html.Append("<table>")
' Add form controls data
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is TextBox Then
Dim textBox As TextBox = DirectCast(ctrl, TextBox)
html.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>",
textBox.Name, textBox.Text)
ElseIf TypeOf ctrl Is ComboBox Then
Dim comboBox As ComboBox = DirectCast(ctrl, ComboBox)
html.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>",
comboBox.Name, comboBox.Text)
End If
Next
html.Append("</table>")
html.Append("</body></html>")
Return html.ToString()
End Function
End SubImports IronPdf
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Private Sub btnPrintToPDF_Click(sender As Object, e As EventArgs) Handles btnPrintToPDF.Click
' Capture the form as HTML content
Dim htmlContent As String = GenerateFormHTML()
' Initialize IronPDF's ChromePdfRenderer instance
Dim renderer As New ChromePdfRenderer()
' Configure rendering options for better output
renderer.RenderingOptions.MarginTop = 10
renderer.RenderingOptions.MarginBottom = 10
renderer.RenderingOptions.MarginLeft = 10
renderer.RenderingOptions.MarginRight = 10
' Generate PDF from HTML content
Dim pdfDocument As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
' Save the PDF file
Dim fileName As String = "FormOutput.pdf"
pdfDocument.SaveAs(fileName)
' Optional: Open the generated PDF
Process.Start(fileName)
End Sub
Private Function GenerateFormHTML() As String
' Build HTML representation of your form
Dim html As New System.Text.StringBuilder()
html.Append("<html><head>")
html.Append("<style>")
html.Append("body { font-family: Arial, sans-serif; }")
html.Append("table { width: 100%; border-collapse: collapse; }")
html.Append("td { padding: 8px; border: 1px solid #ddd; }")
html.Append("</style>")
html.Append("</head><body>")
html.Append("<h1>Hello World</h1>")
html.Append("<table>")
' Add form controls data
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is TextBox Then
Dim textBox As TextBox = DirectCast(ctrl, TextBox)
html.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>",
textBox.Name, textBox.Text)
ElseIf TypeOf ctrl Is ComboBox Then
Dim comboBox As ComboBox = DirectCast(ctrl, ComboBox)
html.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>",
comboBox.Name, comboBox.Text)
End If
Next
html.Append("</table>")
html.Append("</body></html>")
Return html.ToString()
End Function
End SubIRON VB CONVERTER ERROR developers@ironsoftware.comThis code snippet demonstrates several key concepts. First, it captures form data by iterating through Windows Forms controls. Then, it builds an HTML representation with proper formatting using CSS styles. Finally, IronPDF's RenderUrlAsPdf method variant RenderHtmlAsPdf converts this HTML into a PDF document with professional formatting. The method handles all PDF content generation automatically, ensuring your forms are accurately represented in the output file with the specified file name. A similar approach is used when creating a new document from a web page or URL.
Example Windows Form UI

Output PDF Document

Alternative Method: Using Images for Complex Forms
For forms with complex graphics or custom drawing, you can capture the form as an image. The following code snippet shows this approach:
Private Sub PrintFormAsImage()
' Capture form as bitmap
Dim bitmap As New Bitmap(Me.Width, Me.Height)
Me.DrawToBitmap(bitmap, New Rectangle(0, 0, Me.Width, Me.Height))
' Save bitmap to memory stream
Dim ms As New System.IO.MemoryStream()
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
' Convert image to PDF using IronPDF
Dim pdfDocument As PdfDocument = ImageToPdfConverter.ImageToPdf(ms.ToArray())
pdfDocument.SaveAs("FormImage.pdf")
End SubPrivate Sub PrintFormAsImage()
' Capture form as bitmap
Dim bitmap As New Bitmap(Me.Width, Me.Height)
Me.DrawToBitmap(bitmap, New Rectangle(0, 0, Me.Width, Me.Height))
' Save bitmap to memory stream
Dim ms As New System.IO.MemoryStream()
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
' Convert image to PDF using IronPDF
Dim pdfDocument As PdfDocument = ImageToPdfConverter.ImageToPdf(ms.ToArray())
pdfDocument.SaveAs("FormImage.pdf")
End SubIRON VB CONVERTER ERROR developers@ironsoftware.comThis code provides an alternative approach for complex forms. It uses the DrawToBitmap method to capture the entire form as an image, preserving exact visual appearance including custom graphics and special controls. The ImageToPdfConverter class ensures high-quality conversion from PNG or other image formats to PDF. This provides a clear reference for complex form handling.
Printing PDF Documents Directly
Once you've generated your PDF file, IronPDF also supports direct printing:
' Print PDF to default printer
pdfDocument.Print()
' Print with specific settings
Dim printDoc As System.Drawing.Printing.PrintDocument = pdfDocument.GetPrintDocument()
printDoc.PrinterSettings.PrinterName = "My Printer"
printDoc.Print()' Print PDF to default printer
pdfDocument.Print()
' Print with specific settings
Dim printDoc As System.Drawing.Printing.PrintDocument = pdfDocument.GetPrintDocument()
printDoc.PrinterSettings.PrinterName = "My Printer"
printDoc.Print()IRON VB CONVERTER ERROR developers@ironsoftware.comThis sample code shows how to print PDF files directly without opening them. The first method sends the document to the default printer, while the second allows you to specify printer settings programmatically. For more details on printing PDF documents, check the IronPDF printing documentation.
Adding Professional Features
IronPDF enables you to enhance your PDF documents with professional features. This includes advanced editing options:
' Add headers and footers
renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.CenterText = "Company Report",
.DrawDividerLine = True
}
' Set page numbers on first page and beyond
renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.RightText = "Page {page} of {total-pages}",
.FontSize = 10
}' Add headers and footers
renderer.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.CenterText = "Company Report",
.DrawDividerLine = True
}
' Set page numbers on first page and beyond
renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.RightText = "Page {page} of {total-pages}",
.FontSize = 10
}IRON VB CONVERTER ERROR developers@ironsoftware.comThese features transform basic PDF files into professional documents. The library supports comprehensive customization of PDF content, from headers and footers to security settings. Learn more about advanced PDF features (note the customization options).
Output

Common Troubleshooting Tips
When working with form-to-PDF conversion in .NET applications, keep these points in mind:
- Ensure all required .NET Framework components are installed
- For web applications (ASPX), verify IIS permissions for file system access
- Use UTF-8 encoding for international characters in form data (argument)
- Test rendering with different form sizes to ensure proper page layout
- Store generated PDF files in an appropriate local copy directory. This happens on load end of the form data conversion
For additional support, consult the comprehensive IronPDF documentation or explore community solutions on Stack Overflow (post a question).
Conclusion
IronPDF transforms the complex task of printing forms to PDF into a straightforward process. Whether you're building Windows Forms applications or ASP.NET web forms, the library provides all the tools needed to generate PDF documents from your VB.NET projects. This is a powerful resource for any user.
The combination of HTML rendering capabilities and direct form capture methods gives developers flexibility in handling various form types and requirements. With support for advanced features like headers, footers, and security settings, IronPDF delivers a complete solution for PDF generation in .NET applications.
Ready to use IronPDF for your VB.NET print form to PDF tasks, or any other PDF workflows? Start with a free trial of IronPDF, or explore the comprehensive documentation and API reference to discover more features. For production deployments, licensing options start at $799.
Download IronPDF today and transform your Windows Forms into professional PDF documents with just a few lines of code.







