TImageEnIO.LoadFromFilePDF
Declaration
function LoadFromFilePDF(const FileName: string; Width: Integer = -1; Height: Integer = -1; const Password: string = ''): Boolean;
Description
Loads a PDF image PDF into the attached
TImageEnView or
TIEBitmap using a plug-in.
You can optionally specify a size to load the PDF file to improve quality (the size will be automatically adjusted to maintain the aspect ratio).
If the file is encrypted you can specify the password (otherwise a password prompt will be displayed if
AutoPromptForPassword is enabled).
Result will be false if the file is not PDF format or no PDF plug-ins are available (
Aborting will be true). Loading errors due to a file not being available will raise an exception.
PDF loading requires one of the following plug-ins:
◼ImageEn PDFium Plug-in from:
www.imageen.com/download/◼WPViewPDF commercial plug-in◼ImageMagick + GhostScriptNote:
◼PDF loading creates a rasterized image of each page (unless
PdfViewer = True)
◼To manipulate PDF files, enable
PdfViewer◼Use
ImageIndex to specify which page of the PDF file to load
◼Read more about
ImageEn PDF Support// Load the 3rd page of a PDF file with max dimensions of 1000x1000
ImageEnView1.ImageIndex := 2;
ImageEnView1.IO.LoadFromFilePDF( 'C:\Test.pdf', 1000, 1000 );
// Display a PDF document
ImageEnView1.PdfViewer.Enabled := True;
ImageEnView1.IO.LoadFromFilePDF( 'C:\document.pdf' );
// Merge two PDF documents
ImageEnView1.PdfViewer.Enabled := True;
ImageEnView1.IO.LoadFromFilePDF( 'C:\document.pdf' );
ImageEnView1.PdfViewer.ImportPages( 'C:\morepages.pdf' );
ImageEnView1.IO.SaveToFilePDF( 'C:\merged.pdf' );
// When rendering PDF files scale to double size
IEGlobalSettings().PdfViewerDefaults.DPI := 144; // PDF files are 72 DPI, so 144 is 200% size
ImageEnView1.IO.LoadFromFilePDF( 'C:\Test.pdf' );
// Save all pages of a PDF file to PNG
filename := 'C:\doc.pdf';
outputFolder := 'D:\';
IEGlobalSettings().PdfViewerDefaults.DPI := 144; // PDF files are 72 DPI, so 144 is 200% size
io := TImageEnIO.Create(nil);
idx := 0;
Repeat
io.Params.ImageIndex := idx;
io.LoadFromFilePDF( filename );
io.SaveToFile( IncludeTrailingBackSlash( outputFolder ) + format( '%s_%d.png', [ ExtractFilename( filename ), idx+1 ] ));
inc( idx );
Until idx > io.Params.ImageCount - 1;
io.Free;
// Or alternatively...
var
iev : TImageEnView;
idx : Integer;
begin
// Check PDF library available (shows error if not found)
IEGlobalSettings().PlugInAvailable([ iepiPDFium ], True );
iev := TImageEnView.Create(nil);
try
iev.PdfViewer.Enabled := True;
iev.IO.LoadFromFilePDF( 'C:\doc.pdf );
idx := 0;
Repeat
iev.IO.SaveToFileJpeg('D:\PageOut_' + idx.ToString + '.jpg');
inc( idx );
Until iev.IO.Seek( ieioSeekNext ) <> idx;
finally
iev.Free;
end;
end;
// Determine if a file is password protected
function PdfFileIsPasswordProtected(const Filename: string): Boolean;
var
iev: TImageEnView;
begin
Result := False;
try
iev := TImageEnView.Create(nil);
try
iev.PdfViewer.Enabled := True;
iev.IO.LoadFromFilePDF( Filename, -1, -1, '' );
finally
iev.Free;
end;
except
on e: Exception do
if e.Message = RsPdfErrorPassword then // Defined in iexPdfiumCore = 'Invalid password'
Result := True;
end;
end;
See Also
◼PdfViewer◼PdfViewerDefaults