I have PDF documents stored in an Oracle database as a BLOB which I need to
generate a new consolidated PDF from and store as new record in Oracle
Database as a new Blob. I have searched the forums for a similar situation
and I have the iText book, but I find that I still could use some assistance
and/or direction.
I am new to iText, Blobs, and Input/Output Stream programming so please
excuse my ignorance if my code contains errors. One unique requirement is
that I do NOT generate physical files on the server. Currently, I generate
an iText Document for the "output" stream using a PdfWriter without error.
When I attempt to open (read) a stored PDF (Blob) from the database using an
Input Stream, I encounter an IO Exception that the "PDF header signature not
found" constructing the PdfReader. Essentially, I want to read multiple PDF
documents stored as Blobs and append them to a new PDF document and then
store it as a Blob without generating any physical files on the server.
Here is the Reader's Digest version of my Java source code.
...
Document finalDocument = new Document(PageSize.A5, 36, 36, 108, 108);
... // query database to populate OracleResultSet with contents of BLOB
column
OracleResultSet blobDetails = (OracleResultSet) stmt.executeQuery("Select
BLOB_CONTENT from table");
if(blobDetails.next()){
InputStream input = blobDetails.getBLOB(1).getBinaryStream();
long mylong = blobDetails.getBLOB(1).length();
OutputStream fos = blobDetails.getBLOB(1).setBinaryStream(mylong);
PdfWriter writer = PdfWriter.getInstance(finalDocument, fos); // <-- this
is where the error is thrown
finalDocument.open();
// get input stream for file to append
blobDetails.next();
InputStream inputAppend = blobDetails.getBLOB(1).getBinaryStream();
PdfReader otherPDF = new PdfReader(inputAppend);
// add page by page
for(int x=1; x<=reader.getNumberOfPages(); x++){
PdfImportedPage page = writer.getImportedPage(reader,x);
Image image = Image.getInstance(page);
finalDocument.add(image);
}
// save document back to database
if(finalDocument.isOpen()){
try{
byte[] data = new byte[writer.getCurrentDocumentSize()];
Statement stmt = (OraclePreparedStatement)
conn.prepareStatement("Insert into upload_table(BLOB_CONTENT) values (?)");
stmt.setObject(1,data);
stmt.executeUpdate();
}catch(Exception e){e.printStackTrace();}
}
// close document
finalDocument.close();
--
View this message in context:
http://www.nabble.com/Editing-PDF-Stored-as-a-BLOB-without-Re-Constituting-File-tp19498541p19498541.html
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php