Print Page | Close Window

FindFormFieldByTitle

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: General Discussion
Forum Description: Discussion board for Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=879
Printed Date: 23 Nov 24 at 4:40AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: FindFormFieldByTitle
Posted By: jwhitham
Subject: FindFormFieldByTitle
Date Posted: 15 Mar 08 at 7:20PM
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 Ouch).
 
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'.



Replies:
Posted By: jwhitham
Date Posted: 15 Mar 08 at 7:48PM
Argh no, I'm an idiot! Please ignore the above. Once flattened the field is of course no longer a field. Should have gone from count down to 1.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk