I did the following and it worked for me.

I created a test class which has a main method (just for testing purpose):

   public static void main(String[] args) {
       ByteArrayOutputStream bs;
       RomeoJulietBaos rmBaos=new RomeoJulietBaos();

       bs=rmBaos.mainExecute();
       System.out.println(bs);

   }

My second step was to alter the RomeoJuliet.java code like this:

I changed the main method to mainExecute with ByteArrayOutputStream as
return type:

public ByteArrayOutputStream mainExecute() {

inside I added the following:

       ByteArrayOutputStream baos=new ByteArrayOutputStream();
       try {
           // step 2:
           // we create a writer that listens to the document
           // and directs a XML-stream to a file
           PdfWriter writer = PdfWriter.getInstance(document,baos);

Instead of a FileOutPutStream, I pass the baos as parameter to the
PdfWriter.

The last step was to return the baos to the caller class:

       document.close();
       return bs;
   }

This worked fine and the result was printed to the console.

As I recall your original post, you mentioned that you want to display the
output in a browser. So you only need to change my test class to a servlet
with the proper response commands (see the link I send you last time), to
open the pdf.

2007/5/21, Jim Hurricane <[EMAIL PROTECTED]>:

Hi Bruno,

I'm assuming you mean to create the new ByteArrayOutputStream when the
writer is created (instead of the FileOutputStream to create the PDF
disk-based file), right?

So, my question then is what object would actually hold the BAOS when the
code is done?

If I create the BAOS as you suggested, I'm not sure how I'd get a hold of
the BAOS when the code is done. Perhaps, I'm not extracting the BAOS in
the
right part of the code?

I did try to create one where I defined the ByteArrayOutputStream outside
the writer creation code (in R&J example) then put the reference to the
BAOS
inside the writer creation code.

But, at the end of the code, there was still nothing in the BAOS. My goal
was to have a reference to the object (BAOS defined, and instantiated, at
the class level) that I could reference (with a filled-in BAOS) when the
code was done.

I must be missing something....

Look forward to your reply..

Thanks again.

- 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] BAOS in one step?
>Date: Mon, 21 May 2007 10:08:28 +0200
>
>Jim Hurricane wrote:
> > Sorry, I guess my question wasn't clear...
> >
> > I'm trying to see if there's a simple change that can be made to the
> > Romeo & Juliet Example that will let you output to a baos instead of
to
> > a physical file. If not, I already have the code that reads the PDF
into
> > a BAOS and returns it to the browser.
>
>You are referring to the example in chapter 14 of the book:
>http://itext.ugent.be/itext-in-action/chapter.php?chapter=14
>As explained in chapter 2, iText can write PDF to any OutputStream.
>In the example, a file is written to:
>new FileOutputStream("romeo_juliet.pdf")
>But you could easily replace this with baos, where baos is constructed
>like this: ByteArrayOutputStream baos = new ByteArrayOutputStream();
>
>br,
>Bruno
>
>-------------------------------------------------------------------------
>This SF.net email is sponsored by DB2 Express
>Download DB2 Express C - the FREE version of DB2 express and take
>control of your XML. No limits. Just data. Click to get it now.
>http://sourceforge.net/powerbar/db2/
>_______________________________________________
>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/

_________________________________________________________________
PC Magazine's 2007 editors' choice for best Web mail—award-winning Windows
Live Hotmail.

http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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/


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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