Oliver Schoenwald wrote:
> Hello and good morning from Germany,

Good morning from Belgium! We're neighbors ;-)

> Because the webapplication should not write unnecessary data to the 
> filesystem, because the created pages are
> to be send to the webclient only, so I want to handle the whole 
> PDF-Document (loaded, created, changed, concatenated etc.)
> in memory only.

OK, that's also how I write my web applications:
nothing is stored on disk on the serverside.

However, this is totally wrong:
> --- snip! ---
> private static byte[] readDocument(PdfReader reader) throws 
> DocumentException, IOException {
>    ByteArrayOutputStream baos = new ByteArrayOutputStream();
>    for ( int i = 1; i <= reader.getNumberOfPages(); i++ ) {
>        byte[] content = reader.getPageContent(i);
>        baos.write(content, 0, content.length);
>    }
>    return baos.toByteArray();
> --- snip!---

The page content is a stream of PDF syntax.
For instance:

q
BT
36 806 Td
0 -18 Td
/F1 12 Tf
(Hello World)Tj
ET
Q

In your code snippet, you are concatenating streams
like this, throwing away the document structure,
resources like the font /F1, and so on...

> Alas, the result seems to be broken.

That's only normal.

> When I use the resulting byte-Array 
> to create a new PDFReader-object,
> "java.io.IOException: PDF header signature not found" is being thrown.

One of the items in the above 'and so on...',
is the document header: something like: %PDF-1.4

> I assume that the PDF-Document contains more than is being put into the 
> byte-Array when using getPageContent(int).

That's an understatement ;-)

> What would be the more convenient method to load and handle a 
> PDF-Document in memory space? Or do I have to
> add something to my readDocument()-method to migrate the complete 
> PDF-Document to the byte-Array?

You don't need any iText related code to read a file
into a byte[]. You can do this with the usual java.io methods.
Or you could use the iText class RandomAccessFileOrArray:
new RandomAccessFileOrArray(pdf);
where the parameter pdf can be a filename, a byte[], an InputStream,...
I think that's the class you're looking for.

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/

Reply via email to