Hi !
First, here is the code snippet modifying the pdf document :
File f = File.createTempFile("TheModifiedFormFile", ".pdf");
PdfReader reader = new PdfReader("/path/to/OriginalFormFile.pdf");
PdfDictionary root = reader.getCatalog();
PdfDictionary acroform = root.getAsDict(PdfName.ACROFORM);
PdfArray xfa = acroform.getAsArray(PdfName.XFA);
for (int i = 0; i < xfa.size(); i += 2) {
if( "template".equals(xfa.getAsString(i).toString())) {
PRStream s = (PRStream)xfa.getAsStream(i + 1);
String templateString = new
String(PdfReader.getStreamBytes(s));
byte[] b =
templateString.replaceAll("TOKEN_FOR_REPLACEMENT", "the_real_url").getBytes();
s.setData(b);
PdfStamper stamper = new PdfStamper(reader,
new FileOutputStream(f));
stamper.close();
break;
}
}
// send file with mime-type "application/pdf";
Notice that I do not actually use XML tools to process the data, but perform
simple string substitution. I do have a copy of Live Cycle Designer and Adobe
Acrobat Professional. But the form has to be usable by simple end users who
only have Acrobat Reader. The original PDF document was created with Live Cycle
Designer. Then, using Acrobat, I open the file and "enable usage rights", so
that end users can save filled versions of the pdf form. Finally, I modify the
file using the code above. Once modified with that code, editing works
awkwardly, and saving and submitting do not work at all anymore.
Thanks,
Martin.
-----Message d'origine-----
De : Leonard Rosenthol [mailto:[email protected]]
Envoyé : Thursday, April 16, 2009 9:24 AM
À : Post all your questions about iText here
Objet : Re: [iText-questions] URL of submit button
Unless you have a copy of Adobe Acrobat Professional or LiveCycle Reader
Extensions Server, you can't.
How did you end up modifying the document? Sounds like you didn't use a
PdfStamper...
Leonard
-----Original Message-----
From: Martin Leboeuf [mailto:[email protected]]
Sent: Thursday, April 16, 2009 9:07 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] URL of submit button
Hi again !
Thanks for the help. I did manage to modify my form. The problem now is that
when I open the resulting file with Acrobat Reader, I get the following message:
"This document contained certain rights to enable special features in Adobe
Reader. The document has been changed since it was created and these rights are
no longer valid. Please contact the author for the original version of this
document."
and indeed editing of the file now only partially works and I can no longer
save a filled copy of the form.
How can I re-enable the lost "certain rights" ?
Thanks,
Martin.
-----Message d'origine-----
De : Leonard Rosenthol [mailto:[email protected]]
Envoyé : Wednesday, April 15, 2009 8:55 AM
À : Post all your questions about iText here
Objet : Re: [iText-questions] URL of submit button
> It was developped with LiveCycle Designer 8
LiveCycle-based forms are NOT AcroForms, they are XFA-Forms. As such, trying
to get the acroform from them, simply won't work....
To modify an XFA-based form, you need to load out the XFA (it's an XML stream)
and process it using standard XML tools and then put it back. There are
samples online.
Leonard
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php