I still do not have a solution to this problem, but i can share a workaround incase someone runs into the same issue.
All I did was instead of sending the baos to the output, I loaded it into a PDFReader and then used PDFCopy to make an an exact replica of it into another stream. This new stream works as expected. If anyone knows of a real solution, please share :) - Michael On 9/17/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Date: Fri, 15 Sep 2006 20:48:00 -0400 > From: "Michael Shmulenson" <[EMAIL PROTECTED]> > Subject: [iText-questions] last page trouble > To: [email protected] > Message-ID: > <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=UTF-8; format=flowed > > I have a strange issue related to concatenation of PDFs. Everything > works very well (almost). I am able to process dozens of pdfs, while > adding headers and footers. The problem occurs when certain pdfs are > the last to get concatenated. From what I can tell, there is nothing > special about these pdfs. The same files work perfectly well when > that are NOT at the end. I have narrowed it down to one particular pdf > that consists of about half a page of text. I played around with it > until adding a single character (any character) caused the "damaged > file" error from acrobat. As I mentioned before, the same "bad" file > works just fine when i added another file to the queue so it would not > be be processed last. When I first saw this issue, I assumed it is > related to me not "flushing" :) properly and thus sending out > incomplete pdf. I checked, but everything looks correct. I dont > think I had this issue when I used PDFCopy, but because I needed to > apply headers and footers I had to switch to PDFWriter. > > Here is my set up. I use a servlet that starts the process: > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > > // some code here that initializes needed variables > > baos = ReportGenerator.regenerateReport(baos, sURL, exhibitList, > sFirmName, sFooter); > > resp.setHeader("Expires", "0"); > resp.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); > resp.setHeader("Pragma", "public"); > resp.setContentType("application/pdf"); > > resp.setContentLength(baos.size()); > > ServletOutputStream out = resp.getOutputStream(); > > baos.writeTo(out); > out.flush(); > out.close(); > > > > > then I have a separate class that handles the generation: > > > > > public static ByteArrayOutputStream > regenerateReport(ByteArrayOutputStream baos, String sURL, ArrayList > exhibitList, String sFirmName, String sFooter) throws IOException { > > Document document = null; > PdfWriter writer = null; > PdfReader reader = null; > > document = new Document(PageSize.LETTER); > > try { > writer = PdfWriter.getInstance(document, baos); > writer.setPageEvent(new ReportGenerator(sFirmName, sFooter)); > > document.open(); > > reader = new PdfReader(new URL(sURL)); > processPDF(reader, writer, document); > > } catch(DocumentException de) { > de.printStackTrace(); > } finally { > document.close(); > writer.freeReader(reader); > } > > return baos; > } > > private static void processPDF(PdfReader reader, PdfWriter writer, > Document document) throws IOException, BadPdfFormatException, > DocumentException { > reader.consolidateNamedDestinations(); > > PdfContentByte cb = writer.getDirectContent(); > PdfImportedPage page; > for (int i = 1; i <= n; i++) { > document.newPage(); > page = writer.getImportedPage(reader, i); > cb.addTemplate(page, 0, -3); > } > > } > > > Any ideas? Any help would be greatly appriciated. I already spent a > few hours on this, and I am afraid I may have to put in some "ugly" > work around if I do not get to a solution soon. Thank you. > > -- > Michael Shmulenson > > > -- Michael Shmulenson ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
