When using repeatedely the same template it's often overlooked the
PdfReader copy constructor that can speed up things. For example and
taking your example:

PdfReader original = new PdfReader(readerStream ); //store the original
somewhere

PdfReader polReader = new PdfReader(original); //repeat this for each
run
  
Paulo

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Iliadis Yannis
> Sent: Friday, April 13, 2007 2:37 PM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Reading a PDF via a 
> ByteArrayOutputStream?
> 
> To give you a small example:
> 
> First I define a static reference to the template (physical file).
>     static String TEMPLATE_PATH="print/templates/template.pdf"; 
> 
> 
> Later in my code I have a function which adds contents to the pdf.
> 
>            ByteArrayOutputStream policyAsOutputStream = new 
> ByteArrayOutputStream();
> 
>            InputStream 
> readerStream=getClass().getResourceAsStream(TEMPLATE_PATH);
> 
>            PdfReader polReader = new PdfReader(readerStream );
> 
>            PdfStamper polStamp = new PdfStamper(polReader, 
> policyAsOutputStream);
> 
> After that I do all my content manipulation (e.g. setting 
> acrofields with data, placing tables, list etc.)
> 
> And at the end I return the ByteArrayOutputStream which is 
> servered through the web service to the web client. 
> 
>         return policyAsOutputStream; 
> 
> 
> 
> 2007/4/13, Mork Afur <[EMAIL PROTECTED]>: 
> 
>       Interesting.
>       
>       It really sounds like the file based approach makes 
> more sense (since the 
>       Adobe plug-in can't handle memory-only baos's).
>       
>       Iliadis mentioned reading the PDF into a 
> ByteArrayOutputStream.  However,
>       checking around the book (including chapter 17), I 
> didn't find a simple way 
>       to load an existing file-based PDF into a baos.
>       
>       The following example files use baos, but, don't seem 
> to load an existing
>       PDF into one. (probably because it's not useful?)
>       
>       C:\temp\examples\chapter02\HelloWorldAddMetadata.java 
>       C:\temp\examples\chapter02\HelloWorldCopyStamp.java
>       C:\temp\examples\chapter02\HelloWorldStampCopy.java
>       C:\temp\examples\chapter02\HelloWorldStampCopyStamp.java
>       C:\temp\examples\chapter17\FoobarCourses.java
>       C:\temp\examples\chapter17\helloworld.jsp
>       C:\temp\examples\chapter17\OutSimplePdf.java
>       C:\temp\examples\chapter17\ProgressServlet.java
>       C:\temp\examples\chapterF\HelloWorldAddMetadata.java
>       C:\temp\examples\chapterF\HelloWorldXmpMetadata.java 
>       
>       Thanks in advance.
>       
>       M
>       
>       
>       >From: "Bruno Lowagie (iText)" <[EMAIL PROTECTED]>
>       >Reply-To: Post all your questions about iText here
>       >< [EMAIL PROTECTED]>
>       >To: Post all your questions about iText here
>       ><[EMAIL PROTECTED] >
>       >Subject: Re: [iText-questions] Reading a PDF via a 
> ByteArrayOutputStream?
>       >Date: Fri, 13 Apr 2007 13:43:37 +0200
>       >
>       >Strange, I received the answer to this question,
>       >but not the original question. Anyhow: 
>       >
>       >Iliadis Yannis wrote:
>       > > I for myself read a pdf template (physical file) into a
>       > > ByteArrayOutputStream and pass it to a PdfStamper 
> where I do all the
>       > > manipulation (in your case a PdfWriter object). 
>       >
>       >That's an ideal way to do it if you are reusing
>       >the same template over and over again.
>       >
>       > > After that the final pdf (still a 
> ByteArrayOutputStream) is send through
>       > > a web service to the clients web browser. From 
> there the adobe reader 
>       > > plug takes over and shows the pdf.
>       >
>       >Yep, but remember that the PDF will be stored somewhere
>       >as a file on the client machine (maybe only temporarily).
>       >Most viewer (certainly Adobe Reader) need the PDF as a 
>       >file; Adobe Reader doesn't accept a byte stream from memory.
>       >
>       > > 2007/4/13, Mork Afur <[EMAIL PROTECTED]
>       > > <mailto: [EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]> >>:
>       > >
>       > >     In the case where a file-based PDF would have a 
> short life span, we
>       >are
>       > >     thinking about just using a 
> ByteArrayOutputStream representation for 
>       > >     creating and viewing the PDF.
>       > >
>       > >     Is this possible? I'm not sure how we'd "view" the
>       > >     ByteArrayOutputStream.
>       > >
>       > >     Also, there is only one example (in the 297 
> java examples with the 
>       >book)
>       > >     that returns a "baos" object.
>       >
>       >In Chapter 2 I explain that you can write to any OutputStream,
>       >including a ByteArrayOutputStream. Point is: how are you going
>       >to send those bytes to a Viewer?
>       >If you really want to keep the documents in memory only,
>       >you could try writing a PDF to a Ramdisk and let the viewer
>       >read it from there. I haven't tried this yet. Do people still 
>       >use ramdisk? I feel very old when I use that word...
>       >
>       >br,
>       >Bruno
>       >


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.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to