Extract images from PDF Files
The code below shows you how to extract all of the images from a PDF file and store copy them to a folder.
This sample requires a Tools license.
C#
using System;
using SolidFramework.Converters;
namespace PDFExtractImages
{
class Program
{
[STAThread]
static void Main(string[] args)
{
// Call your Solid Documents License
SolidFramework.License.Import(@"C:\MyFolder\license.xml");
// Set the location of your the file you want to convert
String pdfPath = @"C:\YourFolder\yourpdf.pdf";
//*Extract Images from PDF File*//
using (PdfToImageConverter converter = new PdfToImageConverter())
{
//Add the Selected File
converter.AddSourceFile(pdfPath);
//Set where to save the images
converter.OutputDirectory = @"C:\MyPDFImages";
//Extract the images using .Convert
converter.Convert();
}
}
}
}
C++
#include "stdafx.h"
#include "SolidFramework.h"
#include
using namespace std;
void DoProgress(SolidFramework::ProgressEventArgsPtr args)
{
// Not implemented
}
void DoWarning(SolidFramework::WarningEventArgsPtr args)
{
// Not implemented
}
class PdfToImageConverter : public SolidFramework::Converters::PdfToImageConverterBase
{
public:
void FireProgress(SolidFramework::ProgressEventArgsPtr args) override { DoProgress(args); };
void FireWarning(SolidFramework::WarningEventArgsPtr args) override { DoWarning(args); };
};
int _tmain(int argc, _TCHAR* argv[])
{
// Enter your License code goes here
SolidFramework::License::Import(L"C:\\MyFolder\\license.xml");
// Create a PDF to Image Converter called converter
PdfToImageConverter *pageImage = new PdfToImageConverter();
SolidFramework::Converters::CustomData *pData = NULL;
pData = new SolidFramework::Converters::CustomData();
pData->Converter = pageImage;
pData->Data = nullptr;
pageImage->setCustomData(pData);
// Add the PDF file to convert.
pageImage->AddSourceFile(L"C:\\YourFolder\\yourpdf.pdf");
pageImage->setOutputDirectory(L"C:\\MyFolder");
// Set the ImageConvertionType to extact pages
pageImage->setConversionType(SolidFramework::Converters::Plumbing::ImageConversionType::ExtractPages);
// Set the DPI to determine the dimensions of the images
pageImage->setPageDPI(300);
// Choose from the supported image file types
pageImage->setOutputType(SolidFramework::Converters::Plumbing::ImageDocumentType::Tiff);
// Set this if you only want to extract certain pages
pageImage->setPageRange(SolidFramework::PageRange::Parse(L"1-5"));
//Start the Conversion
cout << "Starting conversion." << endl; pageImage->Convert();
SolidFramework::Converters::Plumbing::ConversionStatus status = pageImage->getResults()->getItem(0)->getStatus();
if (status != SolidFramework::Converters::Plumbing::ConversionStatus::Success)
{
cout << "Conversion failed." << endl;
}
else
{
cout << "Conversion succeeded." << endl; } pageImage->Dispose();
cout << "Press to exit." << endl;
cin.get();
return 0;
}
VB.Net
Module ExtractImages
Sub Main()
' Call your Solid Documents License
SolidFramework.License.Import("C:\MyFolder\license.xml")
'Define a variable for your source file
Dim sPdfPath As String
' Define your Solid Framework Converter
Dim myConverter As SolidFramework.Converters.PdfToImageConverter
' Set your file path
sPdfPath = "C:\YourFolder\filepdf.pdf"
' Set the converter
myConverter = New SolidFramework.Converters.PdfToImageConverter
'Set the preferred conversion properties
' Add files to convert.
myConverter.AddSourceFile(sPdfPath)
' Detect Headers and Footers
myConverter.OutputDirectory = "C:\MyPDFImages\"
' Convert the file
myConverter.Convert()
' Clean up
myConverter.Dispose()
End Sub
End Module
