List of usage examples for com.itextpdf.text Image rotate
public Rectangle rotate()
From source file:adams.gui.print.PDFWriter.java
License:Open Source License
/** * generates the actual output./*w w w.j ava 2s .com*/ * * @throws Exception if something goes wrong */ @Override public void generateOutput() throws Exception { BufferedImage bi; Document doc; Image image; float scale; FileOutputStream fos; // render image bi = createBufferedImage(); // generate PDF scale = (float) m_ImageScale; doc = new Document(); fos = new FileOutputStream(getFile().getAbsoluteFile()); PdfWriter.getInstance(doc, fos); doc.open(); image = Image.getInstance(Toolkit.getDefaultToolkit().createImage(bi.getSource()), null); if (m_ImageRotation != 0) { image.setRotationDegrees(m_ImageRotation); image.rotate(); } image.scaleToFit(doc.getPageSize().getWidth() * scale, doc.getPageSize().getHeight() * scale); doc.add(image); doc.close(); FileUtils.closeQuietly(fos); }
From source file:com.tommontom.pdfsplitter.PdfMerge.java
public static void doMerge(java.util.List<InputStream> list, String[] imageList, String[] listWordExcels, OutputStream outputStream) throws DocumentException, IOException { Document document = new Document(PageSize.LETTER, 0, 0, 0, 0); PdfWriter writer = PdfWriter.getInstance(document, outputStream); writer.setFullCompression();//from ww w .ja v a 2 s . com document.open(); PdfContentByte cb = writer.getDirectContent(); Image img; for (InputStream in : list) { PdfReader reader = new PdfReader(in); for (int i = 1; i <= reader.getNumberOfPages(); i++) { document.newPage(); //import the page from source pdf PdfImportedPage page = writer.getImportedPage(reader, i); //add the page to the destination pdf cb.addTemplate(page, 0, 0); } } for (int i = 0; i < imageList.length; i++) { document.newPage(); if (imageList[i] != null) { img = Image.getInstance(String.format("%s", imageList[i])); Rectangle one = new Rectangle(img.getPlainWidth(), img.getPlainHeight()); document.setPageSize(one); if (img.getScaledWidth() > img.getScaledHeight()) { img.rotate(); } if (img.getScaledWidth() > 792 || img.getScaledHeight() > 792) { img.scaleToFit(792, 792); } img.setDpi(150, 150); document.add(img); } } for (int i = 0; i < listWordExcels.length; i++) { if (imageList[i] != null) { File input = new File(listWordExcels[i]); File output = new File(listWordExcels[i] + ".pdf"); String outputS = listWordExcels[i] + ".pdf"; OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(input, output); PdfReader readerWord = new PdfReader(outputS); PdfImportedPage page = writer.getImportedPage(readerWord, readerWord.getNumberOfPages()); cb.addTemplate(page, 0, 0); } } outputStream.flush(); document.close(); outputStream.close(); }