Print Page | Close Window

Form Filling Duplication Problem

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=1469
Printed Date: 17 Jan 26 at 12:39AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Form Filling Duplication Problem
Posted By: DAVe3283
Subject: Form Filling Duplication Problem
Date Posted: 04 Jun 10 at 3:23AM
I am having a major problem with the form filling abilities of QuickPDF.  I have several PDF files with form fields, that I want to fill differently.  However, when I fill a field once, every field with the same name will be filled with the same information, even in different files.

I created a simple demo to demonstrate this.  It is a Console Application compiled in Visual Studio 2010 Beta 2 and is using .NET Framework 4 Client Profile.
using System;
using QuickPDFAX0719;

namespace FormFieldError
{
    class Program
    {
        static void Main(string[] args)
        {
            QuickPDFAX0719.PDFLibrary qp = new PDFLibrary();        // Create a new QuickPDF Lib
            qp.UnlockKey("j53g73ru93q4dp4ja7ri53b4y");              // License key for the QuickPDF library (TRIAL - expires 06/23/2010)
            int mainDocument = qp.NewDocument();                    // Create a new document, store it's id
            int tempDocument;                                       // Holds the id of the loaded document

            // Get file paths
            string form1 = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "form1.pdf");
            string form2 = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "form2.pdf");
            string output = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "output.pdf");

            // Fill document 1
            qp.LoadFromFile(form1);                                 // Load the form
            tempDocument = qp.SelectedDocument();                   // Get the id of the loaded document
            qp.SetFormFieldValueByTitle("RecordFileNo", "123");     // Set the file #
            qp.SelectDocument(mainDocument);                        // Select the main document
            qp.MergeDocument(tempDocument);                         // Merge the temp document into the main document

            // Fill document 2
            qp.LoadFromFile(form2);                                 // Load the form
            tempDocument = qp.SelectedDocument();                   // Get the id of the loaded document
            qp.SetFormFieldValueByTitle("RecordFileNo", "abc");     // Set the file #
            qp.SelectDocument(mainDocument);                        // Select the main document
            qp.MergeDocument(tempDocument);                         // Merge the temp document into the main document

            // Save result
            qp.SelectDocument(mainDocument);                        // Select the main document
            qp.DeletePages(1, 1);                                   // Delete the first (blank) page
            qp.SaveToFile(output);                                  // Save to disk
        }
    }
}

Opening the output.pdf file, you would expect to find the text "123" on the first page and "abc" on the second page.  However, both pages have the text "123".

Am I doing something wrong, or is there a bug in the library?  I really need to get this to work for my application, and I already have too much time invested to switch to a different PDF writer.

Thanks!
~David



Replies:
Posted By: Ingo
Date Posted: 04 Jun 10 at 6:36AM
Hi!

You have different files with identical form field names.
After the merge both documents are one new with the same formfield names.
So the content is a bit mixed up.
For me it's clear. The only difference is that i had thought that in both fields is "abc" ;-)
I would change the fieldnames before merging. You can get all properties setting a new one with a name combined with an on going number over the other formfields....

Cheers and welcome here,
Ingo
 


Posted By: DAVe3283
Date Posted: 04 Jun 10 at 4:25PM
Thanks, I'll try that and see if I can get it to work.

I would have though they would be "abc" as well, but they weren't.  Strange.

Is there a way to rename a field, rather than re-creating every field?

~David


Posted By: Jack
Date Posted: 04 Jun 10 at 4:28PM
I ran into the same problem in my program.  It turned out that it was an issue with the way that Acrobat handles fields.  If you go into Acrobat and set up a form with two fields named "Test_1" and then put "123" into one of the fields, it will show up in both.  Rename one of the fields to "Test_2" and the problem goes away.

My solution was to load a form from a template and then add the page number to the front of each field and then fill the fields.  Some of my forms have master and detail fields too.  For them, when I am setting up the form, I add the detail number to the end of the form field.

My uses have been pretty routine form filling so I probably have not run across every possible test, but QuickPDF has not let me down yet.

I hope this is helpful.

Jack




Posted By: Jack
Date Posted: 04 Jun 10 at 4:37PM
Here is the code I used to add the page number to the form fields:

procedure TPDF.AddPageNoToFieldNames(var oPDF: TQuickPDF; iPageNo: Integer);
var i: Integer;
    sFieldName: String;
begin
  for i := 1 to oPDF.FormFieldCount do begin
    sFieldName := oPDF.GetFormFieldTitle(i);
    sFieldName := LPad(iPageNo, 3, '0') + '_' + sFieldName;
    oPDF.SetFormFieldChildTitle(i, sFieldName);
  end;
end;
It's in Delphi, but it's pretty clear what it's doing.
Jack


Posted By: DAVe3283
Date Posted: 04 Jun 10 at 5:51PM
Ingo:
I was able to re-create the fields and get the result I wanted.  However, the re-creation procedure takes a very long time (filling and merging 4 pages of fields takes a fraction of a second, recreating those ~50 fields takes 3-4 seconds).  Very strange.
Thanks for getting me going!

Jack:
That is pretty much what I am doing with my program.  Your method worked great, and much faster than re-creating every field.  It was exactly what I was looking for!  Thank you!



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