SplitDocumentToFiles
Page manipulation, Document assembly
Description
Splits the selected document into a batch of output files with a fixed number of pages each, parsing the source only once.
Syntax
Delphi
Function TPDFlib.SplitDocumentToFiles(Const FileNameTemplate: WideString; PagesPerFile: Integer): Integer;Parameters
| FileNameTemplate | Output file name pattern. A %p placeholder is replaced with the 1-based output file number; without a placeholder the number is inserted before the file extension. |
|---|---|
| PagesPerFile | Number of pages per output file. Pass 1 to burst the document into single-page files. |
Return values
| 0 | Invalid arguments, or writing a chunk failed. |
|---|---|
| N | The number of output files written. |
Remarks
The selected document is parsed once and every chunk is copied from the same in-memory object graph, so splitting a large document is dramatically faster than calling ExtractFilePages in a loop, which re-opens and re-parses the input file for every range. The final file receives the remaining pages when the page count is not an exact multiple of PagesPerFile. The selected document is not modified.
Example
PDF.LoadFromFile('report.pdf', '');
// report.pdf has 5 pages: writes burst-1.pdf (2), burst-2.pdf (2), burst-3.pdf (1)
PDF.SplitDocumentToFiles('burst-%p.pdf', 2);