I am trying to concatenate two pdf's. The first pdf is a set of "notes" the second pdf is comprised of images. I found an example that seems to work as far as getting the page numbers correctly on all the pages, however only part of the image is displayed on the final pdf. Paginate is set to true. You can see on the original pdf that the entire image was sized to fit on the page, but on the merged pdf the image is blown up & only partially viewable. Is this an example I should be using, or is there a more appropriate way to do this? Please adivse.
Attached is my source code and the two pdfs I am trying to merge along with the final pdf. Below is the method I am using. It came from an example posted here: http://java-x.blogspot.com/2006/11/merge-pdf-files-with-itext.html How do I get my images to be sized appropriately on the final pdf? public static void concatPDFs(List<InputStream> streamOfPDFFiles, OutputStream outputStream, boolean paginate) { //paginate needs to be true in order to get page numbers on the first file Document document = new Document(); try { List<InputStream> pdfs = streamOfPDFFiles; List<PdfReader> readers = new ArrayList<PdfReader>(); int totalPages = 0; Iterator<InputStream> iteratorPDFs = pdfs.iterator(); // Create Readers for the pdfs. while (iteratorPDFs.hasNext()) { InputStream pdf = iteratorPDFs.next(); PdfReader pdfReader = new PdfReader(pdf); readers.add(pdfReader); totalPages += pdfReader.getNumberOfPages(); System.out.println("the total pages " + totalPages); } // Create a writer for the outputstream PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); PdfContentByte cb = writer.getDirectContent(); // Holds the PDF // data PdfImportedPage page; int currentPageNumber = 0; int pageOfCurrentReaderPDF = 0; Iterator<PdfReader> iteratorPDFReader = readers.iterator(); // Loop through the PDF files and add to the output. while (iteratorPDFReader.hasNext()) { PdfReader pdfReader = iteratorPDFReader.next(); // Create a new page in the target for each source page. while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) { document.newPage(); pageOfCurrentReaderPDF++; currentPageNumber++; page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF); cb.addTemplate(page, 0, 0); // Code for pagination. if (paginate) { cb.beginText(); cb.setFontAndSize(bf, 9); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Page " + currentPageNumber + " of " + totalPages, 520, 5, 0); cb.endText(); } } pageOfCurrentReaderPDF = 0; } outputStream.flush(); document.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (document.isOpen()) document.close(); try { if (outputStream != null) outputStream.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } } http://www.nabble.com/file/p24377657/MergePDF.java MergePDF.java http://www.nabble.com/file/p24377657/image.pdf image.pdf http://www.nabble.com/file/p24377657/note.pdf note.pdf http://www.nabble.com/file/p24377657/merged.pdf merged.pdf -- View this message in context: http://www.nabble.com/How-to-concatenate%2C-number-pages-and-keep-image-size-in-proportion---tp24377657p24377657.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/blackberry _______________________________________________ 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 Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
