Hi,
I'm having an hard time trying to do something that I don't even know if it's
possible. I have read a lot about iText and goggled like a maniac (I had dozens
of tabs opened in my Firefox, all about iText).
Here's my problem:
- I have a dynamic pdf form with a repetitive part. Let's say I have such
template with a list of 10 tables with 5 fields each and each page takes 2 of
those tables.
- However, sometimes I just need to fill (or just have enough data to fill) 3 or
7 or N-1 of those tables. So my challenge was to make the exceeding tables just
disappear. Let's assume that I have access to this information when I start
processing the template: the number of tables per page and the number of tables
I need.
- I managed to do the easiest part: let's say I only need 5 tables, so I cycle
through the reader's pages and copy them (as is) to a writer, until I get the
number of tables I need. In this case, I would copy page 1 (2 tables), page 2
(plus 2 tables) and page 3 (plus 2 tables), getting the total number of 6
tables.
- Knowing the name of the table, my wish was to (somehow) hide it. So I thought
I could use "Presence" property of the table and set it to "Invisible". That's
very easy to do in LiveCycle, but I need to do it in runtime, with iText.
- By looking at the XML Source, in LiveCycle, I noticed that each table
corresponded to a <subform> tag, to which I could add the attribute
presence="invisible". So, in my code (i'm using c#, sorry), I do the following:
FileStream fs = new FileStream(fileName, FileMode.Create);
stamper = new PdfStamper(reader, fs);
XfaForm xfaForm = new XfaForm(stamper.Reader);
XmlDocument xmldoc = new XmlDocument();
xmldoc = xfaForm.DomDocument;
XmlNodeList nodelst = xmldoc.GetElementsByTagName("subform");
XmlAttributeCollection attriblist;
ArrayList finalNodeList = new ArrayList();
foreach (XmlNode no in nodelst)
{
attriblist = no.Attributes;
if (attriblist != null)
{
foreach (XmlAttribute attrib in attriblist)
{
if (attrib.Name.Equals("name") &&
attrib.Value.Equals("TableX"))
{
finalNodeList.Add(no);
}
}
}
}
XmlNode attr;
foreach (XmlNode node in finalNodeList)
{
attr = xmldoc.CreateAttribute("presence");
attr.Value = "invisible";
node.Attributes.SetNamedItem(attr);
}
- With something like this, I can add the "hiding" attribute to the nodes I want
and have a xmldoc with the xml I need. My question now is: how do I "inject"
these changes to the Stamper? How can I set my stamper, so I can close it and
have the result I wish in my output pdf file?
I tried using MergeXfaData, SetXfa, ... but with no results. I just can't find a
way to do it.
Thank you, if you got this far down the message! ;)
Any clue you might give me would be helpful.
Ricardo Matos
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar