ImageEn, unit iexHelperFunctions

IECreatePDFFromFileList


Declaration

function IECreatePDFFromFileList(const sDestFilename: string;
                                 ssFileList: TStrings;
                                 const aPaperSize: TIOPDFPaperSize;
                                 const aCompression: TIOPDFCompression;
                                 const sTitle: string;
                                 const sAuthor: string;
                                 Margins: Integer = 0;
                                 Centered: Boolean = False;
                                 ShrinkOnly: Boolean = False;
                                 FailOnUnsupportedImage: Boolean = True
                                 ): Boolean;


Description

Generates a PDF file from all images specified in a TStrings list, by combining the functions of CreatePDFFile, SaveToPDF and ClosePDFFile.
Result is true unless an error is encountered.

Parameter Description
sDestFilename The .PDF filename to save the file to
ssFileList A list of all images to add to the PDF file
aPaperSize The size at which to create the PDF file
aCompression The level of compression to use
sTitle The title for the PDF document (appears in "Properties")
sAuthor The author for the PDF document (appears in "Properties")
Margins Specifies the size of margins (blank area) on all sides of the page when saving to PDF. Value is in Adobe PDF points (1 point = 1/72 of inch), e.g. 72 would be 1 inch margins
Centered Specifies that the image will be centered within the page (instead of positioned at the top-left)
ShrinkOnly If not enabled, all images will be made to fill the entire page. If enabled, only large images are shrunk. Small images are not enlarged
FailOnUnsupportedImage When true this procedure will fail if unsupported images (or other file types) are found in ssFileList. If false, unsupported file types are skipped

Note:
You must add the iexHelperFunctions unit to your uses clause
Delphi/C++ 2005 or newer is required
If the PDFEngine is ieenDLL, then PDFium will be used to create the PDF, otherwise native PDF code will be used
If you use ioPDF_JPEG as your compression, the default JPEG quality will be used


Examples

ssMyImages := TStringList.Create();
ssMyImages.Add( 'D:\image1.jpg' );
ssMyImages.Add( 'D:\image2.jpg' );
ssMyImages.Add( 'D:\image3.jpg' );

// 1 inch margins and centered images (shrink only)
if IECreatePDFFromFileList( 'D:\MyNewPDF.pdf',
                            ssMyImages,
                            iepA4,
                            ioPDF_JPEG,
                            'My Cool PDF',
                            'Mr Developer',
                            72, True, True ) = False then
    raise Exception.create( 'Cannot create PDF' );
ssMyImages.Free();

const
  PDF_Folder = 'D:\Album_Images';
  Fail_On_Unsupported_Image = True;
var
  ssImages: TStringList;
begin
  // Create PDF from all images in D:\Album_Images
  ssImages := TStringList.Create();
  GetAllFiles( PDF_Folder, ssImages );
  if IECreatePDFFromFileList( 'D:\MyNewPDF.pdf',
                              ssImages,
                              iepAuto, // Page matches size of the image
                              ioPDF_JPEG,
                              'My Cool PDF',
                              'Mr Developer',
                              0, // no margins around page
                              True, Fail_On_Unsupported_Image ) = False then
      raise Exception.create( 'Cannot create PDF' );
  ssImages.Free();
end;

See Also

TImageEnMIO.SaveToFilePDF
TImageEnIO.SaveToFilePDF