Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||||||
This article is written with the assumption that you don't want a whole lot of technical information about the PDF format or PDFtoolkit. Instead, we assume that you wish to know just how easily PDFtoolkit can help you work with PDF documents.
Still, if you require it, a good introduction to PDF is available in an earlier article titled PDFtoolkit v3.0 and its new PDF Processor. A introduction to PDFtoolkit architecture is another article titled PDFtoolkit At A Glance.
To illustrate the capabilities of PDFtoolkit, we created a demo application that performs these simple but necessary functions.
function LoadFromFile(const FileName: string): Boolean;
In PDFtoolkit VCL, TgtPDFDocument is the class representing a PDF document. To read a document, we call the LoadFromFile() function.
PDFDoc: TgtPDFDocument; ... PDFDoc.LoadFromFile('input_file.pdf');
property PageCount: Integer;
The TgtPDFDocument class has a PageCount property that will tell you the number of pages in a PDF document.
lblNoOfPages: TLabel; ... // Check if a document is loaded if PDFDoc.IsLoaded then lblNoOfPages.Caption := 'Number of Pages: ' + IntToStr(PDFDoc.PageCount);

procedure TextOut(HTMLStr: String;
XPos, YPos: Double); overload;
procedure TextOut(HTMLStr: String;
PageRange: String;
XPos, YPos: Double); overload;
You can write formatted text with simple HTML style tags to a PDF document using TextOut() method.
edPageRange: TEdit; edXcord: TEdit; edYCord: TEdit; if PDFDoc.IsLoaded then begin if edPageRange.Text <> '' then PDFDoc.TextOut('<i>Hello, <b>World!</b></i>', edPageRange.Text, StrToFloat(edXCord.Text), StrToFloat(edYCord.Text)) else PDFDoc.TextOut('<i>Hello, <b>World!</b></i>', StrToFloat(edXCord.Text), StrToFloat(edYCord.Text)); end;
You can use simple HTML tags such as b (bold), i (italic), s (strikeout), and u (underline).

procedure SetPageTransitionEffect(
PageRange: string;
Duration: Single;
TransitionEffect: TgtTransitionEffect); virtual;
PDF supports Microsoft® PowerPoint®-style page transitions. PDFtoolkit allows you to add transitions to pages using the SetPageTransitionEffect() method.
edTransitionPageRange: TEdit; cbTransitionEffect: TComboBox; edDuration: TEdit; ... PDFDoc.SetPageTransitionEffect( edTransitionPageRange.Text, StrToInt(edDuration.Text), TgtTransitionEffect(cbTransitionEffect.ItemIndex));
TgtTransitionEffect is an enumeration that defines various transition styles. To see page transitions in action, view the PDF in full screen in Adobe® Reader™.
procedure DeletePages(PageRange: string);
To delete a page, load the document, call the DeletePages() method, and save the document.
edDelPageRange: TEdit; ... if PDFDoc.IsLoaded then begin PDFDoc.DeletePages(Trim(edDelPageRange.Text)); SaveDocument; // See below end
procedure InsertPagesFrom( Document: TgtPDFDocument; Pages: string; InsertAfterPage: Integer); overload; virtual; procedure InsertPagesFrom( FileName: string; Pages: string; InsertAfterPage: Integer); overload; virtual;
You can insert pages from an existing document specified by its pathname or by a loaded TgtPDFDocument object.
edLoadSecondDoc: TEdit;
edInsertPages: TEdit;
edInsertafter: TEdit;
...
procedure TForm1.InsertPagesFromDoc;
var
LTempDoc: TgtPDFDocument;
begin
try
LTempDoc := TgtPDFDocument.Create(NIL);
LTempDoc.LoadFromFile(Trim(edLoadSecondDoc.Text));
if PDFDoc.IsLoaded then
begin
PDFDoc.InsertPagesFrom(
LTempDoc,
Trim(edInsertPages.Text),
StrToInt(edInsertafter.Text));
SaveDocument; // See below
end;
finally
LTempDoc.Free
end;
end;
procedure ExtractPagesTo(
Document: TgtPDFDocument;
PageRange: string); overload; virtual;
procedure ExtractPagesTo(
FileName: string;
PageRange: string); overload; virtual;
PDFtoolkit can extract pages to a specified pathname or a loaded TgtPDFDocument object.
procedure TForm1.ExtractPage;
begin
if PDFDoc.IsLoaded then
begin
// Extracts pages
PDFDoc.ExtractPagesTo(
edExtractPagesToFileName.Text,
edExtractPagesToPagerRange.Text);
end;
end;
procedure SaveToFile(
const FileName: string;
NeedAppearance: TgtNeedAppearanceState = naNoChange);
To save a file that has been loaded, call the SaveToFile() method.
edSaveTofile: TEdit; ... procedure TForm1.SaveDocument; begin if edSaveTofile.Text <> '' then begin PDFDoc.ShowSetupDialog := False; PDFDoc.OpenAfterSave := True; PDFDoc.SaveToFile(Trim(edSaveTofile.Text),naEnable); end else PDFDoc.SaveToFile('Output.pdf'); end;
Next month, we will continue this series with some other everyday PDF-related tasks that can be performed with PDFtoolkit.
Downloads:
| Privacy | Legal | Feedback | Newsletter | © 2002-2010 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 users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.