|
Tutorial - Using PDF Engine |
Top Previous Next |
|
This section contains tutorials specific to PDF documents. They are
6.Page & Document Level Action
To create an application for inserting annotations:
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.
Explanation: This tutorial creates text annotation using the TgtPDFTextAnnot class and set all their properties. To add the text annotation to the document using AddAnnotItem of TgtPDFEngine.
Delphi:
procedure TForm1.Button1Click(Sender: TObject); var LLineAnnot: TgtPDFLineAnnot; LTextAnnot: TgtPDFTextAnnot; LLinkAnnot: TgtPDFLinkAnnot; LURIAction: TgtAnnotLinkAction; LLaunchAction: TgtAnnotLaunchAction; LGotoAction: TgtAnnotGoToAction; LNamedAction: TgtAnnotNamedAction; LRemoteGotoAction: TgtAnnotRemoteGotoAction; LJavaScriptAction: TgtAnnotJSAction; LFreeTextAnnot: TgtPDFFreeTextAnnot; LSquareAnnot : TgtPDFSquareAnnot; LCircleAnnot : TgtPDFCircleAnnot; LPolygonAnnot : TgtPDFPolygonAnnot; LTextMarkupAnnot : TgtPDFTextMarkupAnnot; LInkAnnot : TgtPDFInkAnnot; LCaretAnnot : TgtPDFCaretAnnot; LPolylineAnnot : TgtPDFPolylineAnnot; begin with gtPDFEngine1 do begin FileName := 'Output'; BeginDoc; Font.Style := [fsBold]; Font.Color := clRed; Font.Size := 20; TextOut(3,1.3,'Annotations Demo'); Font.Style := [fsUnderline]; Font.Color := clBlack; Font.Size := 12; TextOut(3.6,1.8,'Line Annotations'); LLineAnnot := TgtPDFLineAnnot.Create; with LLineAnnot do begin BorderStyle := brDashed; BorderPattern := '1.2 1.3'; BorderWidth := 5; StartStyle := lsRClosedArrow; EndStyle := lsButt; BorderColor := clGreen; InteriorColor := clYellow; Line := gtLine(2.5,2.3,4,2.3); Title := 'Annotations Demo'; Subject := 'Line Annotation'; Contents := 'This Demo shows how to create a Line Annotation'; end; AddAnnotItem(LLineAnnot); LLineAnnot := TgtPDFLineAnnot.Create; with LLineAnnot do begin BorderStyle := brSolid; BorderPattern := '1.2 1.3 4.5 3.3'; BorderWidth := 2; StartStyle := lsDiamond; EndStyle := lsROpenArrow; BorderColor := clBlue; InteriorColor := clRed; Line := gtLine(4.5,2.3,6,2.3); Title := 'Annotations Demo'; Subject := 'Line Annotation'; Contents := 'This Demo shows how to create Line annotation'; end; AddAnnotItem(LLineAnnot); TextOut(3.6, 2.8, 'Circle Annotations');
LCircleAnnot := TgtPDFCircleAnnot.Create; with LCircleAnnot do begin Rect := gtRect(2.5,3.3,4,4.3); BorderColor := clRed; BorderStyle := brDashed; BorderWidth := 5; BorderPattern := '1.2 2.3 4.4'; //Contents := 'This Demo shows how to create a Circle Annotation. Interior color is not set. Cloud Intensity is nil'; Title := 'Circle Annot'; Subject := 'eDocEngine Demo'; Contents := 'This shows how to create circle annotation'; end; AddAnnotItem(LCircleAnnot);
LCircleAnnot := TgtPDFCircleAnnot.Create; with LCircleAnnot do begin Rect := gtRect(4.5,3.6,6,4); BorderColor := clBlue; BorderStyle := brDashed; BorderWidth := 3; BorderPattern := '1.2 0'; InteriorColor := clAqua; Cloudy := True; CloudIntensity := 1; Contents := 'This Demo shows how to create a Circle Annotation. Cloud Intensity is less'; end; AddAnnotItem(LCircleAnnot); TextOut(3.6, 4.5, 'Square Annotations'); LSquareAnnot := TgtPDFSquareAnnot.Create; with LSquareAnnot do begin Rect := gtRect(2.5,5,4,6); BorderColor := clBlue; BorderStyle := brDashed; BorderWidth := 5; BorderPattern := '1.2 2.3 4.4'; Contents := 'This Demo shows how to create a Square Annotation. Interior color is not set. Cloud Intensity is nil'; Title := 'Square Annot'; Subject := 'eDocEngine Demo'; end; AddAnnotItem(LSquareAnnot);
LSquareAnnot := TgtPDFSquareAnnot.Create; with LSquareAnnot do begin Rect := gtRect(4.5,5.1,6,5.9); BorderColor := clYellow; BorderStyle := brDashed; BorderWidth := 3; BorderPattern := '1 1'; InteriorColor := clGreen; Cloudy := True; CloudIntensity := 2; Contents := 'This Demo shows how to create a Square Annotation. Cloud Intensity is more '; Title := 'Square Annot'; Subject := 'eDocEngine Demo'; end; AddAnnotItem(LSquareAnnot); TextOut(3.6, 6.5, 'Polygon Annotations'); LPolygonAnnot := TgtPDFPolygonAnnot.Create; with LPolygonAnnot do begin Contents := 'This Demo shows how to create a Polygon Annotation'; BorderColor := clHighlight; BorderStyle := brDashed; BorderWidth := 3; InteriorColor := clRed; SetVertices([gtPoint(4,7.3), gtPoint(5.4,8.3),gtPoint(4,9.3), gtPoint(4.4,8.3)]); Title := 'Polygon Annot'; Subject := 'eDocEngine Demo'; Cloudy := True; end; AddAnnotItem(LPolygonAnnot);
TextOut(3.6, 10, 'Caret Annotations'); Font.Size := 10; Font.Style := []; TextOut(2, 10.5,' Caret annotation displays the missing information in the pop up window.'); Font.Size := 12; Font.Style := [fsUnderline];
LCaretAnnot := TgtPDFCaretAnnot.Create; with LCaretAnnot do begin Rect := gtRect(5, 10.6, 5.1, 10.7); BorderColor := clRed; Contents := 'like this text here'; end; AddAnnotItem(LCaretAnnot);
NewPage;
TextOut(3.4, 1.3, 'PolyLine Annotations');
LPolylineAnnot := TgtPDFPolylineAnnot.Create; with LPolylineAnnot do begin Contents := 'This Demo shows how to create a Polyline Annotation'; BorderColor := clPurple; BorderWidth := 3; InteriorColor := clGreen; SetVertices([gtPoint(3.3,2.8), gtPoint(4.0,1.7), gtPoint(4.7,2.8), gtPoint(3.3,2), gtPoint(4.7,2), gtPoint(3.6,2.6)]); EndStyle := lsOpenArrow; StartStyle := lsROpenArrow; end; AddAnnotItem(LPolylineAnnot);
TextOut(3.5, 3, 'Text Annotations');
LTextAnnot := TgtPDFTextAnnot.Create; with LTextAnnot do begin Name := tnComment; Open := True; Rect := gtRect(4,3,4.7,3.5); Title := 'Annotations Demo'; Subject := 'Text Annotation'; BorderColor := clRed; Contents := 'This Demo shows how to create Text annotation'; end; AddAnnotItem(LTextAnnot);
LTextAnnot := TgtPDFTextAnnot.Create; with LTextAnnot do begin Name := tnKey; Open := False; Rect := gtRect(3.3,3,4.5,3.5); Title := 'Annotations Demo'; Subject := 'Text Annotation'; BorderColor := clGreen; Contents := 'This Demo shows how to create a Text Annotation'; end; AddAnnotItem(LTextAnnot);
LTextAnnot := TgtPDFTextAnnot.Create; with LTextAnnot do begin Name := tnHelp; Open := False; Rect := gtRect(4.7,3,4.8,3.5); Title := 'Annotations Demo'; Subject := 'Text Annotation'; BorderColor := clBlue; Contents := 'This Demo shows how to create a Text Annotation'; end; AddAnnotItem(LTextAnnot);
TextOut(3.3, 4, 'FreeText Annotations');
LFreeTextAnnot := TgtPDFFreeTextAnnot.Create; with LFreeTextAnnot do begin Contents := 'This is FreeText Annotation. This is not a pop up annotation'; Rect := gtRect(3,4.5,5.5,5.2); BorderColor := clMaroon; TextFont.Size := 12; TextColor := clGreen; TextAlign := taRight; end; AddAnnotItem(LFreeTextAnnot);
TextOut(3.3, 5.5, 'TextMarkUp Annotations'); Font.Style := []; Font.Size := 10; LTextMarkupAnnot := TgtPDFTextMarkupAnnot.Create; with LTextMarkupAnnot do begin TextStyle := tsSquiggly; BorderColor := clRed; Title := 'Polygon Annot'; Subject := 'eDocEngine Demo'; SetQuadPoints([gtPoint(3,5.9),gtPoint(5.5,5.9),gtPoint(3,6.2),gtPoint(5.5,6.2)]); Contents:= 'This Demo shows how to create a TextMarkup Annotation'; Textout(3,6,'This is Squiggly Text Markup Annotation'); end; AddAnnotItem(LTextMarkupAnnot);
LTextMarkupAnnot := TgtPDFTextMarkupAnnot.Create; with LTextMarkupAnnot do begin TextStyle := tsUnderline; BorderColor := clGreen; SetQuadPoints([gtPoint(3,6.4),gtPoint(5.5,6.4),gtPoint(3,6.7),gtPoint(5.5,6.7)]); Contents:= 'This Demo shows how to create a TextMarkup Annotation'; Textout(3,6.5,'This is Underline Text Markup Annotation'); end; AddAnnotItem(LTextMarkupAnnot);
LTextMarkupAnnot := TgtPDFTextMarkupAnnot.Create; with LTextMarkupAnnot do begin TextStyle := tsHighlight; BorderColor := clYellow; SetQuadPoints([gtPoint(3,7),gtPoint(5.5,7),gtPoint(3,7.2),gtPoint(5.5,7.2)]); Contents:= 'This Demo shows how to create a TextMarkup Annotation'; Textout(3,7,'This is Highlight TextMarkup Annotation'); end; AddAnnotItem(LTextMarkupAnnot);
LTextMarkupAnnot := TgtPDFTextMarkupAnnot.Create; with LTextMarkupAnnot do begin TextStyle := tsStrikeOut; BorderColor := clBlue; SetQuadPoints([gtPoint(3,7.4),gtPoint(5.5,7.4),gtPoint(3,7.7),gtPoint(5.5,7.7)]); Contents:= 'This Demo shows how to create a TextMarkup Annotation'; Textout(3,7.5,'This is StrikeOut TextMarkup Annotation'); end; AddAnnotItem(LTextMarkupAnnot);
Font.Style := [fsUnderline]; Font.Size := 12;
TextOut(3.5, 8, 'Ink Annotation');
LInkAnnot := TgtPDFInkAnnot.Create; with LInkAnnot do begin BorderColor := clBlue; SetInkPoints([gtPoint(1,8.5),gtPoint(1.5,9),gtPoint(2,8.5),gtPoint(2.5,9), gtPoint(3,8.5),gtPoint(3.5,9),gtPoint(4,8.5),gtPoint(4.5,9), gtPoint(5,8.5),gtPoint(5.5,9),gtPoint(6,8.5),gtPoint(6.5,9), gtPoint(7,8.5),gtPoint(7.5, 8.75),gtPoint(7,9),gtPoint(6.5,8.5), gtPoint(6,9),gtPoint(5.5,8.5),gtPoint(5,9),gtPoint(4.5,8.5), gtPoint(4,9),gtPoint(3.5,8.5),gtPoint(3,9),gtPoint(2.5,8.5), gtPoint(2,9),gtPoint(1.5,8.5),gtPoint(1,9)]); Contents := 'This shows how to create Ink Annotation'; end; AddAnnotItem(LInkAnnot);
TextOut(3.5, 9.2, 'Link Annotation'); Font.Size := 10; Font.Style := [];
LLaunchAction := TgtAnnotLaunchAction.Create; with LLaunchAction do begin FilePath := ExtractFileDir(Application.ExeName) + '\Test.txt'; NewWindow := True; end;
LLinkAnnot := TgtPDFLinkAnnot.Create; with LLinkAnnot do begin BorderColor := clBlue; Action := LLaunchAction; Rect := gtRect(1, 9.5, 1.6, 9.65); Font.Color := clBlue; TextOut(1, 9.5, 'Click here'); TextOut(1, 9.8, 'Click here'); TextOut(1, 10.1, 'Click here'); TextOut(1, 10.4, 'Click here'); TextOut(1, 10.7, 'Click here'); TextOut(1, 11, 'Click here');
Font.Color := clBlack; TextOut(1.7, 9.5, ' - Launch Action: Launches any files in their respective applications'); TextOut(1.7, 9.8, ' - GoTo Action: Navigates within the current PDF document'); TextOut(1.7, 10.1, ' - Named Action: Navigates to either next, previous, first or last pages of the current document'); TextOut(1.7, 10.4, ' - RemoteGoto Action: Opens another PDF document'); TextOut(1.7, 10.7, ' - JavaScript Action: Executes Java Scripts'); TextOut(1.7, 11, ' - URI Action: Opens specified URI'); end; AddAnnotItem(LLinkAnnot);
LGotoAction := TgtAnnotGoToAction.Create; with LGotoAction do begin Page := 1; Zoom := 1; end;
LLinkAnnot := TgtPDFLinkAnnot.Create; with LLinkAnnot do begin BorderColor := clBlue; Action := LGotoAction; Rect := gtRect(1, 9.8, 1.6, 9.95); end; AddAnnotItem(LLinkAnnot);
LNamedAction := TgtAnnotNamedAction.Create; LNamedAction.ActionName := anPrevPage;
LLinkAnnot := TgtPDFLinkAnnot.Create; with LLinkAnnot do begin BorderColor := clBlue; Action := LNamedAction; Rect := gtRect(1, 10.1, 1.6, 10.25); end; AddAnnotItem(LLinkAnnot);
LRemoteGotoAction := TgtAnnotRemoteGotoAction.Create; with LRemoteGotoAction do begin FilePath := 'Test.pdf'; Zoom := 2; Page := 1; NewWindow := True; end;
LLinkAnnot := TgtPDFLinkAnnot.Create; with LLinkAnnot do begin BorderColor := clBlue; Action := LRemoteGotoAction; Rect := gtRect(1, 10.4, 1.6, 10.55); end; AddAnnotItem(LLinkAnnot);
LJavaScriptAction := TgtAnnotJSAction.Create; with LJavaScriptAction do begin JavaScript := 'app.alert("Gnostice Information Technologies Private Limited")'; end;
LLinkAnnot := TgtPDFLinkAnnot.Create; with LLinkAnnot do begin BorderColor := clBlue; Action := LJavaScriptAction; Rect := gtRect(1, 10.7, 1.6, 10.85); end; AddAnnotItem(LLinkAnnot);
LURIAction := TgtAnnotLinkAction.Create; with LURIAction do begin URI := 'www.gnostice.com'; end;
LLinkAnnot := TgtPDFLinkAnnot.Create; with LLinkAnnot do begin BorderColor := clBlue; Action := LURIAction; Rect := gtRect(1, 11, 1.6, 11.15); end; AddAnnotItem(LLinkAnnot); EndDoc; end; end;
5. Run the application. Click 'Insert Annotation' button on the form to see the change in the 'Output.pdf' file.
To create an application:
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.
procedure TForm1.Button1Click(Sender: TObject); var LDocInfo: TgtPDFCustomDocInfo; begin with gtPDFEngine1 do begin FileName := 'C:\Output'; BeginDoc; // Do not free this instance. Engine will take care. LDocInfo := TgtPDFCustomDocInfo.Create; with LDocInfo do begin // Set the properties for the CustomDocInfo Schema := schAdobePDF; Name := 'Form Page No'; Value := '8'; end; // Add the information to the PDF. AddCustomDocInfo(LDocInfo); EndDoc; end; end;
5. Run the application. Click 'Custom Document Info' button on the form to see the change in the 'Output.pdf' file.
To create an application:
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.
Delphi procedure TForm1.Button1Click(Sender: TObject); begin with gtPDFEngine1 do begin FileName := 'Output'; BeginDoc; Font.Name := 'Arial'; Font.Size := 14; // Set the Rotation Angle if needed SetTextRotation(45); // Call the TextOutV procedure for rendering // vertical text TextOutV(1, 1, 'Welcome to Gnostice eDocEngine', True); EndDoc; end; end;
C++Builder
void __fastcall TForm1::Button1Click(TObject *Sender) { gtPDFEngine1->FileName = "Output"; gtPDFEngine1->BeginDoc(); gtPDFEngine1->Font->Name = "Arial"; gtPDFEngine1->Font->Size = 14; // Set the Rotation Angle if needed gtPDFEngine1->SetTextRotation(45); // Call the TextOutV procedure for rendering // vertical text gtPDFEngine1->TextOutV(1, 1, "Welcome to Gnostice eDocEngine", True); gtPDFEngine1->EndDoc(); }
5. Run the application. Click 'Vertical Text Rendering' button on the form to see the rendered text in 'Output.pdf' file.
To create an application to set Page and Document Level Actions follow these steps:
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.
procedure TForm1.Button1Click(Sender: TObject); var LFileAnnot: TgtPDFFileAttachmentAnnot; begin with gtPDFEngine1 do begin FileName := 'C:\Output'; BeginDoc; // Do not free this instance. Engine will take care. LFileAnnot := TgtPDFFileAttachmentAnnot.Create; with LFileAnnot do begin // Path of the file that needs to be attached AttachedFilename := 'C:\Sample.doc'; FileAttachmentIcon := faTag; Rect := gtRect(3,3,4,4); BorderColor := clBlue; Contents := 'This is File Attachment Demo in PDF'; end; // Add the annotation to the PDF. AddAnnotItem(LFileAnnot); EndDoc; end; end;
5. Run the application. Click 'File Attachments' button on the form to see the change in the 'Output.pdf' file.
To create an application to set Page and Document Level Actions follow these steps:
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.
Delphi:
procedure TForm1.Button1Click(Sender: TObject); begin with gtPDFEngine1 do begin FileName := 'Output'; BeginDoc; Font.Color := clRed; Font.Size := 20; TextOut(1, 1, 'Auto Link Activation'); Font.Color := clBlack; Font.Size := 12; TextOut(1, 2, 'This demo shows the feature of activating links in texts.'); TextOut(1, 3, 'Web links like http://www.gnostice.com are activated automatically.'); TextOut(1, 4, 'Even email ids like info@gnostice.com are hyperlinked.'); TextOut(1, 5, 'FTP sites ftp://www.yourcompany.com are also activated.'); //This needs Test.txt |