The following example demonstrates how to load a PDF document and render it into a GIF image file. Converting PDF pages to GIF can be done in just a few simple lines of VB.NET code.
Imports System.Drawing Imports System.Drawing.Imaging Imports PQScan.PDFToImage Namespace PDF2GIF 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 Dim gifImage As Bitmap = pdfDoc.ToImage(i) 'Save image with gif file type gifImage.Save("output" & i & ".gif", ImageFormat.Gif) Next End Sub End Class End Namespace
Below VB.Net sample codes introduce you how to draw Gif image from PDF stream, and resize the output Gif image.
Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports PQScan.PDFToImage Namespace PDFToGIF 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 gif image width from PDF page Dim width As Integer = pdf.GetPageWidth(0) / 2 ' Specify gif image height from PDF page Dim height As Integer = pdf.GetPageHeight(0) / 2 'Convert PDF first page to image with the customized size Dim gif As Bitmap = pdf.ToImage(0, width, height) 'Save image to gif format gif.Save("result.gif", ImageFormat.Gif) End Sub End Class End Namespace
There is another article shows more information of customizing the image size and changing image quality, if you want to, it may be helpful.