All,
I'm using iText to merge multiple pdfs together. However, under certain
conditions iText is throwing an exception with the above message.
Here is the code I use to merge docs together:
/**
* Merges a list of PDF documents
* @param pdfGenerationContext
*/
private void mergePDFs(PDFGenerationContext pdfGenerationContext) throws
EDistPDFException {
logger.debug("Enter method");
int fileCount = 0;
com.lowagie.text.Document document = null;
PdfCopy writer = null;
IPDFPage pdfPage = null;
ByteArrayOutputStream baos = null;
try {
Iterator iterator = pdfGenerationContext.getPdfPages().iterator();
while (iterator.hasNext()){
pdfPage = (IPDFPage) iterator.next();
PdfReader reader = new PdfReader(pdfPage.getPDFBytes());
if (fileCount == 0){
document = new
com.lowagie.text.Document(reader.getPageSizeWithRotation(1));
baos = new ByteArrayOutputStream();
writer = new PdfCopy(document, baos);
document.open();
}
int pageCount = reader.getNumberOfPages();
PdfImportedPage page = null;
for (int i = 0; i < pageCount;){
++i;
page = writer.getImportedPage(reader, i);
writer.addPage(page);
}
fileCount++;
}
document.close();
}
catch(IOException ioe){
logger.error("Error merging PDF: " + ioe.getMessage());
throw new EDistPDFException(ioe);
}
catch(BadPdfFormatException badPdfe){
logger.error("Error merging PDF: " + badPdfe.getMessage());
throw new EDistPDFException(badPdfe.getMessage());
}
catch(
com.lowagie.text.DocumentException dome){
logger.error("Error merging PDF: " + dome.getMessage());
throw new EDistPDFException(dome.getMessage());
}
_________________________________________________________________
Don?t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/