List of usage examples for com.lowagie.text Image getPlainHeight
public float getPlainHeight()
From source file:com.toolkit.util.pdf.HomeITextUserAgent.java
License:Open Source License
private void scaleToOutputResolution(Image image) { float factor = _sharedContext.getDotsPerPixel(); image.scaleAbsolute(image.getPlainWidth() * factor, image.getPlainHeight() * factor); }
From source file:controllers.PdfUserAgent.java
private void scaleToOutputResolution(Image image) { float factor = getSharedContext().getDotsPerPixel(); image.scaleAbsolute(image.getPlainWidth() * factor, image.getPlainHeight() * factor); }
From source file:org.eclipse.birt.report.engine.emitter.pdf.PDFPage.java
License:Open Source License
protected void drawBackgroundImage(float x, float y, float width, float height, float imageWidth, float imageHeight, int repeat, String imageUrl, byte[] imageData, float offsetX, float offsetY) throws Exception { contentByte.saveState();//from www . j a v a2 s.co m clip(x, y, width, height); PdfTemplate image = null; if (imageUrl != null) { if (pageDevice.getImageCache().containsKey(imageUrl)) { image = pageDevice.getImageCache().get(imageUrl); } } if (image == null) { Image img = Image.getInstance(imageData); if (imageHeight == 0 || imageWidth == 0) { int resolutionX = img.getDpiX(); int resolutionY = img.getDpiY(); if (0 == resolutionX || 0 == resolutionY) { resolutionX = 96; resolutionY = 96; } imageWidth = img.getPlainWidth() / resolutionX * 72; imageHeight = img.getPlainHeight() / resolutionY * 72; } image = contentByte.createTemplate(imageWidth, imageHeight); image.addImage(img, imageWidth, 0, 0, imageHeight, 0, 0); if (imageUrl != null && image != null) { pageDevice.getImageCache().put(imageUrl, image); } } boolean xExtended = (repeat & BackgroundImageInfo.REPEAT_X) == BackgroundImageInfo.REPEAT_X; boolean yExtended = (repeat & BackgroundImageInfo.REPEAT_Y) == BackgroundImageInfo.REPEAT_Y; imageWidth = image.getWidth(); imageHeight = image.getHeight(); float originalX = offsetX; float originalY = offsetY; if (xExtended) { while (originalX > 0) originalX -= imageWidth; } if (yExtended) { while (originalY > 0) originalY -= imageHeight; } float startY = originalY; do { float startX = originalX; do { drawImage(image, x + startX, y + startY, imageWidth, imageHeight); startX += imageWidth; } while (startX < width && xExtended); startY += imageHeight; } while (startY < height && yExtended); contentByte.restoreState(); }
From source file:org.eclipse.birt.report.engine.layout.pdf.emitter.ImageLayout.java
License:Open Source License
/** * get intrinsic dimension of image in pixels. Now only support png, bmp, * jpg, gif.//from w w w.ja v a 2 s .c o m * * @return * @throws IOException * @throws MalformedURLException * @throws BadElementException */ protected Dimension getIntrinsicDimension(IImageContent content, Image image) throws BadElementException, MalformedURLException, IOException { if (image != null) { // The DPI resolution of the image. // the preference of the DPI setting is: // 1. the resolution restored in content. // 2. the resolution in image file. // 3. use the DPI in render options. // 4. the DPI in report designHandle. // 5. the JRE screen resolution. // 6. the default DPI (96). int contentResolution = content.getResolution(); if (contentResolution != 0) { resolutionX = contentResolution; resolutionY = contentResolution; } else { resolutionX = PropertyUtil.getImageDpi(content, image.getDpiX(), context.getDpi()); resolutionY = PropertyUtil.getImageDpi(content, image.getDpiY(), context.getDpi()); } return new Dimension((int) (image.getPlainWidth() * 1000 / resolutionX * 72), (int) (image.getPlainHeight() * 1000 / resolutionY * 72)); } return null; }
From source file:org.eclipse.birt.report.engine.layout.pdf.PDFImageLM.java
License:Open Source License
/** * get intrinsic dimension of image in pixels. Now only support png, bmp, * jpg, gif.// w w w. j a v a 2 s. c om * * @param in * @return * @throws IOException * @throws MalformedURLException * @throws BadElementException */ protected Dimension getIntrinsicDimension(IImageContent content) throws BadElementException, MalformedURLException, IOException { Image image = null; switch (content.getImageSource()) { case IImageContent.IMAGE_FILE: ReportDesignHandle design = content.getReportContent().getDesign().getReportDesign(); URL url = design.findResource(content.getURI(), IResourceLocator.IMAGE, content.getReportContent().getReportContext() == null ? null : content.getReportContent().getReportContext().getAppContext()); InputStream in = url.openStream(); try { byte[] buffer = new byte[in.available()]; in.read(buffer); image = Image.getInstance(buffer); } catch (Exception ex) { logger.log(Level.WARNING, ex.getMessage(), ex); } finally { in.close(); } break; case IImageContent.IMAGE_NAME: case IImageContent.IMAGE_EXPRESSION: image = Image.getInstance(content.getData()); break; case IImageContent.IMAGE_URL: image = Image.getInstance(new URL(content.getURI())); break; default: assert (false); } if (image != null) { int resolution = 96; int contentResolution = content.getResolution(); if (contentResolution != 0) { resolution = contentResolution; } return new Dimension((int) (image.getPlainWidth() * 1000 / resolution * 72), (int) (image.getPlainHeight() * 1000 / resolution * 72)); } return null; }
From source file:org.eclipse.birt.report.engine.nLayout.area.impl.ContainerArea.java
License:Open Source License
protected void updateBackgroundImage() { BackgroundImageInfo bgi = boxStyle.getBackgroundImage(); Image img = null; if (bgi != null) { img = bgi.getImageInstance();//w ww. ja v a 2 s .co m if (img != null) { int resolutionX = img.getDpiX(); int resolutionY = img.getDpiY(); if (0 == resolutionX || 0 == resolutionY) { resolutionX = 96; resolutionY = 96; } float imageWidth = img.getPlainWidth() / resolutionX * 72; float imageHeight = img.getPlainHeight() / resolutionY * 72; if (content != null) { IStyle style = content.getComputedStyle(); int ox = getDimensionValue(style.getProperty(IStyle.STYLE_BACKGROUND_POSITION_X), (width - (int) (imageWidth * PDFConstants.LAYOUT_TO_PDF_RATIO))); int oy = getDimensionValue(style.getProperty(IStyle.STYLE_BACKGROUND_POSITION_Y), (height - (int) (imageHeight * PDFConstants.LAYOUT_TO_PDF_RATIO))); bgi.setXOffset(ox); bgi.setYOffset(oy); } } } }
From source file:org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.java
License:Open Source License
protected BackgroundImageInfo createBackgroundImage(String url) { ResourceLocatorWrapper rl = null;//ww w . ja v a2 s . c o m ExecutionContext exeContext = ((ReportContent) content.getReportContent()).getExecutionContext(); if (exeContext != null) { rl = exeContext.getResourceLocator(); } IStyle cs = pageContent.getComputedStyle(); BackgroundImageInfo backgroundImage = new BackgroundImageInfo(url, cs.getProperty(IStyle.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl); Image img = backgroundImage.getImageInstance(); IStyle style = pageContent.getStyle(); String widthStr = style.getBackgroundWidth(); String heightStr = style.getBackgroundHeight(); if (img != null) { int resolutionX = img.getDpiX(); int resolutionY = img.getDpiY(); if (0 == resolutionX || 0 == resolutionY) { resolutionX = 96; resolutionY = 96; } float imageWidth = img.getPlainWidth() / resolutionX * 72 * PDFConstants.LAYOUT_TO_PDF_RATIO; float imageHeight = img.getPlainHeight() / resolutionY * 72 * PDFConstants.LAYOUT_TO_PDF_RATIO; int actualWidth = (int) imageWidth; int actualHeight = (int) imageHeight; if (widthStr != null && widthStr.length() > 0 || heightStr != null && heightStr.length() > 0) { if ("contain".equals(widthStr) || "contain".equals(heightStr)) { float rh = imageHeight / height; float rw = imageWidth / width; if (rh > rw) { actualHeight = height; actualWidth = (int) (imageWidth * height / imageHeight); } else { actualWidth = width; actualHeight = (int) (imageHeight * width / imageWidth); } } else if ("cover".equals(widthStr) || "cover".equals(heightStr)) { float rh = imageHeight / height; float rw = imageWidth / width; if (rh > rw) { actualWidth = width; actualHeight = (int) (imageHeight * width / imageWidth); } else { actualHeight = height; actualWidth = (int) (imageWidth * height / imageHeight); } } else { DimensionType widthDim = DimensionType.parserUnit(widthStr); DimensionType heightDim = DimensionType.parserUnit(heightStr); if (widthDim != null) { actualWidth = PropertyUtil.getDimensionValue(content, widthDim); if (heightDim == null) { actualHeight = (int) (imageHeight * actualWidth / imageWidth); } else { actualHeight = PropertyUtil.getDimensionValue(content, heightDim); } } else if (heightDim != null) { actualHeight = PropertyUtil.getDimensionValue(content, heightDim); if (widthDim == null) { actualWidth = (int) (imageWidth * actualHeight / imageHeight); } else { actualWidth = PropertyUtil.getDimensionValue(content, widthDim); } } else { actualHeight = (int) imageHeight; actualWidth = (int) imageWidth; } } } backgroundImage.setXOffset( getDimensionValue(cs.getProperty(IStyle.STYLE_BACKGROUND_POSITION_X), width - actualWidth)); backgroundImage.setYOffset( getDimensionValue(cs.getProperty(IStyle.STYLE_BACKGROUND_POSITION_Y), height - actualHeight)); backgroundImage.setHeight(actualHeight); backgroundImage.setWidth(actualWidth); return backgroundImage; } return null; }
From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java
License:Open Source License
/** Print an iText image */ private void printImage(Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate) throws DocumentException { if (image != null) { float boxWidth = Math.abs(x2 - x1) + 1; float boxHeight = Math.abs(y2 - y1) + 1; log.debug("Print Image (Size w=" + image.getPlainWidth() + ",h=" + image.getPlainHeight() + ") wthin BOX (w=" + boxWidth + ",h=" + boxHeight + ") FitMethod = " + fitMethod); // Clip the image based on the bounding box if (fitMethod == FIT_METHOD_CLIP) { if ((boxWidth < image.getPlainWidth()) || (boxHeight < image.getPlainHeight())) { // @TODO - Clip image log.warn("IMAGE CLIPPING REQUIRED, but not implemented - default to 'SCALE'..."); fitMethod = FIT_METHOD_SCALE; }/*from w w w . ja v a 2s . c om*/ } // Stretch/shrink both the X/Y to fit the bounding box if (fitMethod == FIT_METHOD_FILL) { log.debug("Scale image to fill box"); image.scaleToFit(x2 - x1, y2 - y1); } // Stretch/shrink preserving the aspect ratio to fit the bounding box if (fitMethod == FIT_METHOD_SCALE) { float multipler = Math.min(boxWidth / image.getPlainWidth(), boxHeight / image.getPlainHeight()); log.debug("Need to scale image by " + (Math.floor(multipler * 10000) / 100) + "%"); image.scalePercent(multipler * 100); } log.debug("Print image at (" + x1 + "," + y1 + ")"); image.setAbsolutePosition(x1, y1); image.setRotationDegrees(rotate); cb.addImage(image); //Phrase text = new Phrase(new Chunk(image, 0, 0)); //ColumnText ct = new ColumnText(cb); //ct.setSimpleColumn(text, x1, y1, x2, y2, 10, alignment); //ct.go(); } }
From source file:org.kuali.coeus.common.impl.print.watermark.WatermarkServiceImpl.java
License:Open Source License
/** * This method is for setting the properties of watermark Image. * // w w w. j a va 2 s .c o m * @param pdfContentByte * @param pageWidth * @param pageHeight * @param watermarkBean */ private void decoratePdfWatermarkImage(PdfContentByte pdfContentByte, int pageWidth, int pageHeight, WatermarkBean watermarkBean) { PdfGState pdfGState = new PdfGState(); final float OPACITY = 0.3f; float absPosX; float absPosY; try { if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_IMAGE)) { Image watermarkImage = Image.getInstance(watermarkBean.getFileImage()); if (watermarkImage != null) { pdfGState.setFillOpacity(OPACITY); pdfContentByte.setGState(pdfGState); float height = watermarkImage.getPlainHeight(); float width = watermarkImage.getPlainWidth(); int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight)); int pivotPoint = (diagonal - (int) width) / 2; float angle = (float) Math.atan((float) pageHeight / pageWidth); absPosX = (float) (pivotPoint * pageWidth) / diagonal; absPosY = (float) (pivotPoint * pageHeight) / diagonal; watermarkImage.setAbsolutePosition(absPosX, absPosY); if ((pageWidth / 2) < width) { watermarkImage.scaleToFit(pageWidth / 2, pageHeight / 2); } else { watermarkImage.scaleToFit(width, height); } pdfContentByte.addImage(watermarkImage); } } } catch (BadElementException badElementException) { LOG.error("WatermarkDecoratorImpl Error found: " + badElementException.getMessage()); } catch (DocumentException documentException) { LOG.error("WatermarkDecoratorImpl Error found: " + documentException.getMessage()); } }
From source file:org.kuali.kra.printing.service.impl.WatermarkServiceImpl.java
License:Educational Community License
/** * This method is for setting the properties of watermark Image. * /*from ww w . j a va2 s.c o m*/ * @param pdfContentByte * @param pageWidth * @param pageHeight * @param watermarkBean */ private void decoratePdfWatermarkImage(PdfContentByte pdfContentByte, int pageWidth, int pageHeight, WatermarkBean watermarkBean) { try { if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_IMAGE)) { Image watermarkImage = Image.getInstance(watermarkBean.getFileImage()); if (watermarkImage != null) { float height = watermarkImage.getPlainHeight(); float width = watermarkImage.getPlainWidth(); watermarkImage.setAbsolutePosition((pageWidth - width) / 2, (pageHeight - height) / 2); pdfContentByte.addImage(watermarkImage); } } } catch (BadElementException badElementException) { LOG.error("WatermarkDecoratorImpl Error found: " + badElementException.getMessage()); } catch (DocumentException documentException) { LOG.error("WatermarkDecoratorImpl Error found: " + documentException.getMessage()); } }