Print Page | Close Window

Set Form Field Value problems

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1349
Printed Date: 26 Jun 24 at 6:58AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Set Form Field Value problems
Posted By: Francesco_Halley
Subject: Set Form Field Value problems
Date Posted: 23 Feb 10 at 10:50AM
Hi,
i have a pre-built pdf file which contains text fields.
Now i want to fill these fields with my information.
I use DAOpenFile to open the pdf file.
I use DAGetFormFieldCount to get the number of the fields.
I use DAGetFormFieldTitle to get the name of the filed.
But, when i use SetFormFieldValue method to replace the old value, it doesn't work.
I think i can't use direct access functions together with standard functions.
But i didn't find a whole of functions (DA or standard) that allows me to reach my goal.
So, do you know a method which can help me?
 
Thank you very much
 
Francesco Passarini



Replies:
Posted By: Ingo
Date Posted: 23 Feb 10 at 1:43PM
Hi Francesco!

Again: It doesn't matter what you wanna do or not... DON'T MIX DA- and non-DA-functions.
At the "general section" i've posted a message for "the first steps"... It's all there what you need.
ffc := QP.FormFieldCount;
// . . .      
for i := 1 to ffc do
    begin
// . . .
//     get a value ...
       nffv := QP.GetFormFieldValue(i);
// . . .
//     set a value ...
       QP.SetFormFieldValue( i, FieldValue );

Cheers and welcome here,
Ingo



Posted By: Francesco_Halley
Date Posted: 23 Feb 10 at 2:08PM

Hi Ingo,

I wanna explain better my mistake. I need to merge some data (saved on a text file) with a pdf which contains text fields. If i use DA functions i can't use the SetFormFieldFunction, while if i use the standard instructions i can't use the the GetFromFieldCount. I need to know the number of fields because i want to flatten them at the end of the operations, and FlattenFormField method need the index of the field. 

So i found this solution: i used the DAOpenFunction to open the pdf file. Once obtained the Field Count, i closed the direct link and i loaded the file using standard options.
Then i filled the fields using a loop, flattening each one at the end.

This is my sample code:
 
int file_handle = QP.DAOpenFile("file.pdf","");  
int num_fields = QP.DAGetFormFieldCount(file_handle);   
QP.DACloseFile(file_handle);
// ...
int new_file = QP.LoadFromFile("file.pdf");
// ...
for(i=0; i<num_fields; i++)
{
 field_name = QP.GetFormFieldTitle(i);
 if(field_name.compare("...")==0)
 {
  int app = QP.SetFormFieldValue(i,"new value");       
  QP.FlattenFormField(i);         
  break;           
 }
}
 
thank you again Ingo
 
Francesco


Posted By: Shotgun Tom
Date Posted: 23 Feb 10 at 4:53PM
You can use the standard FormFieldCount to get your field count.
 
 (function TQuickPDF0717.FormFieldCount: Integer;)
 
Tom


Posted By: Ingo
Date Posted: 23 Feb 10 at 7:22PM
Hi!

I agree with Tom:
I can't understand why you're using the DA-functions?
The same functions without "DA" are available in the lib.

Cheers, Ingo


Posted By: Jack
Date Posted: 23 Feb 10 at 10:28PM
I have been doing something similar for a while.  My data comes from SQL queries.  I don't use any DA functions.  It works kind of cool.  I don't know C++ very well, but from what I see of your code, it looks like it should work.


Posted By: Francesco_Halley
Date Posted: 25 Feb 10 at 11:04AM

Hi guys,

i tried this code:
int new_file = QP.LoadFromFile("C:\\dir\\form_file.pdf");
int num_fields = QP.FormFieldCount();
 
but QP.FormFieldCount(); give me back value 0.
What did i forget?
Any post will be helpful for me.
Thank you very much
 
Francesco
 

 



Posted By: Ingo
Date Posted: 25 Feb 10 at 11:50AM
Hi!

You did the create first and then the unlock-function?
What's possible:
It's not a real form.
What's the returning value from "new_file"? "1"? If it's "0" then there's already the error.

Cheers, Ingo



Posted By: Francesco_Halley
Date Posted: 25 Feb 10 at 11:56AM

Sorry, i saw it was a my problem. But now the FormFieldCount() function gives me back twice value of the fields (96 instead of 48), and not all fields turn flattened. I'll put a new post when i'll able to solve the problem.

Francesco


Posted By: Ingo
Date Posted: 25 Feb 10 at 1:05PM
So the form-creation already went wrong 48 unvisible fields... 48 visible fields... something like that?

Cheers, Ingo


Posted By: Francesco_Halley
Date Posted: 25 Feb 10 at 1:57PM
Hi Ingo,
i dont know if there are hidden fields. When i opened the file using DA access
DAGetFormFieldCount returned me back 48, now, using FormFieldCount, 96.
But i found a solution to my problem without using the field count:
 
int new_file = QP.LoadFromFile("form_file.pdf"); 
ifstream values_file;
values_file.open("new_data_file.txt", ios::in);       
 string line, field_name;
while(getline(values_file,line))            {
 string fn = getFieldName_byFile(line);  //read the name of the field to edit       
 string fv = getFieldValue_byFile(line);  //read the new field value from file       
   
 QP.SetFormFieldValueByTitle(fn,fv);
 int id_field = QP.FindFormFieldByTitle(fn);
 if(id_field != 0)
  QP.FlattenFormField(id_field);
}
 
Thank you
 


Posted By: Ingo
Date Posted: 25 Feb 10 at 3:28PM
There's no need for a workaround.
Both functions will give you the same result. Sure.
Probably there's something mixed anywhere set.../get...




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