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: oliver.schoenwald@(protected)