  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Replacing PDF stream content | Replacing PDF stream content 2007-11-07 - By Ismael F
Back
Thanks a lot! I tried It but I think there is something I can't see! Originally I have the PDF content: ......73 0 obj<</XFA[(preamble)5 0 R(config)6 0 R(template)7 0 R(datasets)8 0 R (localeSet)9 0 R(PDFSecurity)10 0 R(xmpmeta)11 0 R(xfdf)12 0 R(postamble)13 0 R] /Fields[2 0 R]/DA(/Helv 0 Tf 0 g )/DR<</Font<</Helv 1 0 R/MyriadPro-Regular 87 0 R>>>>>>endobj...7 0 obj<</Length 22490/Filter[/FlateDecode]/Type/EmbeddedFile> >stream...endstreamendobj... There isn't in the PDF any other place that links "7 0" template object than in "73 0". Then I have the code A): // xfa_element_ind --> "7 0" PdfReader .killIndirect(xfa_element_ind); PdfStream xfa_stream = new PdfStream(form _field_property_value); PdfIndirectReference ref = writer.addToBody(xfa_stream , false).getIndirectReference(); writer.getExtraCatalog().put(PdfName.XFA, ref ); As a result I get that addresses have been recalculated, an I have the information duplicated (the new one at "1 0" the original one at "11 0"):...1 0 obj <</Length 42104>>stream ....... endstream...75 0 obj<</XFA[(preamble) 9 0 R (config) 10 0 R(template) 11 0 R(datasets) 12 0 R(localeSet) 13 0 R(PDFSecurity) 14 0 R(xmpmeta) 15 0 R(xfdf) 16 0 R(postamble) 17 0 R]/Fields[4 0 R]/DR<</Font< </MyriadPro-Regular 77 0 R/Helv 3 0 R>>>>/DA(/Helv 0 Tf 0 g )>>endobj...11 0 obj <</Filter[/FlateDecode]/Type/EmbeddedFile/Length 22490>>stream.. .endstreamendobj... With next code B): // xfa_element_ind --> "7 0" PdfReader.killIndirect (xfa_element_ind); PdfStream xfa_stream = new PdfStream(form_field_property _value); PdfIndirectReference ref = writer.addToBody(xfa_stream, xfa_element _ind, false).getIndirectReference(); writer.getExtraCatalog().put(PdfName.XFA , ref); I get the resultant PDF content:...7 0 obj <</Length 42104>>stream ....... endstream...74 0 obj<</XFA[(preamble) 8 0 R(config) 9 0 R(template) 10 0 R (datasets) 11 0 R(localeSet) 12 0 R(PDFSecurity) 13 0 R(xmpmeta) 14 0 R(xfdf) 15 0 R(postamble) 16 0 R]/Fields[3 0 R]/DR<</Font<</MyriadPro-Regular 76 0 R/Helv 2 0 R>>>>/DA(/Helv 0 Tf 0 g )>>endobj...10 0 obj <</Filter[/FlateDecode]/Type /EmbeddedFile/Length 22490>>stream...endstreamendobj... This code is the same as A: // xfa_element_ind --> "7 0" PdfIndirectReference ref = writer.addToBody(xfa_stream, false) .getIndirectReference(); PdfReader.killIndirect(xfa_element_ind); writer .getExtraCatalog().put(PdfName.XFA, ref); An this one is like B: // xfa_element_ind --> "7 0" PdfIndirectReference ref = writer .addToBody(xfa_stream, xfa_element_ind, false).getIndirectReference(); PdfReader.killIndirect(xfa_element_ind); writer.getExtraCatalog().put (PdfName.XFA, ref); It's possible to make a direct replacement of stream bytes without changing references? Perhaps there is another object that references to "7 0" and 'killIndirect' takes it into account and makes the recalculation to update it and possible 'xrefs'? I'm sorry, It's possible that I still haven't understood PDF concepts! Thanks a lot! Isma > Date: Tue, 6 Nov 2007 10:29:59 +0000> From: psoares@(protected)> To: itext -questions@(protected)> Subject: Re: [iText-questions] Replacing PDF stream content> > You'll have to delete the old object with PdfReader .killIndirect(PRIndirectReference).> > Paulo > > > -- --Original Message-- --> > From: itext-questions-bounces@(protected) > > [mailto:itext-questions -bounces@(protected)] On > > Behalf Of Ismael F> > Sent: Tuesday, November 06, 2007 9:58 AM> > To: itext-questions@(protected)> > Subject: [iText-questions] Replacing PDF stream content> > > > Hello everybody, > > > > I need to change, replace a whole stream of bytes 'object' > > from a PDF. In this case those bytes corresponds to a XFA form.> > > > The original PDF content is like:> > %PDF-1 (See http://PDF-1.ora-code.com).6> > %????> > 1 0 obj <</Type/Metadata/...> > .. .> > ...> > 10 0 obj <</Filter[/FlateDecode]/Type/EmbeddedFile/Length > > 22459> >stream ... endstream> > 11 0 obj .......> > ...> > > > So I use this piece of code:> > PdfIndirectReference ref = writer.addToBody(new > > PdfStream(form _field_property_value), xfa_element_ind, > > false).getIndirectReference();> > writer.getExtraCatalog().put(PdfName.XFA, ref);> > > > where "xfa_element_ind" is "10 0", and corresponds to the > > bytes adress that I want to replace.> > > > As a result I get this PDF content:> > %PDF-1 (See http://PDF-1.ora-code.com).6> > %????> > 10 0 obj << /Length 42101>>stream ... endstream> > 1 0 obj <</Type/Metadata/...> > ...> > .. .> > ...> > 10 0 obj <</Filter[/FlateDecode]/Type/EmbeddedFile/Length > > 22459> >stream ... endstream> > 11 0 obj .......> > ...> > > > As one can see the content has not changed/replaced, is > > duplicated and I don't achieve the desired result.> > > > How can I make a direct substitution/replacement to the > > stream without duplicating content?> > Is It possible?> > How?> > > > I tried diferent things but I'm not able to get it!> > > > Thanks a lot!> > > Aviso Legal:> Esta mensagem ? destinada exclusivamente ao destinat?rio. Pode conter informa??o confidencial ou legalmente protegida. A incorrecta transmiss ?o desta mensagem n?o significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. ? proibido a qualquer pessoa que n?o o destinat?rio de usar, revelar ou distribuir qualquer parte desta mensagem. > > Disclaimer:> This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.> > -- ---- ------ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------> This SF.net email is sponsored by: Splunk Inc.> Still grepping through log files to find problems ? Stop.> Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/> __ ____ _____ __ ____ ____ ____ ____ ____ ______> iText-questions mailing list> iText -questions@(protected)> https://lists.sourceforge.net/lists/listinfo /itext-questions> Buy the iText book: http://itext.ugent.be/itext-in-action/ __ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ <html> <head> <style> .hmmessage P { margin:0px; padding:0px } body.hmmessage { FONT-SIZE: 10pt; FONT-FAMILY:Tahoma } </style> </head> <body class='hmmessage'> Thanks a lot! <BR> I tried It but I think there is something I can't see!<BR><BR> Originally I have the PDF content:<BR> ...<BR>...<BR>73 0 obj<BR><</XFA[(preamble)5 0 R(config)6 0 R(template)7 0 R(datasets)8 0 R(localeSet)9 0 R(PDFSecurity)10 0 R(xmpmeta)11 0 R(xfdf)12 0 R(postamble)13 0 R]/Fields[2 0 R]/DA(/Helv 0 Tf 0 g )/DR<</Font<< /Helv 1 0 R/MyriadPro-Regular 87 0 R>>>>>><BR>endobj<BR>...<BR >7 0 obj<BR><</Length 22490/Filter[/FlateDecode]/Type/EmbeddedFile>> ;stream<BR>...<BR>endstream<BR>endobj<BR>...<BR> <BR>There isn't in the PDF any other place that links "7 0" template object than in "73 0". Then I have the code A):<BR> // xfa_element_ind -- > "7 0"<BR> PdfReader.killIndirect(xfa_element_ind);<BR> PdfStream xfa_stream = new PdfStream(form_field_property_value);<BR> PdfIndirectReference ref = writer.addToBody(xfa_stream, false) .getIndirectReference();<BR> writer.getExtraCatalog().put(PdfName .XFA, ref);<BR> <BR> As a result I get that addresses have been recalculated, an I have the information duplicated (the new one at "1 0" the original one at "11 0"):<BR>.. .<BR>1 0 obj <</Length 42104>>stream ....... endstream<BR>...<BR>75 0 obj<</XFA[(preamble) 9 0 R(config) 10 0 R(template) 11 0 R(datasets) 12 0 R(localeSet) 13 0 R(PDFSecurity) 14 0 R(xmpmeta) 15 0 R(xfdf) 16 0 R (postamble) 17 0 R]/Fields[4 0 R]/DR<</Font<</MyriadPro-Regular 77 0 R/Helv 3 0 R>>>>/DA(/Helv 0 Tf 0 g )>>endobj<BR>...<BR>11 0 obj <</Filter[/FlateDecode]/Type/EmbeddedFile/Length 22490>>stream <BR>...<BR>endstream<BR>endobj<BR>...<BR> <BR>With next code B):<BR> // xfa_element_ind --> "7 0"<BR > PdfReader.killIndirect(xfa_element_ind);<BR> PdfStream xfa_stream = new PdfStream(form_field_property_value);<BR> PdfIndirectReference ref = writer.addToBody(xfa_stream, xfa _element_ind, false).getIndirectReference();<BR> writer .getExtraCatalog().put(PdfName.XFA, ref);<BR> I get the resultant PDF content:<BR>...<BR>7 0 obj <</Length 42104>> ;stream ....... endstream<BR>...<BR>74 0 obj<</XFA[(preamble) 8 0 R(config ) 9 0 R(template) 10 0 R(datasets) 11 0 R(localeSet) 12 0 R(PDFSecurity) 13 0 R (xmpmeta) 14 0 R(xfdf) 15 0 R(postamble) 16 0 R]/Fields[3 0 R]/DR<</Font <</MyriadPro-Regular 76 0 R/Helv 2 0 R>>>>/DA(/Helv 0 Tf 0 g ) >><BR>endobj<BR>...<BR>10 0 obj <</Filter[/FlateDecode]/Type /EmbeddedFile/Length 22490>>stream<BR>...<BR>endstream<BR>endobj<BR>...<BR > <BR>This code is the same as A:<BR> // xfa_element_ind --> "7 0"<BR> PdfIndirectReference ref = writer.addToBody(xfa _stream, false).getIndirectReference();<BR> PdfReader .killIndirect(xfa_element_ind);<BR> writer.getExtraCatalog() .put(PdfName.XFA, ref);<BR> <BR>An this one is like B:<BR> // xfa_element_ind --> "7 0 "<BR> PdfIndirectReference ref = writer.addToBody(xfa_stream, xfa_element_ind, false).getIndirectReference();<BR> PdfReader .killIndirect(xfa_element_ind);<BR> writer.getExtraCatalog() .put(PdfName.XFA, ref);<BR> <BR> It's possible to make a direct replacement of stream bytes without changing references?<BR><BR> Perhaps there is another object that references to "7 0" and 'killIndirect' takes it into account and makes the recalculation to update it and possible 'xrefs'?<BR> <BR> I'm sorry, It's possible that I still haven't understood PDF concepts!<BR> <BR> Thanks a lot!<BR> <BR>Isma<BR> <BR> <BR>> Date: Tue, 6 Nov 2007 10:29:59 +0000<BR>> From: psoares@(protected) <BR>> To: itext-questions@(protected)<BR>> Subject: Re: [iText -questions] Replacing PDF stream content<BR>> <BR>> You'll have to delete the old object with PdfReader.killIndirect(PRIndirectReference).<BR>> <BR> > Paulo <BR>> <BR>> > -- --Original Message-- --<BR>> > From: itext-questions-bounces@(protected) <BR>> > [mailto:itext -questions-bounces@(protected)] On <BR>> > Behalf Of Ismael F<BR >> > Sent: Tuesday, November 06, 2007 9:58 AM<BR>> > To: itext -questions@(protected)<BR>> > Subject: [iText-questions] Replacing PDF stream content<BR>> > <BR>> > Hello everybody,<BR>> ; > <BR>> > I need to change, replace a whole stream of bytes 'object' <BR>> > from a PDF. In this case those bytes corresponds to a XFA form.<BR >> > <BR>> > The original PDF content is like:<BR>> > %PDF-1 (See http://PDF-1.ora-code.com).6 <BR>> > %????<BR>> > 1 0 obj <</Type/Metadata/...<BR>> > ...<BR>> > ...<BR>> > 10 0 obj <</Filter[/FlateDecode]/Type /EmbeddedFile/Length <BR>> > 22459>>stream ... endstream<BR>> > ; 11 0 obj .......<BR>> > ...<BR>> > <BR>> > So I use this piece of code:<BR>> > PdfIndirectReference ref = writer.addToBody(new <BR >> > PdfStream(form_field_property_value), xfa_element_ind, <BR>> > false).getIndirectReference();<BR>> > writer.getExtraCatalog().put (PdfName.XFA, ref);<BR>> > <BR>> > where "xfa_element_ind" is "10 0" , and corresponds to the <BR>> > bytes adress that I want to replace.<BR> > > <BR>> > As a result I get this PDF content:<BR>> > %PDF-1 (See http://PDF-1.ora-code.com) .6<BR>> > %????<BR>> > 10 0 obj <</Length 42101>>stream ... endstream<BR>> > 1 0 obj <</Type/Metadata/...<BR>> > ... <BR>> > ...<BR>> > ...<BR>> > 10 0 obj <</Filter[ /FlateDecode]/Type/EmbeddedFile/Length <BR>> > 22459>>stream ... endstream<BR>> > 11 0 obj .......<BR>> > ...<BR>> > <BR>> > As one can see the content has not changed/replaced, is <BR>> > duplicated and I don't achieve the desired result.<BR>> > <BR>> > How can I make a direct substitution/replacement to the <BR>> > stream without duplicating content?<BR>> > Is It possible?<BR>> > How?<BR> > > <BR>> > I tried diferent things but I'm not able to get it!<BR> > > <BR>> > Thanks a lot!<BR>> <BR>> <BR>> Aviso Legal:<BR> > Esta mensagem ? destinada exclusivamente ao destinat?rio. Pode conter informa??o confidencial ou legalmente protegida. A incorrecta transmiss?o desta mensagem n?o significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. ? proibido a qualquer pessoa que n?o o destinat?rio de usar, revelar ou distribuir qualquer parte desta mensagem. <BR>> <BR>> Disclaimer:<BR>> This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.<BR>> <BR>> -- ---- ---- ---- ---- ---- ---- ---- ---- ----- -- ---- ---- ---- ---- --<BR>> This SF.net email is sponsored by: Splunk Inc. <BR>> Still grepping through log files to find problems? Stop.<BR>> Now Search log events and configuration files using AJAX and a browser.<BR>> Download your FREE copy of Splunk now >> http://get.splunk.com/<BR>> _ __ ____ ____ ____ ____ ____ ____ ____ ____ ___<BR>> iText-questions mailing list<BR>> iText-questions@(protected)<BR>> https://lists .sourceforge.net/lists/listinfo/itext-questions<BR>> Buy the iText book: http ://itext.ugent.be/itext-in-action/<BR><BR><br /><hr />Express yourself instantly with MSN Messenger! <a href='http://clk.atdmt.com/AVE/go/onm00200471ave/direct /01/' target='_new'>MSN Messenger</a></body> </html> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ __ ____ ____ ____ ____ ____ ____ ____ ____ ____ iText-questions mailing list iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
|
|
 |