<< Click to Display Table of Contents >> Navigation: Create a PDF Editor > Delphi Example > Add dialog to create form fields |
Our PDF edit demo program features a dialog to create a form.
It can be used to customize most properties of acroform widgets.
You find this dialog in directory PDFEdit\WPViewFieldForm.pas
To use this dialog add the from to your project so it is automatically created call it like this:
begin
// assign the current Viewer - we actually assign the function so this stays current!
WPDFFields.WPViewPDF1 := pdf;
WPDFFields.Show; // Not modal!
end;
Please note that "WPViewPDF1" has been defined a function:
WPViewPDF1 : function : TWPViewPDF of Object;
So, although it looks like an object reference, it actually is a function which always provides the current Editor.
This makes it possible to work with different instances of WPViewPDF, as our implementation examples does.
The dialog is opened in a non-modal way, it remains open.
To a field just to click on "Insert field ad draw widget" and then draw a frame in the current viewer.
procedure TWPDFFields.btnInsertClick(Sender: TObject);
var FieldTag : Integer;
fieldtype, FieldValues : String;
FieldOptions : TStringList;
FieldActions : TStringList;
begin
FieldOptions := TStringList.Create;
FieldActions := TStringList.Create;
try
if TypeSel.ActivePageIndex=0 then // TextEdit
begin
fieldtype := 'Edit';
FieldValues := '';
if cbFontName.Text<>'' then
FieldOptions.Add('font=' + cbFontName.Text);
if cbFontSize.Text<>'' then
FieldOptions.Add('font-size=' + cbFontSize.Text);
case selFormat.ActivePageIndex of
// Standard TextEdit or Memo
0 : if chMultiline.Checked then fieldtype := 'Memo';
// Edit with Date Format
1 : if cbDateMask.Text<>'' then
begin
FieldActions.Add('Action-F=AFDate_FormatEx("'
+ cbDateMask.Text + '")' );
FieldActions.Add('Action-K=AFDate_KeystrokeEx("'
+ cbDateMask.Text + '")' );
end;
// Edit with Special Format
2 : if cbMask.Text<>'' then
begin
// AFSpecial_FormatEx requires string parameter
FieldActions.Add('Action-F=AFSpecial_FormatEx("'
+ cbMask.Text + '")' );
FieldActions.Add('Action-K=AFSpecial_KeystrokeEx("'
+ cbMask.Text + '")' );
end;
end;
if chMultiline.Checked then
fieldtype := 'Memo'
else fieldtype := 'Edit';
end
else
if TypeSel.ActivePageIndex=1 then // Choice
begin
if rbComboBox.Checked then
fieldtype := 'Combobox'
else fieldtype := 'Listbox';
if chMultiselect.Checked then fieldtype := fieldtype + ',multi';
if chEditable.Checked then fieldtype := fieldtype + ',edit';
FieldValues := edChoiceItems.Lines.CommaText;
end
else
if TypeSel.ActivePageIndex=2 then // Checkbox
begin
fieldtype := 'checkbox';
if rgBtnGlyph.ItemIndex>0 then
fieldtype := fieldtype + ','
+ IntToStr(rgBtnGlyph.ItemIndex);
if edBtnValueTrue.Text='' then
FieldValues := 'Yes,Off'
else FieldValues := edBtnValueTrue.Text +',Off';
end
else exit;
// Set the annotation widget color
// Here we pass a color string to be set in the Annotation in the
// MK dictionary as BC element.
if chLineColor.Checked then
begin
(*
FieldOptions.Add('prp.d.MK.c.BC='
+ ColorToString(BCColor.Brush.Color) );
FieldOptions.Add('prp.c.B='
+ ColorToString(BCColor.Brush.Color) );
*)
FieldOptions.Add('Color=' + ColorToString(BCColor.Brush.Color) );
end;
if chBackgroundColor.Checked then
begin
// FieldOptions.Add('prp.d.MK.c.BG='
// + ColorToString(BGColor.Brush.Color) );
FieldOptions.Add('Background-Color='
+ ColorToString(BGColor.Brush.Color) );
end;
// We add or update the field
FieldTag :=
WPViewPDF1.AddAcrofield(
chFieldName.Text, // the fieldname including the path
'', // Path is empty
edMappingName.Text,
edFieldValue.Text,
fieldtype,
4, // F=4 means visible and pritable
FieldValues,
FieldActions.CommaText, // Actions - only used with wpAddFieldAndDrawWidget!
FieldOptions.CommaText, // Options - only used with wpAddFieldAndDrawWidget!
wpAddFieldAndDrawWidget
);
finally
FieldOptions.Free;
FieldActions.Free;
end;
end;