Author: Jorge Abel Ayala Marentes
Adobe Acrobat PDF is a well known format that some users love, so how can I open
PDF files from a Delphi Application?
Answer:
Ok, you must have installed the Acrobat Reader program in your machine, if you
donīt have it you can download it from Adobeīs site:
www.adobe.comhttp://www.adobe.com
After that you have to install the type library for Acrobat (Project -> Import Type
Library from Delphiīs menu) select "Acrobat Control for ActiveX (version x)". Where
x stands for the current version of the type library. Click the install button to
install it into the IDE.
Now, Start a new Application, drop from whatever page of the component palette you
have installed a TPDF component in a form, next add an OpenDialog, and finally a
Button, in the Onclick event of the Button use:
1 procedure TForm1.Button1Click(Sender: TObject);
2 begin3 if OpenDialog1.Execute then4 pdf1.src := OpenDialog1.FileName;
5 end;
6 7 //in PdfLib_TLB Unit you can find the interface of the TPdf class in order to know 8 the behaviour of that class so here it is:
9 10 TPdf = class(TOleControl)
11 private12 FIntf: _DPdf;
13 function GetControlInterface: _DPdf;
14 protected15 procedure CreateControl;
16 procedure InitControlData; override;
17 public18 function LoadFile(const fileName: WideString): WordBool;
19 procedure setShowToolbar(On_: WordBool);
20 procedure gotoFirstPage;
21 procedure gotoLastPage;
22 procedure gotoNextPage;
23 procedure gotoPreviousPage;
24 procedure setCurrentPage(n: Integer);
25 procedure goForwardStack;
26 procedure goBackwardStack;
27 procedure setPageMode(const pageMode: WideString);
28 procedure setLayoutMode(const layoutMode: WideString);
29 procedure setNamedDest(const namedDest: WideString);
30 procedure Print;
31 procedure printWithDialog;
32 procedure setZoom(percent: Single);
33 procedure setZoomScroll(percent: Single; left: Single; top:
34 Single);
35 procedure setView(const viewMode: WideString);
36 procedure setViewScroll(const viewMode: WideString; offset:
37 Single);
38 procedure setViewRect(left: Single; top: Single; width: Single;
39 height: Single);
40 procedure printPages(from: Integer; to_: Integer);
41 procedure printPagesFit(from: Integer; to_: Integer; shrinkToFit:
42 WordBool);
43 procedure printAll;
44 procedure printAllFit(shrinkToFit: WordBool);
45 procedure setShowScrollbars(On_: WordBool);
46 procedure AboutBox;
47 property ControlInterface: _DPdf read GetControlInterface;
48 property DefaultInterface: _DPdf read GetControlInterface;
49 published50 property TabStop;
51 property Align;
52 property DragCursor;
53 property DragMode;
54 property ParentShowHint;
55 property PopupMenu;
56 property ShowHint;
57 property TabOrder;
58 property Visible;
59 property OnDragDrop;
60 property OnDragOver;
61 property OnEndDrag;
62 property OnEnter;
63 property OnExit;
64 property OnStartDrag;
65 property src: WideString index 1 read GetWideStringProp write66 SetWideStringProp stored False;
67 end;
finally hereīs an advice:
You canīt be sure your users will have Acrobat Reader installed so please fisrt check that situation before you take any actions with the TPdf component. And second if your PDF file have links for an AVI file for example, they donīt work from Delphi.