Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







In this article, we will see part of the code that was used in the CodeRageĀ II Gnostice session titled Top 5 PDF User Needs Solved using Gnostice PDF Tools. One of the top PDF-related needs that we addressed in the demo was about splitting PDF documents based on a given criteria.
In the session, we demonstrated how to split a PDF documents by its bookmarks. Imagine that you have a PDF document where the content is divided into several chapters. If each of these chapters have a corresponding bookmark, then we could split the document in such a manner that each chapter would be available in a separate PDF document.
The main procedure in the code was SplitByBookmark. It uses a function GetFirstBookmarkWithSiblings recursively to parse the bookmark tree of the PDF document and return bookmark nodes that have child bookmarks.
// Object used to load // the input PDF document PDFDoc: TgtPDFDocument; edOutputFile: TEdit; ... procedure TSplitByBkmark.SplitByBookmark; function GetFirstBookmarkWithSiblings: TgtPDFOutline; begin // Get hold of root bookmark object and then the // first node, which is always the first // child of the root with PDFDoc do begin Result := GetBookmarkRoot; if Result = nil then Exit; Result := Result.GetFirstChild; // Traverse down the bookmark tree until multiple // siblings are found at the same level while (Result.GetNextNode = nil) and (Result <> nil) do Result := Result.GetFirstChild; end; end; var LBookmark1: TgtPDFOutline; begin with PDFDoc do begin LBookmark1 := GetFirstBookmarkWithSiblings; if LBookmark1 = nil then begin ShowMessage( 'The specified document does not contain ' + 'bookmarks.'#13#10 + 'Aborting splitting operation.'); LSplitDone := False; Exit; end; // Loop through all bookmarks in the same level while LBookmark1.GetNextNode <> nil do begin // Use bookmark title text for the name of // the output document and copy pages until // page linked by the next bookmark is reached ExtractPagesTo( MakeOutputFilename(edOutputFile.Text, LBookmark1.Title), Format('%d-%d', [LBookmark1.Destination.PageNo, LBookmark1.GetNextNode.Destination.PageNo - 1])); LBookmark1 := LBookmark1.GetNextNode; end; // Copy last chapter into new document ExtractPagesTo( MakeOutputFilename(edOutputFile.Text, LBookmark1.Title), Format('%d-%d', [LBookmark1.Destination.PageNo, PageCount])); LSplitDone := True; end; end;
The procedure also uses a function MakeOutputFilename that creates valid output filenames by appending the text used to display the bookmark to the original filename. Invalid filename characters are automatically stripped out of the resulting filename.
Downloads:
---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).