The sample codes below show PDF to PNG image conversion in VB.NET using PDF To Image SDK.
Imports System.Drawing Imports System.Drawing.Imaging Imports PQScan.PDFToImage Namespace PDF2PNG Class Program Private Shared Sub Main(args As String()) ' Create an instance of PQScan.PDFToImage.PDFDocument object. Dim pdfDoc As New PDFDocument() ' Load local PDF document. pdfDoc.LoadPDF("sample.pdf") 'Get total page count. Dim count As Integer = pdfDoc.PageCount For i As Integer = 0 To count - 1 'Convert page to image Dim pngImage As Bitmap = pdfDoc.ToImage(i) 'Save image with png file type pngImage.Save("output" & i & ".png", ImageFormat.Png) Next End Sub End Class End Namespace
The second Visual Basic.NET example shows convert PDF stream to customized size Png image.
Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports PQScan.PDFToImage Namespace PDFToPNG Class Program Private Shared Sub Main(args As String()) ' Generate a new PDFDocument instance from PQScan.PDFToImage. Dim pdf As New PDFDocument() ' Open PDF document to file stream Dim stream As New FileStream("sample.pdf", FileMode.Open) ' Load message from PDF document stream. pdf.LoadPDF(stream) ' Specify png image width from PDF page Dim width As Integer = pdf.GetPageWidth(0) / 2 ' Specify png image height from PDF page Dim height As Integer = pdf.GetPageHeight(0) / 2 'Convert PDF first page to image with the customized size Dim png As Bitmap = pdf.ToImage(0, width, height) 'Save image to png format png.Save("result.png", ImageFormat.Png) End Sub End Class End Namespace
Besides resetting the with and height of output image, our library also allows to type image in a custom size through DPI property, if you need, please see "How to resize output images from PDF pages in vb.net".