Is it a static XFA or a dynamic XFA that you are working with?
From: DEVSGL INFORMATIQUE [mailto:[email protected]]
Sent: Tuesday, November 09, 2010 8:38 AM
To: [email protected]
Subject: [iText-questions] Replacing image in XFA PDF with iTextSharp
Hello,
I have a problem while trying to replace an image in a PDF. I'm using C# and
iTextSharp, but if someone get a solution with Java and iText it would be good
enough I think ^^
I have almost succeed to do the replace, the only problem is I always see the
old image in Adobe Reader. But if I open the modified PDF with LiveCycle I see
the new image. Really strange, and in LiveCycle the XML is good, I see the new
image too (base64 encoded).
Some part have been removed to make the example simplier, but this is what I
have mostly done (C#, but should be clear enough).
public static void InitializePdf(string sourceFile, string destinationFile)
{
using (MemoryStream ms = new MemoryStream())
{
PdfReader reader = new PdfReader(sourceFile);
PdfStamper stamper = new PdfStamper(reader, ms);
XfaForm xfaForm = new XfaForm(reader);
XmlDocument xfaDocument = xfaForm.DomDocument;
byte[] image = File.ReadAllBytes("myImage.png");
XmlNamespaceManager mng = new
XmlNamespaceManager(xfaDocument.NameTable);
mng.AddNamespace("xdp", "http://ns.adobe.com/xdp/");
XmlNode node =
xfaDocument.SelectSingleNode("/xdp:xdp/child::*[local-name()=""template""]/descendant::*[local-name()=""draw""
and @name=""Logo""]/descendant::*[local-name()=""image""]", mng);
node.InnerText = Convert.ToBase64String(image);
xfaForm.Changed = true;
XfaForm.SetXfa(xfaForm, stamper.Reader, stamper.Writer);
stamper.Close();
reader.Close();
File.WriteAllBytes(destinationFile, ms.ToArray());
}
}
With this I can replace the image, but the result is only visible in LiveCycle,
not in Adobe Reader. What am I doing wrong ?
Thanks.
P.S. : sorry if the english is bad, it's not my language ^^
------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php