Example usage for com.lowagie.text Image getInstance

List of usage examples for com.lowagie.text Image getInstance

Introduction

In this page you can find the example usage for com.lowagie.text Image getInstance.

Prototype

public static Image getInstance(Image image) 

Source Link

Document

gets an instance of an Image

Usage

From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java

License:Open Source License

/**
 * Method declaration//from  w  ww.j  a  v a  2s  .c o m
 * @param section
 * @param complete
 * @see
 */
public static void addPublication(Section section, CompletePublication complete) {
    Font publicationFont = new Font(Font.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));

    try {
        Paragraph pub = new Paragraph(complete.getPublicationDetail().getName(), publicationFont);
        Section subsection = section.addSection(pub, 0);

        if (complete.getPublicationDetail().getDescription() != null) {
            subsection.add(new Paragraph(complete.getPublicationDetail().getDescription()));
        }
        if ((complete.getInfoDetail() != null) && (complete.getModelDetail() != null)) {
            String toParse = complete.getModelDetail().getHtmlDisplayer();

            Iterator<InfoTextDetail> textIterator = complete.getInfoDetail().getInfoTextList().iterator();
            Iterator<InfoImageDetail> imageIterator = complete.getInfoDetail().getInfoImageList().iterator();

            int posit = toParse.indexOf("%WA");
            InfoTextDetail textDetail = null;
            Paragraph text = null;
            InfoImageDetail imageDetail = null;
            Image img = null;

            while (posit != -1) {
                if (posit > 0) {
                    toParse = toParse.substring(posit);
                }
                if (toParse.startsWith("%WATXTDATA%")) {
                    if (textIterator.hasNext()) {
                        textDetail = textIterator.next();
                        text = new Paragraph(textDetail.getContent());

                        subsection.add(text);
                    }
                    toParse = toParse.substring(11);
                } else if (toParse.startsWith("%WAIMGDATA%")) {
                    if (imageIterator.hasNext()) {
                        imageDetail = imageIterator.next();
                        String imagePath = FileRepositoryManager
                                .getAbsolutePath(imageDetail.getPK().getComponentName()) + getImagePath()
                                + File.separator + imageDetail.getPhysicalName();
                        SilverTrace.info("NewsEdito", "PDFGenerator.addPublication", "root.MSG_PARAM_VALUE",
                                "imagePath = " + imagePath);
                        img = Image.getInstance(imagePath);

                        subsection.add(img);
                    }
                    toParse = toParse.substring(11);
                }

                // et on recommence
                posit = toParse.indexOf("%WA");
            }
        }

    } catch (Exception e) {
        SilverTrace.warn("NewsEdito", "PdfGenerator.addPublication", "NewsEdito.EX_NO_PUBLI_ADDED");
    }
}

From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java

License:Open Source License

/**
 * Method declaration//  w  w  w . j  a  v  a2s .  c  om
 * @param document
 * @param archiveDetail
 * @param publicationBm
 * @param langue
 * @see
 */
public static void addEditorial(Document document, NodeDetail archiveDetail, PublicationBm publicationBm,
        String langue) throws NewsEditoException {

    SilverTrace.info("NewsEdito", "PdfGenerator.addEditorial", "NewsEdito.MSG_ENTRY_METHOD");

    try {
        ResourceLocator message = new ResourceLocator(
                "com.stratelia.webactiv.newsEdito.multilang.newsEditoBundle", langue);
        Collection<PublicationDetail> pubList = publicationBm.getDetailsByFatherPK(archiveDetail.getNodePK());
        Iterator<PublicationDetail> i = pubList.iterator();

        if (i.hasNext()) {
            try {

                Font publicationFont = new Font(Font.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));
                Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255));

                Paragraph cTitle = new Paragraph(message.getString("editorial"), titleFont);
                Chapter chapter = new Chapter(cTitle, 0);

                chapter.setNumberDepth(0);

                PublicationDetail detail = null;
                Paragraph name = null;
                Section subsection = null;
                Image img = null;
                while (i.hasNext()) {

                    detail = i.next();
                    name = new Paragraph(detail.getName(), publicationFont);
                    subsection = chapter.addSection(name, 0);

                    subsection.setNumberDepth(0);

                    if (detail.getDescription() != null) {
                        subsection.add(new Paragraph(detail.getDescription()));

                    }
                    if (detail.getImage() != null) {

                        String imagePath = FileRepositoryManager
                                .getAbsolutePath(detail.getPK().getComponentName()) + getImagePath()
                                + File.separator + detail.getImage();
                        try {
                            SilverTrace.info("NewsEdito", "PDFGenerator.addEditorial", "root.MSG_PARAM_VALUE",
                                    "imagePath = " + imagePath);
                            img = Image.getInstance(imagePath);
                        } catch (Exception e) {
                            SilverTrace.info("NewsEdito", "PDFGenerator.addEditorial",
                                    "NewsEdito.MSG_CANNOT_RETRIEVE_IMAGE", "imagePath = " + imagePath);
                        }
                        if (img == null) {
                            SilverTrace.info("NewsEdito", "PdfGenerator.addEditorial",
                                    "NewsEdito.MSG_CANNOT_RETRIEVE_IMAGE");
                        } else {
                            subsection.add(img);
                        }
                    }
                }
                document.add(chapter);

            } catch (DocumentException de) {
                SilverTrace.warn("NewsEdito", "PdfGenerator.addEditorial", "NewsEdito.EX_NO_EDITO_ADDED");
            }

        }
    } catch (Exception e) {
        throw new NewsEditoException("PdfGenerator.addEditorial", NewsEditoException.WARNING,
                "NewsEdito.EX_PROBLEM_TO_ADD_EDITO", e);
    }

}

