AcroForm and AcroField PLUS FAQ ENTRY
- From: "Henry Doan" <geiz777 (at) msn.com>
- Date: Fri, 01 Sep 2006 15:16:55 +0000
Thank you, Thank you, Thank you. The second suggestion was exactly what i
was looking for.
For those who are reading this also, you can use
"Not the correct syntax" -- AcroField.renameField(String oldName, String
newName)
to rename the field.
>From: "Mark Storer" <MStorer (at) cardiff.com>
>Reply-To: Post all your questions about iText here
><itext-questions (at) lists.sourceforge.net>
>To: "Post all your questions about iText here"
><itext-questions (at) lists.sourceforge.net>
>Subject: Re: [iText-questions] AcroForm and AcroField PLUS FAQ ENTRY
>Date: Thu, 31 Aug 2006 12:35:53 -0700
>
>I'm pretty sure this is in the FAQ somewhere. Thought I don't know the FAQ
>URL off the top of my head... lets see here... It's not there. I'm
>shocked.
>
>But there is a form for submitting FAQs:
>
><site:faq-entry name="Why do forms behave strangely when I merge them?">
><site:question>When I merge two forms together, different copies of the
>same name have the same value. What can I do to maintain seperate copies
>of the fields within the same form?</site:question>
><site:answer>
>All fields in a PDF file with the same name share a value. This becomes
>obvious when two copies of a form try to coexist within a single PDF, but
>can be a relatively subtle problem with common field names ("Name",
>"Address" and so forth).
>
>This problem can be further obscured by iText when it is asked to generate
>field appearances. The individual appearances will contain the
>corresponding value until one of them is edited. At that time, Reader will
>update all the fields to hold the new value. From Reader's point of view,
>they always shared a value and merely had inaccurate appearances.
>JavaScript asked to retrieve a given field's value will return that single
>value.
>
>There are two solutions if you absolutely must merge forms:
>
>1) Flatten the individual instances of the form, save them, then stitch
>them all together.
>
>Flattened forms aren't really forms anymore, they're regular PDFs that
>happen to look like one. They aren't editable, and there's no script,
>calculations, or formatting (which can be a problem). You don't need
>PdfCopyForm, PdfCopy alone will work. In fact, you can merge a single
>normal form together with any number of flattened forms.
>
>2) Rename all the fields.
>
>For all but the simplest forms, you should strive to avoid merging them
>unless you know EXACTLY what you are doing, and can plan for it.
>
>Develop some name-mangling scheme and consistently apply it to your fields
>as you import them. Something like appending "__#" where the # is an ID
>number. This avoids name collisions. You'll have to bone up on the
>PdfReference and manipulate PdfDictionary objects directly. Further, this
>must be done before attaching them to an instance of PdfCopyForm. Once a
>PdfWriter is attached to a PdfReader, you can't be sure that any changes
>you make will "stick".
>
>There are problems with renaming fields. Firstly, most field scripts are
>written with specific field names in mind. Furthermore, some signatures
>key off field names, but merging them will invalidate those signatures no
>matter what you do.
>
>Assuming for a moment that you have control over the initial PDF forms
>you'll be using, you can rewrite your scripts to recognise which instance
>of a particular field is the appropriate one. In field events, you can
>check the current field's name to see how to access other fields from the
>same form. Parse out the mangled name, and use it to determine the name of
>the appropriate field form the same form. Document level scripts and
>events are more challenging though it should be possible to set a global on
>each page's "Page Open" event and access the appropriate fields that way.
>
>If you do not have control over the forms and cannot rewrite their script,
>there's not much you can do programmatically. The moment someone builds a
>field name from parts (getField("quantity_" + rowNum)), it's effectively
>impossible to fix in a general way. Specific cases may be more tractable.
></site:answer>
></site:faq-entry>
>
>--Mark Storer
> Senior Software Engineer
> Cardiff Software
>
>#include <disclaimer>
>typedef std::Disclaimer<Cardiff> DisCard;
>
>
>
> > -----Original Message-----
> > From: itext-questions-bounces (at) lists.sourceforge.net
> > [mailto:itext-questions-bounces (at) lists.sourceforge.net]On
> > Behalf Of Henry
> > Doan
> > Sent: Thursday, August 31, 2006 9:47 AM
> > To: itext-questions (at) lists.sourceforge.net
> > Subject: [iText-questions] AcroForm and AcroField
> >
> >
> > Hi i am coping the same pdf file into one big one and each
> > time i copy them
> > in I fill out the form field uniquely, and it shows up too.
> > But when i try
> > to change the form field inside a browser on one pdf page it
> > changes on all
> > of the other pdf page too.
> >
> >
> > Heres my code:
> >
> > // FOR COPYING FORMS
> > PdfCopyFields copy = new PdfCopyFields(baos);
> > // GET THE FILE
> > PdfReader reader2 = null, reader = new PdfReader("e:/myFile.pdf");
> >
> > int tmp =0;
> > while (tmp <= 5){
> > // WRITE TO PDF
> > reader2 = new PdfReader("e:/Webs/walton/ICF.pdf");
> > stamp1 = new PdfStamper(reader2, baos2);
> > acroField = stamp1.getAcroFields();
> > acroField.setField("Name", strName);
> >
> > stamp1.close();
> > reader.close();
> >
> > //write to baos then read from it and copy it to [copy]
> > reader2 = new PdfReader(baos2.toByteArray());
> > copy.addDocument(reader2);
> > tmp++;
> > }
> >
> > Thank you,
> >
> > _________________________________________________________________
> > Windows Live Spaces is here! It's easy to create your own
> > personal Web site.
> > http://spaces.live.com/signup.aspx
> >
> >
> >
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job
>easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>iText-questions mailing list
>iText-questions (at) lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/itext-questions
_________________________________________________________________
Check the weather nationwide with MSN Search: Try it now!
http://search.msn.com/results.aspx?q=weather&FORM=WLMTAG
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions (at) lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions