Hello and good morning from Germany,

I have started to use itext with some success and want to create my own utility library for my webapplication. That library should allow to load an arbitrary PDF-Document from the filesystem into memory to be given to other utility classes for further actions, like fill-out form fields, adding content, concatenating other documents and digitally signing the result. Additionally, I will have to create a completelz new Document to be handled by
the same utility classes, which I did successfully with the Document-class.

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. Even the result would only be put to the responding output stream to be downloaded by the client.

However, I have some problems in finding a useful data type for handling PDF-Documents for that purpose. I tried to load a PDF-Document from the filesystem using PDFReader and to migrate its content to a byte-Array using the following method. The reason for this was that the byte-Array can be used to create further PDFReader-objects, which I use for the other utility-actions like filling form fields or digitally sign the document.

--- 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!---

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

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

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?




--
Oliver Schönwald, Diplom-Informatiker

FernUniversität Hagen
Zentrum für IT und Medien (ZMI) - Competence Center Anwendungsentwicklung
Universitätsstr.21/AVZ - 58084 Hagen - Deutschland
fon: +49 2331 987 1721 - email: [EMAIL PROTECTED]

begin:vcard
fn:Oliver Schoenwald
n:Schoenwald;Oliver
org;quoted-printable:FernUniversitaet Hagen;ZMI - Zentrum f=C3=BCr Medien und IT
adr:;;Universitaetsstrasse 21;Hagen;NRW;58300;Deutschland
email;internet:[EMAIL PROTECTED]
tel;work:02331 987 1721
x-mozilla-html:FALSE
url:http://www.fernuni-hagen.de
version:2.1
end:vcard

-------------------------------------------------------------------------
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