|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
Changing xml-part of PDF and inject it to the final PDF fileHi,
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 iText-questions@... 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 |
||||||||
|
|
Re: Changing xml-part of PDF and inject it to the final PDF fileRicardo Matos <ricardo.matos <at> link.pt> writes:
> - 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. Ok. Forget it! I've found the answer! Just had to use, in the end: xfaForm.SetXfa(stamper.Writer); I had tried the setXfa function...but apparently the wrong way! ;) ------------------------------------------------------------------------- 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 iText-questions@... 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 |
||||||||
|
|
setVertical issue.Hi all, I am trying to use the "setVerticalAlignment" within a cell, (As noted by the code below) but it is not aligning vertically centered at all, it is right up at the top of the cell. Did I miss something?? (Before you tell me to look in the book, my book is still in the mail and has not arrived yet so I can't.) I am on a tight deadline and would appreciate the help. outLine = "Estimate / Tenders Submitted"; outPara = new Paragraph(outLine, FontFactory.getFont(FontFactory.TIMES_ITALIC, 36)); cell = new PdfPCell(new Paragraph(outPara)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); outTable02.addCell(cell); Thank You. Glen Hamel Lead Programmer / Technician Auric Networks Canada, Inc. 570 Orwell Street, Unit 1 Mississauga, Ontario L5A 3V7 Phone 905.361.7621 Fax 905.274.3912 http://www.auricnet.ca |
||||||||
|
|
Re: setVertical issue.glen.hamel@... wrote:
> Did I miss something?? Possible horizontal alignment values: Element.ALIGN_LEFT, Element.ALIGN_CENTER, Element.ALIGN_RIGHT and Element.ALIGN_JUSTIFIED > cell.setHorizontalAlignment(Element.ALIGN_RIGHT); Possible vertical alignment values: Element.ALIGN_TOP, Element.ALIGN_MIDDLE and Element.ALIGN_BOTTOM In other words: > cell.setVerticalAlignment(Element.ALIGN_CENTER); should be: cell.setVerticalAlignment(Element.ALIGN_MIDDLE); br, Bruno ------------------------------------------------------------------------- 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 iText-questions@... 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 |
||||||||
|
|
Re: setVertical issue.Ah crap.. That's what I missed. Thanks a lot! Glen Hamel Lead Programmer / Technician Auric Networks Canada, Inc. 570 Orwell Street, Unit 1 Mississauga, Ontario L5A 3V7 Phone 905.361.7621 Fax 905.274.3912
glen.hamel@... wrote: > Did I miss something?? Possible horizontal alignment values: Element.ALIGN_LEFT, Element.ALIGN_CENTER, Element.ALIGN_RIGHT and Element.ALIGN_JUSTIFIED > cell.setHorizontalAlignment(Element.ALIGN_RIGHT); Possible vertical alignment values: Element.ALIGN_TOP, Element.ALIGN_MIDDLE and Element.ALIGN_BOTTOM In other words: > cell.setVerticalAlignment(Element.ALIGN_CENTER); should be: cell.setVerticalAlignment(Element.ALIGN_MIDDLE); br, Bruno ------------------------------------------------------------------------- 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 iText-questions@... 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 ------------------------------------------------------------------------- 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 iText-questions@... 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 |
||||||||
|
|
Re: Changing xml-part of PDF and inject it to the final PDF fileHi...
you could try this: http://www.mail-archive.com/itext-questions@.../msg35296.html I'm working in a similar project... Araujo On Fri, May 9, 2008 at 11:06 AM, Ricardo Matos <ricardo.matos@...> wrote:
------------------------------------------------------------------------- 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 iText-questions@... 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 |
||||||||
|
|
Re: Changing xml-part of PDF and inject it to the final PDF fileRicardo Matos <ricardo.matos <at> link.pt> writes:
> > Ricardo Matos <ricardo.matos <at> link.pt> writes: > > > - 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. > > Ok. Forget it! I've found the answer! > > Just had to use, in the end: > xfaForm.SetXfa(stamper.Writer); > > I had tried the setXfa function...but apparently the wrong way! ;) After getting the "hiding" part to work, I need to remove the exceeding pages. If I only need 3 of 10 repetitive table blocks, for instance, I end up getting blank pages. Thus, in the "hiding" part of my function, I grab the original pdf template and produce a temporary pdf file with a bunch of hidden tables. This works perfectly. Then, I grab that temporary file and I try using a PDFCopy object to simply copy the useful pages to a final output pdf. Example: I know that I want 3 repetitive elements and I have two of them per page, so I need to copy only the first two pages. The problem is that the resulting output pdf shows the previously hidden tables! :| Should I use another object other than PdfCopy? Is something missing between the two function parts? ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ iText-questions mailing list iText-questions@... 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 |
||||||||
|
|
Re: Changing xml-part of PDF and inject it to the final PDF fileOn May 13, 2008, at 6:23 AM, Ricardo Matos wrote:
> Thus, in the "hiding" part of my function, I grab the original pdf > template > and produce a temporary pdf file with a bunch of hidden tables. > This works > perfectly. > Great... > Then, I grab that temporary file and I try using a PDFCopy object > to simply > copy the useful pages to a final output pdf. PDFCopy is for copying REAL PDF pages - you are working with an XML- based form. You can't intermix the two! What you want to do is just throw away all the PDF stuff and leave yourself with a "shell PDF" and just the XML. This will work perfectly in Acrobat/Reader 8... Leonard ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ iText-questions mailing list iText-questions@... 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 |
||||||||
|
|
Re: Changing xml-part of PDF and inject it to the final PDF fileLeonard Rosenthol <leonardr <at> pdfsages.com> writes:
> On May 13, 2008, at 6:23 AM, Ricardo Matos wrote: > > Then, I grab that temporary file and I try using a PDFCopy object > > to simply > > copy the useful pages to a final output pdf. > > PDFCopy is for copying REAL PDF pages - you are working with an XML- > based form. You can't intermix the two! > > What you want to do is just throw away all the PDF stuff and leave > yourself with a "shell PDF" and just the XML. This will work > perfectly in Acrobat/Reader 8... > > Leonard Thanks for letting me know that I'm scrambling incompatible things. But when you say "What you want to do", you mean "what you are trying to do" or "what you should do"? If the first: what is the alternative? Is there a way to do it? If the second: how do I throw away the PDF stuff? ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ iText-questions mailing list iText-questions@... 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 |
||||||||
|
|
Re: Changing xml-part of PDF and inject it to the final PDF fileI wrote what I meant - what you WANT to do in order to accomplish
your task... How do you do it? Start by reading the PDF Reference to understand the minimal amount of PDF "stuff" necessary to get Acrobat/Reader to process it and how XFA information is contained inside a PDF. Then use Adobe Designer 8.x to produce a sample "shell PDF" and learn from it. Then you should be finally able to produce the necessary code... (and yes, I know this isn't trivial or simple and will take some work on your part) Leonard On May 14, 2008, at 5:57 AM, Ricardo Matos wrote: > Leonard Rosenthol <leonardr <at> pdfsages.com> writes: > >> On May 13, 2008, at 6:23 AM, Ricardo Matos wrote: >>> Then, I grab that temporary file and I try using a PDFCopy object >>> to simply >>> copy the useful pages to a final output pdf. >> >> PDFCopy is for copying REAL PDF pages - you are working with an XML- >> based form. You can't intermix the two! >> >> What you want to do is just throw away all the PDF stuff and leave >> yourself with a "shell PDF" and just the XML. This will work >> perfectly in Acrobat/Reader 8... >> >> Leonard > > Thanks for letting me know that I'm scrambling incompatible things. > > But when you say "What you want to do", you mean "what you are > trying to do" or > "what you should do"? > > If the first: what is the alternative? Is there a way to do it? > > If the second: how do I throw away the PDF stuff? > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ iText-questions mailing list iText-questions@... 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 |
| Free Forum Powered by Nabble | Forum Help |