Extract Images from a PDF
The code below shows you how to extract all of the images from a PDF file and store copy them to a folder.
It is recommended that you have already reviewed the Getting Started sample, since that includes Licensing and Framework initialization code required to make this sample run.
				
				1
				2
				3
				4
				5
				6
				7
				8
				9
				10
				11
				12
				13
				14
				15
				16
				17
				18
				19
				20
				21
				22
				23
				24
				25
				26
				27
				28
				29
				30
				31
				32
				33
				34
				35
				36
				37
				38
				39
				40
				41
				42
				43
				44
				45
				46
				47
				48
				49
				50
				51
				52
			
			
				
				using System;
				using SolidFramework.Converters;
				using SolidFramework.Converters.Plumbing;
				 
				namespace CSharp_Tutorials
				{
				    public static partial class Tutorials
				    {
				        public static bool ExtractPdfImages(string pdfPath, string outputFolder)
				        {
				            // Create a PdfToImageConverter
				            using (var converter = new PdfToImageConverter())
				            {
				                // Add the PDF file to extract images from
				                converter.AddSourceFile(pdfPath);
				 
				                // Set the output folder and overwrite mode
				                converter.OutputDirectory = outputFolder;
				                converter.OverwriteMode = SolidFramework.Plumbing.OverwriteMode.ForceOverwrite;
				 
				                // Set the conversion type to ExtractImages
				                converter.ConversionType = ImageConversionType.ExtractImages;
				 
				                // Optional: Set PdfToImageConverter options to your liking
				                converter.OutputType = ImageDocumentType.Default;
				 
				                Console.WriteLine("Extracting images from " + pdfPath + " into folder " + outputFolder);
				 
				                // Call Convert to extract the images
				                converter.Convert();
				 
				                // Check the results were successful
				                foreach (var result in converter.Results)
				                {
				                    if (result.Status != ConversionStatus.Success)
				                    {
				                        Console.WriteLine("Extracting images from " + pdfPath + " failed with status: " + result);
				                        Console.WriteLine();
				                        return false;
				                    }
				                }
				            }
				            Console.WriteLine("Successfully extracted images from " + pdfPath);
				            Console.WriteLine();
				            return true;
				        }
				    }
				}
				 
			
		
				
				1
				2
				3
				4
				5
				6
				7
				8
				9
				10
				11
				12
				13
				14
				15
				16
				17
				18
				19
				20
				21
				22
				23
				24
				25
				26
				27
				28
				29
				30
				31
				32
				33
				34
				35
				36
				37
				38
				39
				40
				41
				42
				43
				44
				45
				46
				47
				48
				49
			
			
				
				Imports System
				Imports SolidFramework.Converters
				Imports SolidFramework.Converters.Plumbing
				 
				Namespace VBNet_Tutorials
				    Partial Module Tutorials
				        Function ExtractPdfImages(ByVal pdfPath As String, ByVal outputFolder As String) As Boolean
				 
				            ' Create a PdfToImageConverter
				            Using converter As PdfToImageConverter = New PdfToImageConverter()
				 
				                ' Add the PDF file to extract images from
				                converter.AddSourceFile(pdfPath)
				 
				                ' Set the output folder And overwrite mode
				                converter.OutputDirectory = outputFolder
				                converter.OverwriteMode = SolidFramework.Plumbing.OverwriteMode.ForceOverwrite
				 
				                ' Set the conversion type to ExtractImages
				 
				                ' Optional Set PdfToImageConverter options to your liking
				                converter.ConversionType = ImageConversionType.ExtractImages
				                converter.OutputType = ImageDocumentType.[Default]
				 
				                Console.WriteLine("Extracting images from " & pdfPath & " into folder " & outputFolder)
				 
				                ' Call Convert to extract the images
				                converter.Convert()
				 
				                For Each result As ConversionResult In converter.Results
				 
				                    If result.Status <> ConversionStatus.Success Then
				                        Console.WriteLine("Extracting images from " & pdfPath & " failed with status: " & result.ToString())
				                        Console.WriteLine()
				                        Return False
				                    End If
				                Next
				            End Using
				 
				            Console.WriteLine("Successfully extracted images from " & pdfPath)
				            Console.WriteLine()
				            Return True
				        End Function
				    End Module
				End Namespace
				 
			
		
				
				1
				2
				3
				4
				5
				6
				7
				8
				9
				10
				11
				12
				13
				14
				15
				16
				17
				18
				19
				20
				21
				22
				23
				24
				25
				26
				27
				28
				29
				30
				31
				32
				33
				34
				35
				36
				37
				38
				39
				40
				41
				42
				43
				44
			
			
				
				#include "Tutorials.h"
				 
				using namespace SolidFramework::Converters::Plumbing;
				using namespace SolidFramework::Converters;
				 
				bool ExtractPdfImages(const wstring & pdfPath, const wstring & outputFolder)
				{
				    // Create a PdfToImageConverter
				    auto converter = make_shared<PdfToImageConverter>();
				 
				    // Add the PDF file to extract images from
				    converter->AddSourceFile(pdfPath);
				 
				    // Set the output folder and overwrite mode
				    converter->SetOutputDirectory(outputFolder);
				    converter->SetOverwriteMode(SolidFramework::Plumbing::OverwriteMode::ForceOverwrite);
				 
				    // Set the conversion type to ExtractImages
				    converter->SetConversionType(ImageConversionType::ExtractImages);
				 
				    // Optional: Set PdfToImageConverter options to your liking
				    converter->SetOutputType(ImageDocumentType::Default);
				 
				    wcout << L"Extracting images from " << pdfPath << L" into folder " << outputFolder << endl;
				 
				    // Call Convert to extract the images
				    converter->Convert();
				 
				    // Check the results were successful
				    for (const auto & result : converter->GetResults())
				    {
				        if (result->GetStatus() != ConversionStatus::Success)
				        {
				            wcout << L"Extracting images from " << pdfPath << L" failed with status: " << (int)result->GetStatus() << endl << endl;
				            return false;
				        }
				    }
				    wcout << L"Successfully extracted images from " << pdfPath << endl << endl;
				    return true;
				}
				 
			
		