Example usage for com.lowagie.text.pdf PdfTemplate addImage

List of usage examples for com.lowagie.text.pdf PdfTemplate addImage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfTemplate addImage.

Prototype

public void addImage(Image image, float a, float b, float c, float d, float e, float f)
        throws DocumentException 

Source Link

Document

Adds an Image to the page.

Usage

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private PdfTemplate createPasswordLetterTemplate(PdfWriter writer) throws Exception {
    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
    PdfContentByte cb = writer.getDirectContent();

    float tempLength = 511f;
    float tempHeight = getPointsFromMM(40);
    PdfTemplate template = cb.createTemplate(tempLength, tempHeight);

    if (addTemplateHeader()) {
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        String mail_zip = iwb.getProperty("commune.mail_zip");
        String mail_name = iwb.getProperty("commune.mail_name");

        float convLengt = 100f;
        float convHeight = 60f;
        template.rectangle(0f, 0f, convLengt, convHeight);
        template.moveTo(0f, 0f);//from  w  ww  .  ja va  2s.com
        template.lineTo(convLengt, convHeight);
        template.moveTo(convLengt, 0f);
        template.lineTo(0f, convHeight);
        template.stroke();
        template.beginText();
        template.setFontAndSize(bf, 11f);
        template.setTextMatrix(5f, 40f);
        template.showText(mail_name);

        template.endText();
        template.beginText();
        template.setFontAndSize(bf, 11f);
        template.setTextMatrix(5f, 25f);
        template.showText(mail_zip);
        template.endText();

        Image porto = Image.getInstance(iwb.getResourcesRealPath() + "/shared/porto_betalt.jpg");
        porto.scaleAbsolute(60f, 60f);

        // Image portoA =Image.getInstance(iwb.getResourcesRealPath()+
        // "/shared/porto_a_logo.jpg");
        // float Awidth = 2.3f*60f;
        // portoA.scaleToFit(Awidth,60f);

        float portoXPos = tempLength - 90f;
        // float portoAXPos = portoXPos-Awidth-5f;
        template.addImage(porto, 60f, 0f, 0f, 60f, portoXPos, 0);
        // template.addImage(portoA,Awidth,0f,0f,60f,portoAXPos,0);
    }

    return template;
}

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 w  w w .java2  s.  c om
    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.emitter.pdf.PDFPage.java

License:Open Source License

protected void drawImage(String imageId, byte[] imageData, String extension, float imageX, float imageY,
        float height, float width, String helpText, Map params) throws Exception {
    // Flash//from ww w .  ja  va  2 s . c  om
    if (FlashFile.isFlash(null, null, extension)) {
        embedFlash(null, imageData, imageX, imageY, height, width, helpText, params);
        return;
    }

    // Cached Image
    PdfTemplate template = null;
    if (imageId != null) {
        if (pageDevice.getImageCache().containsKey(imageId)) {
            template = pageDevice.getImageCache().get(imageId);
        }
        if (template != null) {
            drawImage(template, imageX, imageY, height, width, helpText);
            return;
        }
    }

    // Not cached yet
    if (SvgFile.isSvg(null, null, extension)) {
        template = generateTemplateFromSVG(null, imageData, imageX, imageY, height, width, helpText);
    } else {
        // PNG/JPG/BMP... images:
        Image image = Image.getInstance(imageData);
        if (imageId == null) {
            // image without imageId, not able to cache.
            drawImage(image, imageX, imageY, height, width, helpText);
            return;
        }
        template = contentByte.createTemplate(width, height);
        template.addImage(image, width, 0, 0, height, 0, 0);
    }
    // Cache the image
    if (imageId != null && template != null) {
        pageDevice.getImageCache().put(imageId, template);
    }
    if (template != null) {
        drawImage(template, imageX, imageY, height, width, helpText);
    }
}

From source file:org.oss.pdfreporter.pdf.Page.java

License:Open Source License

@Override
public void draw(IImage image, float x, float y, float width, float height, ScaleMode mode)
        throws DocumentException {
    try {/*from  w  w w . j av  a 2  s  .c  o m*/
        Image pdfImage = null;
        switch (mode) {
        case NONE:
            pdfImage = getImage(image);
            PdfTemplate t = delegate.getPdfWriter().getDirectContent().createTemplate(width, height);
            t.addImage(pdfImage, pdfImage.getWidth(), 0, 0, pdfImage.getHeight(), 0,
                    height - pdfImage.getHeight());
            pdfImage = Image.getInstance(t);
            break;
        case SCALE:
            pdfImage = getImage(image);
            pdfImage.scaleAbsolute(width, height);
            break;
        case SIZE:
            pdfImage = getImage(image);
            pdfImage.scaleToFit(width, height);
            break;
        }
        pdfImage.setAbsolutePosition(x, y);
        delegate.addImage(pdfImage);
    } catch (Exception e) {
        throw new DocumentException(e);
    }

}

From source file:org.oss.pdfreporter.pdf.Page.java

License:Open Source License

@Override
public void drawCropped(IImage image, float xoffset, float yoffset, float x, float y, float width, float height)
        throws DocumentException {
    try {/*from  ww w  . ja  v  a  2 s . co m*/

        Image pdfImage = getImage(image);
        PdfTemplate t = delegate.getPdfWriter().getDirectContent().createTemplate(width, height);
        t.addImage(pdfImage, pdfImage.getWidth(), 0, 0, pdfImage.getHeight(), xoffset,
                -yoffset + height - pdfImage.getHeight());
        pdfImage = Image.getInstance(t);

        pdfImage.setAbsolutePosition(x, y);
        delegate.addImage(pdfImage);
    } catch (Exception e) {
        throw new DocumentException(e);
    }
}

From source file:questions.images.CustomizedTitleBar.java

public static Image getTitleBar(PdfWriter writer, Image background, String title)
        throws DocumentException, IOException {
    float width = background.getWidth();
    float height = background.getHeight();
    PdfTemplate tmp = writer.getDirectContent().createTemplate(width, height);
    tmp.addImage(background, width, 0, 0, height, 0, 0);
    BaseFont font = BaseFont.createFont();
    tmp.beginText();/*  ww w . ja  v a  2  s .c o  m*/
    tmp.setGrayFill(1);
    tmp.setFontAndSize(font, 18);
    tmp.showTextAligned(Element.ALIGN_CENTER, title, width / 2, 4, 0);
    tmp.endText();
    return Image.getInstance(tmp);
}

From source file:storemanagment.Printing.java

public PdfPCell createImageCellCrip(String path, PdfWriter writer) throws IOException, DocumentException {
    PdfPCell cell = null;/*from  w  w  w.  j a v a2  s.com*/
    try {
        Image img = Image.getInstance(path);
        float w = img.getScaledWidth();
        float h = img.getScaledHeight();

        PdfTemplate t = writer.getDirectContent().createTemplate(w, h);
        t.ellipse(0, 0, w, h);
        t.newPath();
        t.addImage(img, w, 0, 0, h, 0, -600);
        Image clipped = Image.getInstance(t);
        cell = new PdfPCell(clipped, true);
        // cell.setFixedHeight(30);
        // cell.setBorder(Rectangle.NO_BORDER);
        //cell.setBorder(R);
        cell.setPaddingTop(10);

    } catch (BadElementException ex) {
        Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
    } catch (MalformedURLException ex) {
        Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
    }

    return cell;
}