These samples show how to extract images from PDF by pages in C#, VB.NET, and VBScript using Bytescout PDF Extractor SDK.
Also, see the following tutorial if you need to extract image coordinates from PDF.
Select your programming language:
using System; using System.Drawing.Imaging; using Bytescout.PDFExtractor; namespace ExtractImagesByPages { class Program { static void Main(string[] args) { // Create Bytescout.PDFExtractor.ImageExtractor instance ImageExtractor extractor = new ImageExtractor(); extractor.RegistrationName = "demo"; extractor.RegistrationKey = "demo"; // Load sample PDF document extractor.LoadDocumentFromFile("sample1.pdf"); // Get count of pages int pageCount = extractor.GetPageCount(); // Extract images from each page for (int i = 0; i < pageCount; i++) { int j = 0; // Initialize page images enumeration if (extractor.GetFirstPageImage(i)) { do { string outputFileName = "page" + i + "image" + j + ".png"; // Save image to file extractor.SaveCurrentImageToFile(outputFileName, ImageFormat.Png); j++; } while (extractor.GetNextImage()); // Advance image enumeration } } // Open first output file in default associated application System.Diagnostics.Process.Start("page0image0.png"); } } }
Imports Bytescout.PDFExtractor Imports System.Drawing.Imaging Class Program Friend Shared Sub Main(args As String()) ' Create Bytescout.PDFExtractor.ImageExtractor instance Dim extractor As New ImageExtractor() extractor.RegistrationName = "demo" extractor.RegistrationKey = "demo" ' Load sample PDF document extractor.LoadDocumentFromFile("sample1.pdf") ' Get count of pages Dim pageCount As Integer = extractor.GetPageCount() ' Extract images from each page For i As Integer = 0 To pageCount - 1 Dim j As Integer = 0 ' Initialize page images enumeration If extractor.GetFirstPageImage(i) Then Do Dim outputFileName As String = "page" & i & "image" & j & ".png" ' Save image to file extractor.SaveCurrentImageToFile(outputFileName, ImageFormat.Png) j = j + 1 Loop While extractor.GetNextImage() ' Advance image enumeration End If Next ' Open first output file in default associated application System.Diagnostics.Process.Start("page0image0.png") End Sub End Class
' Create Bytescout.PDFExtractor.ImageExtractor object Set extractor = CreateObject("Bytescout.PDFExtractor.ImageExtractor") extractor.RegistrationName = "demo" extractor.RegistrationKey = "demo" ' Load sample PDF document extractor.LoadDocumentFromFile("..\..\sample1.pdf") ' Get page count pageCount = extractor.GetPageCount() ' Extract images from each page For i = 0 To pageCount - 1 j = 0 ' Initialize page images enumeration If extractor.GetFirstPageImage(i) Then Do outputFileName = "page" & i & "image" & j & ".png" ' Save image to file extractor.SaveCurrentImageToFile outputFileName j = j + 1 Loop While extractor.GetNextImage() ' Advance image enumeration End If Next ' Open first output file in default associated application Set shell = CreateObject("WScript.Shell") shell.Run "page0image0.png", 1, false Set shell = Nothing Set extractor = Nothing