List of usage examples for com.itextpdf.text Image setDpi
public void setDpi(final int dpiX, final int dpiY)
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 www . j a v a2 s . c om*/ 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(); }
From source file:mobac.program.atlascreators.PaperAtlasPdf.java
License:Open Source License
@Override protected void processPage(BufferedImage image, int pageNumber) throws MapCreationException { int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); if (document == null) { double width = UnitSystem.pixelsToPoints(imageWidth, s.dpi); double height = UnitSystem.pixelsToPoints(imageHeight, s.dpi); width += s.marginLeft + s.marginRight; height += s.marginTop + s.marginBottom; Rectangle r = new Rectangle((float) width, (float) height); document = createDocument(r);/* w w w . ja va 2s . c om*/ } Image iTextImage; try { iTextImage = Image.getInstance(image, Color.WHITE); } catch (BadElementException e) { throw new MapCreationException(map, e); } catch (IOException e) { throw new MapCreationException(map, e); } iTextImage.setCompressionLevel(s.compression); iTextImage.setDpi(s.dpi, s.dpi); float width = (float) UnitSystem.pixelsToPoints(imageWidth, s.dpi); float height = (float) UnitSystem.pixelsToPoints(imageHeight, s.dpi); iTextImage.scaleAbsolute(width, height); try { document.add(iTextImage); } catch (DocumentException e) { throw new MapCreationException(map, e); } document.newPage(); }
From source file:org.durel.mydooble.ImageItem.java
License:Open Source License
@Override public void toPDF(PDF out, int i) { super.toPDF(out, i); try {// w ww . jav a 2s . c om Image img = Image.getInstance(image); img.setDpi(288, 288); img.setInterpolation(true); float ih = (float) (img.getHeight()); float iw = (float) (img.getWidth()); if (ih > h || iw > w) { float xratio = iw / w; float yratio = ih / h; float ratio = Math.max(xratio, yratio); log.info("ih: " + ih + " - iw: " + iw + " - xratio: " + xratio + " - yratio: " + yratio + " - ratio: " + ratio + " --> " + (int) (iw / ratio) + "x" + (int) (ih / ratio)); img.scalePercent(100 / ratio); } PdfContentByte cb = out.writer.getDirectContent(); float x = bx + (c * (w + m)) + m; float y = by + (r * (h + m)) + m; img.setAbsolutePosition(x, y); cb.addImage(img); } catch (DocumentException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }