How to Add Images to PDF in VB .NET
1. Introduction
Adobe's Portable Document Format (PDF) is widely used in various industries for tasks such as creating invoices. Developers also use the PDF format to produce documents that meet client specifications. Libraries have simplified the process of creating PDFs, and when selecting a library for a project, consider features like build, read, and convert capabilities.
2. IronPDF Features
IronPDF is a robust PDF SDK framework that facilitates the creation, reading, and editing of PDF documents. It converts HTML to PDF using the Chrome engine and supports various web components like Xamarin, Blazor, Unity, HoloLens apps, and more. It works with both online applications and traditional Windows Applications. IronPDF allows for the creation of aesthetically pleasing PDFs using HTML5, JavaScript, CSS, and images, and includes a powerful HTML-to-PDF converter.
- The IronPDF library supports a variety of inputs for PDF production, including image files to PDF conversion, converting HTML5 to PDF, creating PDF from ASPX pages, and Razor/MVC View to PDF.
- The library has tools for creating interactive PDF files, completing and distributing interactive forms, dividing PDF files, extracting text and images, text searching, and converting PDF pages to images.
- In addition to using user agents, proxies, cookies, HTTP headers, and form variables for authentication behind HTML login forms, the library also offers the usage of links as the foundation for PDF documents.
- IronPDF offers access to managing password-protected PDF files by requesting user names and passwords.
- The IronPDF API allows for the reading and editing of existing PDF files.
- The library can extract images from PDF files as well as add text, graphics, bookmarks, watermarks, headers, and footers to PDF files.
- Users can split and combine pages in a new or existing PDF document, and IronPDF can create PDF objects from text without requiring Acrobat Reader.
- Both CSS media files and CSS files can be converted into PDF documents.
- Users of IronPDF can add brand-new PDF forms and edit pre-existing ones.
3. Create PDF Documents from Images
IronPDF makes it easy to create PDFs from images.
' Create a PDF document from a single image file
Dim pdfdoc = ImageToPdfConverter.ImageToPdf("test.png").SaveAs("Resultimage.pdf")
' Create a PDF document from a single image file
Dim pdfdoc = ImageToPdfConverter.ImageToPdf("test.png").SaveAs("Resultimage.pdf")
By using the ImageToPdfConverter
class, it is easy to use without creating any object for the class. The ImageToPdf
method accepts the filename and path as a parameter and converts the given PNG file into the desired PDF. Finally, the SaveAs
method saves the generated PDF file in the desired location.
The below image shows the result of the above code.
The PDF file output
This next example creates a PDF document from a list of images.
' Create a PDF document from a list of image files
Dim lstimages As List(Of String) = New List(Of String)
lstimages.Add("test.png")
lstimages.Add("demo.png")
Dim pdfdoc = ImageToPdfConverter.ImageToPdf(lstimages).SaveAs("Resultimage.pdf")
' Create a PDF document from a list of image files
Dim lstimages As List(Of String) = New List(Of String)
lstimages.Add("test.png")
lstimages.Add("demo.png")
Dim pdfdoc = ImageToPdfConverter.ImageToPdf(lstimages).SaveAs("Resultimage.pdf")
The PDF file from two images
4. Create PDF Documents from Bitmap image objects
Several bitmap image objects can be converted to PDF files with just a few lines of code.
' Convert a single Bitmap image object to a PDF file
Imports System.Drawing
Imports IronPdf
Dim image As Bitmap = Bitmap.FromFile("test.png")
Dim pdfDoc = ImageToPdfConverter.ImageToPdf(image).SaveAs("Resultimage.pdf")
' Convert a single Bitmap image object to a PDF file
Imports System.Drawing
Imports IronPdf
Dim image As Bitmap = Bitmap.FromFile("test.png")
Dim pdfDoc = ImageToPdfConverter.ImageToPdf(image).SaveAs("Resultimage.pdf")
In the above example, a Bitmap object is created from the PNG file and used as a medium format to convert to a PDF file.
Generate a PDF file from a PNG image
It is also possible to combine a collection (or List) of Bitmap
objects into a single PDF:
' Combine multiple Bitmap objects into a single PDF document
Dim lstImages As List(Of IronSoftware.Drawing.AnyBitmap) = New List(Of IronSoftware.Drawing.AnyBitmap)
lstImages.Add(Bitmap.FromFile("test.png"))
lstImages.Add(Bitmap.FromFile("demo.png"))
Dim pdfDoc = ImageToPdfConverter.ImageToPdf(lstImages).SaveAs("Resultimage.pdf")
' Combine multiple Bitmap objects into a single PDF document
Dim lstImages As List(Of IronSoftware.Drawing.AnyBitmap) = New List(Of IronSoftware.Drawing.AnyBitmap)
lstImages.Add(Bitmap.FromFile("test.png"))
lstImages.Add(Bitmap.FromFile("demo.png"))
Dim pdfDoc = ImageToPdfConverter.ImageToPdf(lstImages).SaveAs("Resultimage.pdf")
Combine multiple Bitmap files to generate a PDF file
Configure the behavior of the above method calls using a ChromePdfRenderOptions
object to enhance the visual aspect of the output PDF file. Options that can be configured include the position of the image, header and footer formatting, page title, page size, and many others.
More information about adding images to PDFs using IronPDF, along with other information, can be found in the IronPDF Documentation.
5. Conclusion
The IronPDF library provides a free license for development and a variety of licenses are available for purchase for use in a production environment, depending on the developer's needs. The Lite package costs $749 upfront and has no ongoing expenses. The licenses come with a perpetual license, a year of product support, upgrades, and options for SaaS and OEM redistribution. They are one-time investments that can be utilized for production, staging, and development.
IronPDF also provides extra time-limited free licenses. In addition, IronPDF offers free licenses that prevent redistribution. To view IronPDF's complete pricing and licensing details, please visit the IronPDF Licensing Details.
Frequently Asked Questions
How can I insert images into a PDF document using VB.NET?
You can use IronPDF to insert images into PDF documents in VB.NET by using the ImageToPdfConverter
class. For instance, the method ImageToPdfConverter.ImageToPdf("image.png").SaveAs("output.pdf")
will create a PDF from an image file.
What image formats are supported for PDF conversion in VB.NET?
IronPDF supports a variety of image formats for conversion to PDF, including PNG, JPEG, BMP, and GIF. You can convert these image files into PDFs using the ImageToPdfConverter
.
Can I customize the appearance of the PDF when adding images using VB.NET?
Yes, IronPDF allows customization of the PDF output, such as image positioning, headers, footers, and page sizes, using ChromePdfRenderOptions
.
Is it possible to combine multiple images into a single PDF document?
Yes, with IronPDF, you can combine multiple images into a single PDF document by providing a list of images to ImageToPdfConverter
and saving the output as one PDF file.
How can I use Bitmap objects to create PDFs in VB.NET?
IronPDF supports using Bitmap objects directly for PDF creation. You can convert Bitmap images by passing them to ImageToPdfConverter
to generate PDF files.
What options are available for licensing IronPDF?
IronPDF offers a free development license and various production licenses that include perpetual use, product support, and upgrades. Licensing options also cover SaaS and OEM redistribution.
Does IronPDF allow for interactive elements in a PDF?
Yes, IronPDF can add interactive elements such as forms and annotations to PDF documents, enhancing the functionality of your PDFs.
How does IronPDF handle HTML to PDF conversion?
IronPDF uses the Chrome engine to handle HTML to PDF conversion, ensuring high fidelity in rendering HTML5, JavaScript, and CSS into aesthetically pleasing PDFs.
What platforms are compatible with IronPDF?
IronPDF is compatible with various platforms, including Xamarin, Blazor, Unity, and HoloLens apps, making it versatile for different development environments.