PDF with Delphi
PDF generation with Delphi
Also for Delphi developers we provide a sample application that shows how the COM interface of our PDF Maker can be integrated into your own Delphi applications and used for PDF generation. Complete your Delhi development with our PDF API!
When the code is executed, the PDF engine of our PDF Maker will be used for PDF generation. PDF creation takes into account the PDF settings that were previously set using the corresponding PDF Setting functions of the COM component.
After the PDF conversion has been triggered using the function convertToPDF
, the code waits for the return code of the PDF engine. This ensures that the developer knows exactly when and if the PDF generation was successfully completed.
The code sample below is available for download at the bottom of the page.
Source text extract of the source code example (Delphi)
- unit main;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ComObj, SevenPDFComObj_TLB;
- type
- TForm1 = class(TForm)
- txtReturncode: TEdit;
- Label1: TLabel;
- Label4: TLabel;
- txtFile: TEdit;
- btnCallConvert: TButton;
- btnSelect: TButton;
- Label2: TLabel;
- Label3: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label8: TLabel;
- Label9: TLabel;
- Label10: TLabel;
- Label11: TLabel;
- Label12: TLabel;
- Label13: TLabel;
- Label7: TLabel;
- txtPDF: TEdit;
- btnSelectPDF: TButton;
- Label14: TLabel;
- Label15: TLabel;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- procedure btnCallConvertClick(Sender: TObject);
- procedure btnSelectClick(Sender: TObject);
- procedure btnSelectPDFClick(Sender: TObject);
- private
- { Private-Deklarationen }
- public
- { Public-Deklarationen }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.btnCallConvertClick(Sender: TObject);
- var
- SevenPDFComObj : TSevenPDFObjConverter;
- InFile, OutFile : WideString;
- begin
- InFile := txtFile.Text;
- OutFile := txtPDF.Text;
- SevenPDFComObj := TSevenPDFObjConverter.Create(nil);
- try //finally
- try //exception
- //******* INITIALIZATION *********
- SevenPDFComObj.Init;
- //SevenPDFComObj.UnlockKey('INSERT LICENSEKEY!');
- //********************************
- //****** Customize some PDF Settings *******
- //Notice: PDF encryption works only in registered version
- //******************************************
- SevenPDFComObj.setExportNotes(0);
- SevenPDFComObj.setExportNotesPages(0);
- SevenPDFComObj.setExportBookmarks(0);
- //Set PDF Security Options
- {
- SevenPDFComObj.setEncryptFile(1);
- SevenPDFComObj.setPermissionPassword('test123');
- SevenPDFComObj.setRestrictPermissions(1);
- SevenPDFComObj.setChanges(0);
- SevenPDFComObj.setPrinting(1);
- SevenPDFComObj.setEnableCopyingOfContent(0);
- SevenPDFComObj.setEnableTextAccessForAccessibilityTools(0);
- }
- //Make the Conversion
- txtReturncode.Text := IntToStr(SevenPDFComObj.convertToPdf(PWideChar(InFile), PWideChar(OutFile), 0));
- except
- on E:Exception do // Exception abfangen, falls der User nicht die Rechte hat einen Task zu killen!
- begin
- ShowMessage('An exception occurs: ' + E.Message);
- end;
- end;
- finally
- if Assigned(SevenPDFComObj) then begin
- SevenPDFComObj.Free;
- end;
- end;
- end;
- procedure TForm1.btnSelectClick(Sender: TObject);
- begin
- if OpenDialog1.Execute then begin
- txtFile.Text := OpenDialog1.FileName;
- txtReturncode.Text := '';
- end;
- end;
- procedure TForm1.btnSelectPDFClick(Sender: TObject);
- begin
- if SaveDialog1.Execute then begin
- txtPDF.Text := ChangeFileExt(SaveDialog1.FileName, '.pdf');
- end;
- end;
- end.
Downloads
Attachement | Size |
---|---|
Download the code sample | 3.82 KB |