Below is a sample to guide you how to convert PDF to JPG/JPEG image in VB .NET.
Imports System.Drawing Imports System.Drawing.Imaging Imports PQScan.PDFToImage Namespace PDF2JPG Class Program Private Shared Sub Main(args As String()) ' Create an instance of PQScan.PDFToImage.PDFDocument object. Dim pdfDoc As New PDFDocument() ' Take 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 BitmapjpgImage = pdfDoc.ToImage(i) 'Save image with jpg file type jpgImage.Save("output" & i & ".jpg", ImageFormat.Jpeg) Next End Sub End Class End Namespace
Besides load local PDF, loading PDF stream is supported. Following example shows how to convert PDF first page to Jpeg image with wanted size using Visual Basic.NET code.
Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports PQScan.PDFToImage Namespace PDFToJPG 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 jpg image width from PDF page Dim width As Integer = pdf.GetPageWidth(0) / 2 ' Specify jpg image height from PDF page Dim height As Integer = pdf.GetPageHeight(0) / 2 'Convert PDF first page to image with the customized size Dim jpg As Bitmap = pdf.ToImage(0, width, height) 'Save image to jpg format jpg.Save("result.jpg", ImageFormat.Jpeg) End Sub End Class End Namespace
Another article, guiding to specify the image size using DPI property is supported, please see "How to customize images from PDF pages using vb.net". Do contact us if you have any other questions, pqScan is always ready to help.