logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Digital signing of files with FastReport VCL
  • How to make a PDF from Delphi / C++Builder / Lazarus

    May 14, 2020

    Quite often, you need to get a PDF document from a Pascal application - either

    read more
  • How to create an interactive PDF form for HR interviews in Delphi and Lazarus

    December 14, 2020

    Someone might not know, but the PDF standard allows you to create fillable forms. That

    read more
  • How to create one single report out of several in Delphi / Lazarus / C++ Builder

    December 11, 2020

    I would like to note that FastReport VCL is one of the most convenient components

    read more
  • Make Drill-Down report in VCL (Delphi / Lazarus)

    February 9, 2021

    "Drill Down" or "deepening into data" is a concept with many sides, which can refer

    read more
  • How to combine multiple reports into PDF file in Delphi

    September 3, 2020

    It is often necessary to combine several documents into one (for example, PDF). It could

    read more

Digital signing of files with FastReport VCL

December 12, 2022

Digital signing of files with FastReport VCL

It is hard to imagine our life without electronic document management. Such documents are convenient because they do not deteriorate over time, they are more difficult to lose, easy to store, and quickly transfer to any distance. But as it is known, only signed document comes into force.

Electronic signatures are ciphers that guarantee uniqueness and originality, allowing to establish a definitive authorship and protect the document from changes.

However, signing every generated PDF file can be time-consuming. What if you have a thousand or more generated files — should you sign them manually? Of course not. FastReport VCL can sign the generated files with your signature. Next, we will look into an example of digital signing.

For clarity, we will use a small application that exports files to PDF and signs them.

procedure TForm1.Button1Click(Sender: TObject);
const
 FR3FileName = 'Signatures.fr3';
var
 PDFExport: TfrxPDFExport;
 Report: TfrxReport;
begin
 Report := TfrxReport.Create(nil);
 try
 Report.LoadFromFile(FR3FileName);
 Report.PrepareReport; // upload and prepare a report
 
 PDFExport := TfrxPDFExport.Create(nil);
 try
 PDFExport.Report := Report;
 PDFExport.ShowDialog := False;
 
 
 PDFExport.FileName := ExtractFileName(FR3FileName) + '.pdf';
 Report.Export(PDFExport); // export the report
 SignExport(PDFExport); // sign the file
 finally
 PDFExport.Free;
 end;
 finally
 Report.Free;
 end;
end;
 
procedure SignExport(PDFExport: TfrxPDFExport);
const
 CertificatePath = 'JaneDoe.pfx'; // The name of our certificate
 PasCert = '123'; // certificate password
var
 Lookup: TCertificateStoreLookup;
 FS: TfrxFileSignature;
 FSO: Integer;
begin
 Lookup := TCertificateStoreLookup.Create;
 Lookup.IgnoreCase := true;
 Lookup.CertificatePath := CertificatePath;
 
 FSO := FileSignatureOptions(
 true, // Detached = true Signature in a detached file
 false, // Chain = false Certificate chain
 false, // OnlyGOST= true GOST certificate
 true, // DebugLog = true Debugging Information
 true); // PFX = false (true) indicates that the certificate should be searched in the pfx/p12 file. 
At the same time, the file name and, possibly, the password must be specified.
 
 FS := TfrxFileSignature.Create(
 Lookup,
 PDFExport.FileName, // PDF file name
 PDFExport.FileName + '.sig', // Name of the generated signature
 AnsiString(PasCert),
 FSO);
 
 FS.Sign;
 FS.Free;
 Lookup.Free;
end;

After writing the program, let's move on to running it.

Test program window

After starting, click on the "Export" button. Then we get a signed PDF file with a signature file:

Received files after the successful signature of the document

We should check whether the PDF file was signed correctly. For this, open the console and enter the following commands:

openssl pkcs12 -in JohnDoe.pfx -out JohnDoe.pem

After we enter the password and check with the following command:

openssl smime -verify -binary -inform DER -in Signatures.fr3.pdf.sig -content Signatures.fr3.pdf 
-certfile JohnDoe.pem -nointern -noverify 1> /dev/null

 

Document signature check

This screenshot shows that the PDF file has passed the signature check, so we did it.

Thus, we got a properly exported PDF file signed using FastReport VCL in a fast and easy way.

about product buy
avatar
Marat Alaev
QA
Fast Reports Team: Marat Alaev - Quality Assurance at Fast Reports
VCL Lazarus FastReport PDF Delphi

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • FAQ
  • Tutorial Video
  • Forum
  • Support SLA
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy

Trustpilot