Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
||||||||||||||||||||||||||







Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
|
Gnostice Document Studio .NET |
Gnostice Document Studio Java |
Gnostice Document Studio Delphi |
eDocEngine VCL |
PDFtoolkit VCL |
StarDocs Web APIs |
UniGUI is a web-application development framework for Delphi. Gnostice now provides a native UniGUI component to easily add a multi-format document viewer to your web-application. The viewer supports PDF form filling and offers forms API, and events which enable an enriched form filling user experience. In this article we will look at the steps to be followed to add the viewer to your web application.
If you are new to StarDocs, we suggest you read the introductory article and the getting started article first. This article builds on the steps explained in those foundational articles to avoid repetition. At a minimum please follow the getting started article to download and install the StarDocs SDK for Delphi.You can download the test PDF file used in this demo from here.
A demo project based on this article is available for download from here. Unzip the file and follow the instructions in the Readme.txt file to build and run it.
procedure TMainForm.UniButton1Click(Sender: TObject);
begin
gtUniStarDocsViewer1.Load('C:\docs\SimpleForm.pdf');
end;
type
TMainForm = class(TUniForm)
...
private
procedure AddMessage(Msg: String);
...
end;
// Utility method to format and prepend a message to the memo field
procedure TMainForm.AddMessage(Msg: String);
begin
UniMemo1.Text := Msg + ' | ' + UniMemo1.Text;
end;
procedure TMainForm.gtUniStarDocsViewer1FormFieldChanged(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldChanged: [' + AFormField.FullyQualifiedName + ']');
end;
procedure TMainForm.gtUniStarDocsViewer1FormFieldClicked(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldClicked: [' + AFormField.FullyQualifiedName + ']');
end;
procedure TMainForm.gtUniStarDocsViewer1FormFieldEnter(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldEnter: [' + AFormField.FullyQualifiedName + ']');
end;
procedure TMainForm.gtUniStarDocsViewer1FormFieldExit(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldExit: [' + AFormField.FullyQualifiedName + ']');
end;
procedure TMainForm.gtUniStarDocsViewer1FormLoaded(Sender: TObject);
begin
AddMessage('OnFormLoaded');
end;
procedure TMainForm.gtUniStarDocsViewer1FormModified(Sender: TObject);
begin
AddMessage('OnFormModified');
end;
procedure TMainForm.gtUniStarDocsViewer1FormFieldClicked(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldClicked: [' + AFormField.FullyQualifiedName + ']');
if (AFormField.FullyQualifiedName = 'HelpButton') then
begin
showMessage('You clicked the ''Help'' button.<br>'
+ 'This popup is being shown in response to the ''onFormFieldClick'' event.');
end;
end;
procedure TUniForm1.UniButton1Click(Sender: TObject);
var
SelectedCountry: String;
begin
if (UniListBox1.ItemIndex <> -1) then
begin
SelectedCountry := UniListBox1.Items[UniListBox1.ItemIndex];
// Call Forms API to set the value to the text field
FTextFormField.SetValueAsString(SelectedCountry);
end;
end;
uses gtxUniStarDocsViewer;
type
TUniForm1 = class(TUniForm)
...
private
FTextFormField: TgtViewerPDFTextFormField;
public
procedure ShowPopup(AFormField: TgtViewerPDFTextFormField);
end;
procedure TUniForm1.ShowPopup(AFormField: TgtViewerPDFTextFormField);
begin
FTextFormField := AFormField;
Self.ShowModal();
end;
uses Unit1;
procedure TMainForm.gtUniStarDocsViewer1FormFieldEnter(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldEnter: [' + AFormField.FullyQualifiedName + ']');
if (AFormField.FullyQualifiedName = 'Country') then
begin
UniForm1.ShowPopup(AFormField as TgtViewerPDFTextFormField);
end;
end;
uses System.Generics.Collections;
type
TMainForm = class(TUniForm)
...
private
...
procedure GetAllFormFieldsCallBack(AFormFields: TList<TgtPDFFormField>);
end;
procedure TMainForm.gtUniStarDocsViewer1FormFieldClicked(ASender: TObject;
AFormField: TgtPDFFormField);
begin
AddMessage('OnFormFieldClicked: [' + AFormField.FullyQualifiedName + ']');
if (AFormField.FullyQualifiedName = 'HelpButton') then
begin
showMessage('You clicked the ''Help'' button.<br>'
+ 'This popup is being shown in response to the ''onFormFieldClick'' event.');
end
Else if (AFormField.FullyQualifiedName = 'SubmitButton') then
begin
// Call async method to get all the form fields. Once the form fields are
// fetched the callback procedure 'GetAllFormFieldsCallBack' will be called
gtUniStarDocsViewer1.Forms.GetAllFormFields(GetAllFormFieldsCallBack);
end
Else if (AFormField.FullyQualifiedName = 'ResetButton') then
begin
showMessage('You clicked the ''Reset'' button.<br>'
+ 'Using the Forms API we have reset the form.');
gtUniStarDocsViewer1.Forms.ResetForm();
end;
end;
procedure TMainForm.GetAllFormFieldsCallBack(AFormFields: TList<TgtPDFFormField>);
var
Index: Integer;
FormField: TgtPDFFormField;
MsgStr: String;
begin
// Need to take ownership of AFormFields
MsgStr := '';
try
// Loop through all the form fields and build a message to show to user
for Index := 0 to (AFormFields.Count - 1) do
begin
FormField := AFormFields.Items[Index];
if FormField is TgtViewerPDFTextFormField then
begin
MsgStr := MsgStr + FormField.FullyQualifiedName + ': ';
MsgStr := MsgStr + (FormField as TgtViewerPDFTextFormField).Value;
MsgStr := MsgStr + '<br>';
end;
end;
showMessage('You clicked the ''Submit'' button.<br>'
+ 'Here are the values entered in the form:<br>' + MsgStr);
finally
AFormFields.Free;
end;
end;
Many of the Forms API are asynchronous because after the server-side call is made the client side JavaScript needs to communicate with the viewer iframe and this communication is essentially an asynchronous, message-based one. Therefore all the asynchronous methods take a callback procedure which is invoked once the viewer iframe responds back with the requested data.
Finally we are ready to run the app and try it out. The screenshot below shows the lookup form being shown when the "Country" field gets focus.
---o0O0o---
| Our .NET Developer Tools | |
|---|---|
Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
PDFOne .NETA .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 DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA 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 JavaMulti-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 | |
|---|---|
StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
| Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2026 Gnostice Inc. All rights reserved. |