Hi all,
I've just come across some odd behaviour when calling FindFormFieldByTitle() using Delphi7/qpdf 5.11. I'm at home at the mo where I still have the dcu version, so I wont be able to look at the source till I'm at work tomorrow (Sunday ).
From what I can make out this function does not return 'The index of the form field with the specified title' as stated in the documentation, but 1 for success and 0 for failure. It does however seem to select the field in question, either that or calling it changes the index of the field searched for to 1.
Follows Delphi code to test this:
procedure TForm1.Button1Click(Sender: TObject); var qp: tisedquickpdf; f1, i: integer; begin qp := tisedquickpdf.Create; try screen.Cursor := crhourglass; qp.UnlockKey(iPDF_ID); qp.SetPageSize('A4'); qp.SetMeasurementUnits(1); qp.SetOrigin(1); f1 := qp.AddStandardFont(5); qp.SelectFont(f1); for i := 1 to 6 do begin qp.NewFormField('Field ' + inttostr(i),1); qp.SetFormFieldDescription(i,'Field ' + inttostr(i)); qp.SetFormFieldTextSize(i,16); qp.SetFormFieldValue(i,'This is form field #' + inttostr(i)); qp.SetFormFieldBounds(i,22,20*i,180,12); qp.SetFormFieldVisible(i,1); end; savedialog1.Filter := 'PDF|*.pdf'; savedialog1.DefaultExt := 'pdf'; savedialog1.FileName := ''; if savedialog1.Execute then begin qp.SaveToFile(savedialog1.FileName); end; finally qp.Free; screen.Cursor := crdefault; end; end;
procedure TForm1.Button2Click(Sender: TObject); var qp: tisedquickpdf; i,fieldindex: integer; s: string; begin qp := tisedquickpdf.Create; try screen.Cursor := crhourglass; qp.UnlockKey(iPDF_ID); opendialog1.Filter := 'PDF|*.pdf'; opendialog1.FileName := ''; if opendialog1.Execute then begin qp.LoadFromFile(opendialog1.FileName); for i := 1 to qp.FormFieldCount do begin s := 'Field ' + inttostr(i); fieldindex := qp.FindFormFieldByTitle(s); qp.SetFormFieldValue(fieldindex,'No longer a form field! ' + inttostr(i) + ' ' + inttostr(fieldindex) + ' ' + s); qp.FlattenFormField(fieldindex); end; qp.SaveToFile(opendialog1.FileName); end; finally qp.Free; screen.Cursor := crdefault; end; end;
|
Create a PDF with button1 and view it, then flatten the fields with button2 and take a look at the values for 'fieldindex'.
|