From source file:com.toolkit.util.pdf.HomeITextUserAgent.java

License:Open Source License

/**
 * Implementation Routine getImageResource.
 * @param uri String/*from  www .  j  a va2 s .c  o  m*/
 * @return ImageResource
 * @see org.xhtmlrenderer.extend.UserAgentCallback#getImageResource(String)
 */
public ImageResource getImageResource(String uri) {

    ImageResource resource = null;
    uri = resolveURI(uri);
    resource = (ImageResource) _imageCache.get(uri);

    if (resource == null) {
        InputStream is = resolveAndOpenStream(uri);
        if (is != null) {
            try {
                URL url = new URL(uri);
                if (url.getPath() != null && url.getPath().toLowerCase().endsWith(".pdf")) {

                    PdfReader reader = _outputDevice.getReader(url);
                    PDFAsImage image = new PDFAsImage(url);
                    Rectangle rect = reader.getPageSizeWithRotation(1);
                    image.setInitialWidth(rect.width() * _outputDevice.getDotsPerPoint());
                    image.setInitialHeight(rect.height() * _outputDevice.getDotsPerPoint());
                    resource = new ImageResource(image);
                } else {
                    Image image = Image.getInstance(url);
                    scaleToOutputResolution(image);
                    resource = new ImageResource(new ITextFSImage(image));
                }
                _imageCache.put(uri, resource);

            } catch (IOException e) {
                XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", e);
            } catch (BadElementException e) {
                XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", e);
            }
        }
    }
    if (resource == null) {
        resource = new ImageResource(null);
    }
    return resource;
}

From source file:com.util.tools.FeraExporter.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//w  w  w  .  j a  va2  s .  com
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "Fera_Icon.png";

    pdf.add(Image.getInstance(logo));
}

From source file:controllers.PdfUserAgent.java

@Override
public ImageResource getImageResource(String uri) {
    Option<InputStream> option = Play.current().resourceAsStream(uri);
    if (option.isDefined()) {
        InputStream stream = option.get();
        try {/*from w ww  .  j av  a 2  s  .co m*/
            Image image = Image.getInstance(getData(stream));
            scaleToOutputResolution(image);
            return new ImageResource(uri, new ITextFSImage(image));
        } catch (Exception e) {
            Logger.error("fetching image " + uri, e);
            throw new RuntimeException(e);
        }
    } else {
        return super.getImageResource(uri);
    }
}

From source file:corner.orm.tapestry.pdf.components.PdfImage.java

License:Apache License

/**
 * @see corner.orm.tapestry.pdf.components.AbstractPdfComponent#renderPdf(corner.orm.tapestry.pdf.PdfWriterDelegate, com.lowagie.text.Document)
 *///from  w ww .  j  a v a  2s.co  m
@Override
public void renderPdf(PdfWriterDelegate writer, Document doc) {
    Defense.notNull(getRectangle(), "TextField?");
    String[] p = getRectangle().split(",");
    try {
        Image image = Image.getInstance(getValue());
        image.setAbsolutePosition(Float.valueOf(p[0]), Float.valueOf(p[1]));// ?
        if (getAutoSize()) {
            if (Constants.PDFIMAGE_COMPONENT_SCALE_TYPE_BORDER.equals(getScaleType())) {
                image.scaleAbsolute((Float.valueOf(p[2]) - Float.valueOf(p[0])),
                        (Float.valueOf(p[3]) - Float.valueOf(p[1])));// ?
            } else {
                float picHeight = image.plainHeight();// 
                float picWeight = image.plainWidth();// 
                float borderHeight = Float.valueOf(p[3]) - Float.valueOf(p[1]);// 
                float borderWeight = Float.valueOf(p[2]) - Float.valueOf(p[0]);// 

                float heightPer = borderHeight / picHeight * 100;
                float widthPer = borderWeight / picWeight * 100;

                // ????
                if (heightPer > widthPer) {
                    image.scalePercent(widthPer);
                } else {
                    image.scalePercent(heightPer);
                }
            }
        }
        doc.add(image);
    } catch (BadElementException e) {
        throw new CornerSystemException(e);
    } catch (MalformedURLException e) {
        throw new CornerSystemException(e);
    } catch (IOException e) {
        throw new CornerSystemException(e);
    } catch (DocumentException e) {
        throw new CornerSystemException(e);
    }
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarImagenCabecera(Paragraph imagen) {

    try {//ww w.  jav a 2  s . com
        Image im;
        im = Image.getInstance("src/Imagenes/arriba.png");
        im.setAlignment(Image.ALIGN_CENTER | Image.TEXTWRAP);
        imagen.add(im);
    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarImagenLogo(Paragraph imagen) throws BadElementException {
    try {// w  ww . j av  a2s . c  o m
        Image im = Image.getInstance("src/Imagenes/todo Lonas.png");
        im.setAlignment(Image.ALIGN_LEFT | Image.TEXTWRAP);
        imagen.add(im);
    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarImagenFirma(Paragraph imagen) throws BadElementException {
    try {/*from w  w  w.  j  av  a  2s . com*/
        Image im = Image.getInstance("src/Imagenes/firma3.png");
        im.setAlignment(Image.ALIGN_CENTER | Image.TEXTWRAP);
        imagen.add(im);
        //            agregarLineasEnBlanco(parrafoNormal, 3);

    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarImagenPie(Paragraph imagen) throws BadElementException {
    try {/*w  ww .jav a 2s  .  c om*/
        Image im = Image.getInstance("src/Imagenes/abajo.png");
        im.setAbsolutePosition(0, 0);
        im.setAlignment(Image.ALIGN_CENTER);
        im.scalePercent(60f);
        imagen.add(im);

    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}