Java Mailing List Archive

http://www.junlu.com/

Google
Google
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
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Replacing PDF stream content

Replacing PDF stream content

2007-11-07       - By Ismael F

 Back
Reply:     1     2     3  


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>&lt;&lt;/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&lt;&lt;/Font&lt;&lt;
/Helv 1 0 R/MyriadPro-Regular 87 0 R&gt;&gt;&gt;&gt;&gt;&gt;<BR>endobj<BR>...<BR
>7 0 obj<BR>&lt;&lt;/Length 22490/Filter[/FlateDecode]/Type/EmbeddedFile&gt;&gt
;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>&nbsp;&nbsp; // xfa_element_ind --
&gt; "7 0"<BR>&nbsp;&nbsp; PdfReader.killIndirect(xfa_element_ind);<BR>&nbsp;
&nbsp; PdfStream xfa_stream = new&nbsp;PdfStream(form_field_property_value);<BR>
&nbsp;&nbsp; PdfIndirectReference ref = writer.addToBody(xfa_stream, false)
.getIndirectReference();<BR>&nbsp;&nbsp; writer.getExtraCatalog().put(PdfName
.XFA, ref);<BR>
&nbsp;<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 &lt;&lt;/Length 42104&gt;&gt;stream ....... endstream<BR>...<BR>75
0 obj&lt;&lt;/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&lt;&lt;/Font&lt;&lt;/MyriadPro-Regular 77 0
R/Helv 3 0 R&gt;&gt;&gt;&gt;/DA(/Helv 0 Tf 0 g )&gt;&gt;endobj<BR>...<BR>11 0
obj &lt;&lt;/Filter[/FlateDecode]/Type/EmbeddedFile/Length 22490&gt;&gt;stream
<BR>...<BR>endstream<BR>endobj<BR>...<BR>
<BR>With next code B):<BR>&nbsp;&nbsp;&nbsp; // xfa_element_ind --&gt; "7 0"<BR
>&nbsp;&nbsp;&nbsp; PdfReader.killIndirect(xfa_element_ind);<BR>&nbsp;&nbsp;
&nbsp; PdfStream xfa_stream = new&nbsp;PdfStream(form_field_property_value);<BR>
&nbsp;&nbsp;&nbsp; PdfIndirectReference ref = writer.addToBody(xfa_stream, xfa
_element_ind, false).getIndirectReference();<BR>&nbsp;&nbsp;&nbsp; writer
.getExtraCatalog().put(PdfName.XFA, ref);<BR>
I get the resultant PDF content:<BR>...<BR>7 0 obj &lt;&lt;/Length 42104&gt;&gt
;stream ....... endstream<BR>...<BR>74 0 obj&lt;&lt;/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&lt;&lt;/Font
&lt;&lt;/MyriadPro-Regular 76 0 R/Helv 2 0 R&gt;&gt;&gt;&gt;/DA(/Helv 0 Tf 0 g )
&gt;&gt;<BR>endobj<BR>...<BR>10 0 obj &lt;&lt;/Filter[/FlateDecode]/Type
/EmbeddedFile/Length 22490&gt;&gt;stream<BR>...<BR>endstream<BR>endobj<BR>...<BR
>
<BR>This code is the same as A:<BR>&nbsp;&nbsp;&nbsp; // xfa_element_ind --&gt;
"7 0"<BR>&nbsp;&nbsp;&nbsp; PdfIndirectReference ref = writer.addToBody(xfa
_stream, false).getIndirectReference();<BR>&nbsp;&nbsp;&nbsp; PdfReader
.killIndirect(xfa_element_ind);<BR>&nbsp;&nbsp;&nbsp; writer.getExtraCatalog()
.put(PdfName.XFA, ref);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<BR>An this one is like B:<BR>&nbsp;&nbsp;&nbsp; // xfa_element_ind --&gt; "7 0
"<BR>&nbsp;&nbsp;&nbsp; PdfIndirectReference ref = writer.addToBody(xfa_stream,
xfa_element_ind, false).getIndirectReference();<BR>&nbsp;&nbsp;&nbsp; PdfReader
.killIndirect(xfa_element_ind);<BR>&nbsp;&nbsp;&nbsp; writer.getExtraCatalog()
.put(PdfName.XFA, ref);<BR>
&nbsp;<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>
&nbsp;<BR>
I'm sorry, It's possible that I still haven't understood PDF concepts!<BR>
&nbsp;<BR>
Thanks a lot!<BR>
<BR>Isma<BR>
&nbsp;<BR>
<BR>&gt; Date: Tue, 6 Nov 2007 10:29:59 +0000<BR>&gt; From: psoares@(protected)
<BR>&gt; To: itext-questions@(protected)<BR>&gt; Subject: Re: [iText
-questions] Replacing PDF stream content<BR>&gt; <BR>&gt; You'll have to delete
the old object with PdfReader.killIndirect(PRIndirectReference).<BR>&gt; <BR>
&gt; Paulo <BR>&gt; <BR>&gt; &gt; -- --Original Message-- --<BR>&gt; &gt; From:
itext-questions-bounces@(protected) <BR>&gt; &gt; [mailto:itext
-questions-bounces@(protected)] On <BR>&gt; &gt; Behalf Of Ismael F<BR
>&gt; &gt; Sent: Tuesday, November 06, 2007 9:58 AM<BR>&gt; &gt; To: itext
-questions@(protected)<BR>&gt; &gt; Subject: [iText-questions]
Replacing PDF stream content<BR>&gt; &gt; <BR>&gt; &gt; Hello everybody,<BR>&gt
; &gt; <BR>&gt; &gt; I need to change, replace a whole stream of bytes 'object'
<BR>&gt; &gt; from a PDF. In this case those bytes corresponds to a XFA form.<BR
>&gt; &gt; <BR>&gt; &gt; The original PDF content is like:<BR>&gt; &gt; %PDF-1 (See http://PDF-1.ora-code.com).6
<BR>&gt; &gt; %????<BR>&gt; &gt; 1 0 obj &lt;&lt;/Type/Metadata/...<BR>&gt; &gt;
...<BR>&gt; &gt; ...<BR>&gt; &gt; 10 0 obj &lt;&lt;/Filter[/FlateDecode]/Type
/EmbeddedFile/Length <BR>&gt; &gt; 22459&gt;&gt;stream ... endstream<BR>&gt; &gt
; 11 0 obj .......<BR>&gt; &gt; ...<BR>&gt; &gt; <BR>&gt; &gt; So I use this
piece of code:<BR>&gt; &gt; PdfIndirectReference ref = writer.addToBody(new <BR
>&gt; &gt; PdfStream(form_field_property_value), xfa_element_ind, <BR>&gt; &gt;
false).getIndirectReference();<BR>&gt; &gt; writer.getExtraCatalog().put
(PdfName.XFA, ref);<BR>&gt; &gt; <BR>&gt; &gt; where "xfa_element_ind" is "10 0"
, and corresponds to the <BR>&gt; &gt; bytes adress that I want to replace.<BR>
&gt; &gt; <BR>&gt; &gt; As a result I get this PDF content:<BR>&gt; &gt; %PDF-1 (See http://PDF-1.ora-code.com)
.6<BR>&gt; &gt; %????<BR>&gt; &gt; 10 0 obj &lt;&lt;/Length 42101&gt;&gt;stream
... endstream<BR>&gt; &gt; 1 0 obj &lt;&lt;/Type/Metadata/...<BR>&gt; &gt; ...
<BR>&gt; &gt; ...<BR>&gt; &gt; ...<BR>&gt; &gt; 10 0 obj &lt;&lt;/Filter[
/FlateDecode]/Type/EmbeddedFile/Length <BR>&gt; &gt; 22459&gt;&gt;stream ...
endstream<BR>&gt; &gt; 11 0 obj .......<BR>&gt; &gt; ...<BR>&gt; &gt; <BR>&gt;
&gt; As one can see the content has not changed/replaced, is <BR>&gt; &gt;
duplicated and I don't achieve the desired result.<BR>&gt; &gt; <BR>&gt; &gt;
How can I make a direct substitution/replacement to the <BR>&gt; &gt; stream
without duplicating content?<BR>&gt; &gt; Is It possible?<BR>&gt; &gt; How?<BR>
&gt; &gt; <BR>&gt; &gt; I tried diferent things but I'm not able to get it!<BR>
&gt; &gt; <BR>&gt; &gt; Thanks a lot!<BR>&gt; <BR>&gt; <BR>&gt; Aviso Legal:<BR>
&gt; 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>&gt; <BR>&gt;
Disclaimer:<BR>&gt; 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>&gt; <BR>&gt; -- ---- ---- ---- ---- ---- ---- ---- ---- -----
-- ---- ---- ---- ---- --<BR>&gt; This SF.net email is sponsored by: Splunk Inc.
<BR>&gt; Still grepping through log files to find problems? Stop.<BR>&gt; Now
Search log events and configuration files using AJAX and a browser.<BR>&gt;
Download your FREE copy of Splunk now &gt;&gt; http://get.splunk.com/<BR>&gt; _
__ ____ ____ ____ ____ ____ ____ ____ ____ ___<BR>&gt; iText-questions mailing
list<BR>&gt; iText-questions@(protected)<BR>&gt; https://lists
.sourceforge.net/lists/listinfo/itext-questions<BR>&gt; 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/

©2008 junlu.com - Jax Systems, LLC, U.S.A.