Document Studio Delphi
Next-generation multi-format document-processing component suite for Delphi/C++Builder developers
Compatibility
VCL - FireMonkey - Delphi - C++Builder

Display data-aware PDF forms or AcroForms using Delphi

Learn to display form fields values loaded from a data source using XtremeDocumentStudio Delphi.
By Ramnish R

In March this year, we released a version of XtremeDocumentStudio Delphi that added the ability to display data-aware form fields on the VCL document viewer control. Two new properties have been introduced to make this possible - FieldDataSource and FieldMapping. You need to first connect FieldDataSource to a data source on your computer. Then, you need to use FieldMapping to map the names of the form fields in the PDF document to column names in the data source.

public property FieldDataSource: TDataSource;
public function FieldMapping(FieldName: string): TgtFieldDataLink; virtual;
public: __property TDataSource FieldDataSource;
public: virtual __fastcall TgtFieldDataLink FieldMapping(AnsiString FieldName);

In the TgtFieldDataLink type, you will be mostly interested in DataFieldName and ValueMappings properties. The former is for identifying the form field. The latter is a name-value pair that is used to set the value of the form field in the document and the actual value that is submitted when the former gets chosen by the end-user or code.

public property DataFieldName: string;
public property ValueMappings: TDictionary;
public: __property AnsiString DataFieldName;
public: __property TDictionary ValueMappings;

Here is an example of using this new feature.

  1. Start your IDE and open a new VCL Forms Application project.
  2. Drop the following components on the form.
    • TDBGrid
    • TDataSource
    • TgtDocumentViewer
    • TButton (2)
    The TDataSource needs to be linked to a data set object. For simplicity, I have used a TADODataSet to load values from an Access database (NorthWind). You can choose some other component for your data source.
  3. Set up your dataset properly so that it displays data in the grid at design-time.
  4. In the first button "click" event handler, set the data source of the viewer and map the form field in the document to column names in the data source. Then, load the document containing the form fields.
    gtDocumentViewer1.FieldDataSource := DataSource1;
    gtDocumentViewer1.FieldMapping('f1_1[0]').DataFieldName := 'FirstName';
    
    gtDocumentViewer1.LoadFromFile(
      'C:\Users\egg\Documents\Gnostice\XtremeDocumentStudio Delphi'+
      '\Demos\Delphi\VCL\7. Document Viewer - Data aware Interactive forms'+
      '\Sample_tax_form.pdf');
    
  5. Set the second button's "click" event handler to save the PDF form with the values from the selected record on the DB grid.
    gtDocumentViewer1.SaveToFile('Sample_tax_form_MODIFIED.pdf');
    
  6. Run the project, click the first button, select a record and click the second button to save the values from the record to the PDF.

Of course, this example does not exactly map the form fields to columns in the database. For that, you will need to create a specialized database "view" and then display it in the grid.

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2025 Gnostice Information Technologies Private Limited. All rights reserved.