List of usage examples for com.lowagie.text Image getPlainHeight
public float getPlainHeight()
From source file:org.mapfish.print.PDFUtils.java
License:Open Source License
/** * Gets an iText image with a cache that uses PdfTemplates to re-use the same * bitmap content multiple times in order to reduce the file size. *///ww w . j a va 2 s . c om public static Image getImage(RenderingContext context, URI uri, float w, float h) throws IOException, DocumentException { //Check the image is not already used in the PDF file. // //This part is not protected against multi-threads... worst case, a single image can //be twice in the PDF, if used more than one time. But since only one !map //block is dealed with at a time, this should not happen Map<URI, PdfTemplate> cache = context.getTemplateCache(); PdfTemplate template = cache.get(uri); if (template == null) { Image content = getImageDirect(context, uri); content.setAbsolutePosition(0, 0); final PdfContentByte dc = context.getDirectContent(); synchronized (context.getPdfLock()) { //protect against parallel writing on the PDF file template = dc.createTemplate(content.getPlainWidth(), content.getPlainHeight()); template.addImage(content); } cache.put(uri, template); } //fix the size/aspect ratio of the image in function of what is specified by the user if (w == 0.0f) { if (h == 0.0f) { w = template.getWidth(); h = template.getHeight(); } else { w = h / template.getHeight() * template.getWidth(); } } else { if (h == 0.0f) { h = w / template.getWidth() * template.getHeight(); } } final Image result = Image.getInstance(template); result.scaleToFit(w, h); return result; }
From source file:org.opencms.pdftools.CmsPdfUserAgent.java
License:Open Source License
/** * Scales the image to output resolution.<p> * * @param image the image to scale/*from ww w .ja v a2 s. com*/ */ private void scaleToOutputResolution(Image image) { float factor = m_sharedContext.getDotsPerPixel(); if (factor != 1.0f) { image.scaleAbsolute(image.getPlainWidth() * factor, image.getPlainHeight() * factor); } }
From source file:org.xhtmlrenderer.pdf.ITextUserAgent.java
License:Open Source License
private void scaleToOutputResolution(Image image) { float factor = _sharedContext.getDotsPerPixel(); if (factor != 1.0f) { image.scaleAbsolute(image.getPlainWidth() * factor, image.getPlainHeight() * factor); }//from www. j ava 2s .c o m }
From source file:questions.ocg.AddOptionalWatermark.java
public static void main(String[] args) throws DocumentException, IOException { PdfReader reader = new PdfReader(RESOURCE); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); Image image1 = Image.getInstance(IMAGE_PRINTED); Image image2 = Image.getInstance(IMAGE_NOT_PRINTED); PdfLayer watermark_printed = new PdfLayer("printed", stamper.getWriter()); watermark_printed.setOn(false);/*from w w w .j a va 2 s . c o m*/ watermark_printed.setOnPanel(false); watermark_printed.setPrint("print", true); PdfLayer watermark_not_printed = new PdfLayer("not_printed", stamper.getWriter()); watermark_not_printed.setOn(true); watermark_not_printed.setOnPanel(false); watermark_not_printed.setPrint("print", false); for (int i = 0; i < stamper.getReader().getNumberOfPages();) { PdfContentByte cb = stamper.getUnderContent(++i); Rectangle rectangle = stamper.getReader().getPageSizeWithRotation(i); cb.beginLayer(watermark_printed); float AbsoluteX = rectangle.getLeft() + (rectangle.getWidth() - image1.getPlainWidth()) / 2; float AbsoluteY = rectangle.getBottom() + (rectangle.getHeight() - image1.getPlainHeight()) / 2; image1.setAbsolutePosition(AbsoluteX, AbsoluteY); cb.addImage(image1); cb.endLayer(); cb.beginLayer(watermark_not_printed); AbsoluteX = rectangle.getLeft() + (rectangle.getWidth() - image2.getPlainWidth()) / 2; AbsoluteY = rectangle.getBottom() + (rectangle.getHeight() - image2.getPlainHeight()) / 2; image2.setAbsolutePosition(AbsoluteX, AbsoluteY); cb.addImage(image2); cb.endLayer(); } stamper.close(); }