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)

  1. unit main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ComObj, SevenPDFComObj_TLB;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     txtReturncode: TEdit;
  12.     Label1: TLabel;
  13.     Label4: TLabel;
  14.     txtFile: TEdit;
  15.     btnCallConvert: TButton;
  16.     btnSelect: TButton;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     Label5: TLabel;
  20.     Label6: TLabel;
  21.     Label8: TLabel;
  22.     Label9: TLabel;
  23.     Label10: TLabel;
  24.     Label11: TLabel;
  25.     Label12: TLabel;
  26.     Label13: TLabel;
  27.     Label7: TLabel;
  28.     txtPDF: TEdit;
  29.     btnSelectPDF: TButton;
  30.     Label14: TLabel;
  31.     Label15: TLabel;
  32.     OpenDialog1: TOpenDialog;
  33.     SaveDialog1: TSaveDialog;
  34.     procedure btnCallConvertClick(Sender: TObject);
  35.     procedure btnSelectClick(Sender: TObject);
  36.     procedure btnSelectPDFClick(Sender: TObject);
  37.  
  38.   private
  39.     { Private-Deklarationen }
  40.   public
  41.     { Public-Deklarationen }
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.  
  47. implementation
  48.  
  49. {$R *.dfm}
  50.  
  51. procedure TForm1.btnCallConvertClick(Sender: TObject);
  52. var
  53.   SevenPDFComObj : TSevenPDFObjConverter;
  54.   InFile, OutFile : WideString;
  55.  
  56. begin
  57.  
  58.   InFile := txtFile.Text;
  59.   OutFile := txtPDF.Text;
  60.  
  61.   SevenPDFComObj := TSevenPDFObjConverter.Create(nil);
  62.  
  63.   try //finally
  64.     try //exception
  65.  
  66.       //******* INITIALIZATION *********
  67.  
  68.         SevenPDFComObj.Init;
  69.         //SevenPDFComObj.UnlockKey('INSERT LICENSEKEY!');
  70.  
  71.       //********************************
  72.  
  73.       //****** Customize some PDF Settings *******
  74.       //Notice: PDF encryption works only in registered version
  75.       //******************************************
  76.  
  77.         SevenPDFComObj.setExportNotes(0);
  78.         SevenPDFComObj.setExportNotesPages(0);
  79.         SevenPDFComObj.setExportBookmarks(0);
  80.  
  81.         //Set PDF Security Options
  82.         {
  83.         SevenPDFComObj.setEncryptFile(1);
  84.         SevenPDFComObj.setPermissionPassword('test123');
  85.         SevenPDFComObj.setRestrictPermissions(1);
  86.         SevenPDFComObj.setChanges(0);
  87.         SevenPDFComObj.setPrinting(1);
  88.         SevenPDFComObj.setEnableCopyingOfContent(0);
  89.         SevenPDFComObj.setEnableTextAccessForAccessibilityTools(0);
  90.         }
  91.  
  92.       //Make the Conversion
  93.  
  94.       txtReturncode.Text := IntToStr(SevenPDFComObj.convertToPdf(PWideChar(InFile), PWideChar(OutFile), 0));
  95.  
  96.     except
  97.     on E:Exception do   // Exception abfangen, falls der User nicht die Rechte hat einen Task zu killen!
  98.       begin
  99.         ShowMessage('An exception occurs: ' + E.Message);
  100.       end;
  101.     end;
  102.    
  103.   finally
  104.     if Assigned(SevenPDFComObj) then begin
  105.       SevenPDFComObj.Free;
  106.     end;
  107.   end;
  108.  
  109. end;
  110.  
  111. procedure TForm1.btnSelectClick(Sender: TObject);
  112. begin
  113.   if OpenDialog1.Execute then begin
  114.     txtFile.Text := OpenDialog1.FileName;
  115.     txtReturncode.Text := '';
  116.   end;
  117. end;
  118.  
  119. procedure TForm1.btnSelectPDFClick(Sender: TObject);
  120. begin
  121.     if SaveDialog1.Execute then begin
  122.     txtPDF.Text := ChangeFileExt(SaveDialog1.FileName, '.pdf');
  123.   end;
  124. end;
  125.  
  126. end.

Downloads

Attachement Size
Download the code sample 3.82 KB
LiveZilla Live Chat Software
Top