Example usage for com.lowagie.text Image scalePercent

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

Introduction

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

Prototype

public void scalePercent(float percent) 

Source Link

Document

Scale the image to a certain percentage.

Usage

From source file:org.sigmah.server.report.renderer.itext.ItextMapRenderer.java

License:Open Source License

public void renderMap(DocWriter writer, MapElement element, Document doc) {
    try {//  w ww.  jav a 2s .c  o m
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        this.render(element, baos);

        Image image = Image.getInstance(baos.toByteArray());
        image.scalePercent(72f / 92f * 100f);

        doc.add(image);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.silverpeas.core.util.PdfUtil.java

License:Open Source License

/**
 * Add a image under or over content on each page of a PDF file.
 * @param pdfSource the source pdf file, this content is not modified by this method
 * @param imageToAdd the image file/*from   ww  w .  j  a va  2s.c o  m*/
 * @param pdfDestination the destination pdf file, with the image under or over content
 * @param isBackground indicates if image is addes under or over the content of the pdf source
 * file
 */
private static void addImageOnEachPage(InputStream pdfSource, File imageToAdd, OutputStream pdfDestination,
        final boolean isBackground) {

    // Verify given arguments
    if (imageToAdd == null || !imageToAdd.isFile()) {
        throw new SilverpeasRuntimeException("The image file doesn't exist");
    } else if (!FileUtil.isImage(imageToAdd.getPath())) {
        throw new SilverpeasRuntimeException("The picture to add is not an image file");
    }

    PdfReader reader = null;
    try {

        // Get a reader of PDF content
        reader = new PdfReader(pdfSource);

        // Obtain the total number of pages
        int pdfNbPages = reader.getNumberOfPages();
        PdfStamper stamper = new PdfStamper(reader, pdfDestination);

        // Load the image
        Image image = Image.getInstance(imageToAdd.getPath());
        float imageWidth = image.getWidth();
        float imageHeigth = image.getHeight();

        // Adding the image on each page of the PDF
        for (int i = 1; i <= pdfNbPages; i++) {

            // Page sizes
            Rectangle rectangle = reader.getPageSize(i);

            // Compute the scale of the image
            float scale = Math.min(100, (rectangle.getWidth() / imageWidth * 100));
            image.scalePercent(Math.min(scale, (rectangle.getHeight() / imageHeigth * 100)));

            // Setting the image position for the current page
            image.setAbsolutePosition(computeImageCenterPosition(rectangle.getWidth(), image.getScaledWidth()),
                    computeImageCenterPosition(rectangle.getHeight(), image.getScaledHeight()));

            // Adding image
            PdfContentByte imageContainer = isBackground ? stamper.getUnderContent(i)
                    : stamper.getOverContent(i);
            imageContainer.addImage(image);
        }

        // End of the treatment : closing the stamper
        stamper.close();

    } catch (Exception e) {
        SilverLogger.getLogger(PdfUtil.class).error(e);
        throw new SilverpeasRuntimeException(
                "A problem has occurred during the adding of an image into a pdf file", e);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:org.silverpeas.util.PdfUtil.java

License:Open Source License

/**
 * Add a image under or over content on each page of a PDF file.
 * @param pdfSource the source pdf file, this content is not modified by this method
 * @param imageToAdd the image file//from w w  w . ja va  2 s  . c o  m
 * @param pdfDestination the destination pdf file, with the image under or over content
 * @param isBackground indicates if image is addes under or over the content of the pdf source
 * file
 */
private static void addImageOnEachPage(InputStream pdfSource, File imageToAdd, OutputStream pdfDestination,
        final boolean isBackground) {

    // Verify given arguments
    if (imageToAdd == null || !imageToAdd.isFile()) {
        throw new RuntimeException("The image file doesn't exist");
    } else if (!FileUtil.isImage(imageToAdd.getPath())) {
        throw new RuntimeException("The picture to add is not an image file");
    }

    PdfReader reader = null;
    try {

        // Get a reader of PDF content
        reader = new PdfReader(pdfSource);

        // Obtain the total number of pages
        int pdfNbPages = reader.getNumberOfPages();
        PdfStamper stamper = new PdfStamper(reader, pdfDestination);

        // Load the image
        Image image = Image.getInstance(imageToAdd.getPath());
        float imageWidth = image.getWidth();
        float imageHeigth = image.getHeight();

        // Adding the image on each page of the PDF
        for (int i = 1; i <= pdfNbPages; i++) {

            // Page sizes
            Rectangle rectangle = reader.getPageSize(i);

            // Compute the scale of the image
            float scale = Math.min(100, (rectangle.getWidth() / imageWidth * 100));
            image.scalePercent(Math.min(scale, (rectangle.getHeight() / imageHeigth * 100)));

            // Setting the image position for the current page
            image.setAbsolutePosition(computeImageCenterPosition(rectangle.getWidth(), image.getScaledWidth()),
                    computeImageCenterPosition(rectangle.getHeight(), image.getScaledHeight()));

            // Adding image
            PdfContentByte imageContainer = isBackground ? stamper.getUnderContent(i)
                    : stamper.getOverContent(i);
            imageContainer.addImage(image);
        }

        // End of the treatment : closing the stamper
        stamper.close();

    } catch (Exception e) {
        SilverTrace.error("util", "PdfUtil.stamp", "EX_ERROR_PDF_ADD_WATERWARK", e);
        throw new RuntimeException("A problem has occured during the adding of an image into a pdf file", e);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

/**
 * Get PdfPTable containing the ring width data for this series
 * /*from   w  ww .j  a v a 2s  . c o m*/
 * @return PdfPTable
 * @throws DocumentException 
 * @throws IOException 
 * @throws MalformedURLException 
 */
private void getDataTable(Boolean wj) throws DocumentException, MalformedURLException, IOException {
    // THE actual table
    PdfPTable mainTable = new PdfPTable(11);
    // Cell for column headers
    PdfPCell colHeadCell = new PdfPCell();
    // Model for data
    DecadalModel model;
    // Flag to show if there are *any* ring remarks
    Boolean hasRemarks = false;

    float[] columnWidths = new float[] { 20f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f };
    mainTable.setWidths(columnWidths);
    mainTable.setWidthPercentage(100f);

    if (wj == true) {
        if (s.hasWeiserjahre() == true) {
            model = new WJTableModel(s);
            document.add(new Chunk("Weiserjahre:", subSubSectionFont));
        } else {
            return;
        }
    } else {
        model = new UnitAwareDecadalModel(s);
        document.add(new Chunk("Ring widths:", subSubSectionFont));
    }

    int rows = model.getRowCount();

    // Do column headers
    if (wj == true) {
        colHeadCell.setPhrase(new Phrase("inc/dec", tableHeaderFont));
    } else if (this.s.getTridasUnits() == null) {
        // Unitless
        colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont));
    } else {
        // Normal tridas units
        try {
            /*if(this.s.getTridasUnits().getNormalTridas().equals(NormalTridasUnit.MICROMETRES))
            {
               colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont));
            }*/

            // Use the current default display units

            colHeadCell.setPhrase(new Phrase(displayUnits.value(), tableHeaderFont));

            /*if(displayUnits.equals(NormalTridasUnit.MICROMETRES))
            {
               colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont));
            }
            else if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM))
            {
               colHeadCell.setPhrase(new Phrase("1/100th mm", tableHeaderFont));
            }
            */

        } catch (Exception e) {
            colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont));
        }
    }
    colHeadCell.setBorderWidthBottom(headerLineWidth);
    colHeadCell.setBorderWidthTop(headerLineWidth);
    colHeadCell.setBorderWidthLeft(headerLineWidth);
    colHeadCell.setBorderWidthRight(headerLineWidth);
    mainTable.addCell(colHeadCell);
    for (int i = 0; i < 10; i++) {
        colHeadCell.setPhrase(new Phrase(Integer.toString(i), tableHeaderFont));
        colHeadCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        colHeadCell.setBorderWidthBottom(headerLineWidth);
        colHeadCell.setBorderWidthTop(headerLineWidth);
        colHeadCell.setBorderWidthLeft(lineWidth);
        colHeadCell.setBorderWidthRight(lineWidth);

        if (i == 0)
            colHeadCell.setBorderWidthLeft(headerLineWidth);
        if (i == 9)
            colHeadCell.setBorderWidthRight(headerLineWidth);
        mainTable.addCell(colHeadCell);
    }

    // Loop through rows
    for (int row = 0; row < rows; row++) {
        // Loop through columns
        for (int col = 0; col < 11; col++) {
            // Mini table to hold remark icons
            PdfPTable remarksMiniTable = new PdfPTable(3);
            float[] widths = { 0.3f, 0.3f, 0.6f };
            remarksMiniTable.setWidths(widths);
            remarksMiniTable.setWidthPercentage(100);

            // Get ring value or year number for first column
            Phrase cellValuePhrase = null;
            Object value = model.getValueAt(row, col);
            if (value == null) {
                cellValuePhrase = new Phrase("");
            } else {
                /*if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/10;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }
                }
                else if(displayUnits.equals(NormalTridasUnit.FIFTIETH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/20;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.TWENTIETH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/50;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.TENTH_MM))
                {
                   try{
                   Integer val = (Integer) value;
                   val =val/100;
                   cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col));
                   } catch (Exception e){
                      cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                        
                   }               
                }
                else if(displayUnits.equals(NormalTridasUnit.MICROMETRES))
                {*/
                cellValuePhrase = new Phrase(value.toString(), getTableFont(col));
                //}
            }

            // Get any remarks and compile them into a mini table
            org.tellervo.desktop.Year year = model.getYear(row, col);
            List<TridasRemark> remarksList = null;
            remarksList = s.getRemarksForYear(year);

            // If there are remarks, cycle through them adding cells to the mini table
            if (col != 0 && remarksList.size() > 0) {
                hasRemarks = true;
                // Get icons for remarks
                int cellnum = 1;
                int remarknum = 0;
                for (TridasRemark remark : remarksList) {
                    // Keep track of which remark we are on.
                    remarknum++;
                    // String for holding remark name for debugging
                    String remstr = "?";
                    // The actual remark icon
                    Image icon = null;
                    // A table cell for the remark
                    PdfPCell remarkCell = new PdfPCell();

                    // Set default attributes for remark and value cells
                    remarkCell.setBorderWidthBottom(0);
                    remarkCell.setBorderWidthTop(0);
                    remarkCell.setBorderWidthLeft(0);
                    remarkCell.setBorderWidthRight(0);
                    remarkCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    remarkCell.setPadding(0);
                    remarkCell.setUseBorderPadding(true);

                    // A table cell for the ring width value
                    PdfPCell valueCell = new PdfPCell();
                    valueCell = remarkCell;

                    // Get actual icon (either tridas or tellervo)
                    if (remark.isSetNormalTridas()) {
                        remstr = remark.getNormalTridas().toString();
                        icon = getTridasIcon(remark.getNormalTridas());
                        if (icon == null)
                            icon = Builder.getITextImageMissingIcon();
                    } else if (TELLERVO.equals(remark.getNormalStd())) {
                        remstr = remark.getNormal();
                        icon = getCorinaIcon(remark.getNormal());
                        if (icon == null)
                            icon = Builder.getITextImageMissingIcon();
                    } else {
                        if (remark.isSetValue()) {
                            remstr = remark.getValue();
                        } else if (remark.isSetNormal()) {
                            remstr = remark.getNormal();
                        } else {
                            remstr = "Unknown";
                        }
                        icon = Builder.getITextImageIcon("user.png");

                    }

                    // Print debug info for this remark
                    String errStr = "Getting icon for " + remstr + " for year " + year.toString()
                            + "(cell value = " + cellnum + ")";
                    System.out.print(errStr);

                    // Shrink the icon a bit
                    icon.scalePercent(20);

                    // Add icon to minitable
                    remarkCell.addElement(icon);
                    remarksMiniTable.addCell(remarkCell);
                    cellnum++;

                    if (cellnum == 1 && remarksList.size() < cellnum) {
                        // First cell and no remark so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }
                    if (cellnum == 2 && remarksList.size() < cellnum) {
                        // Second cell and no remark so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }
                    if (cellnum == 3) {
                        // In third cell so print value
                        valueCell.setPhrase(cellValuePhrase);
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    } else if (cellnum % 3 == 0) {
                        // In third column so print blank
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        cellnum++;
                    }

                    if (remarknum == remarksList.size()) {
                        valueCell.setPhrase(new Phrase(""));
                        remarksMiniTable.addCell(valueCell);
                        remarksMiniTable.addCell(valueCell);
                    }

                    remarkCell = null;
                    valueCell = null;
                }
            } else {
                // No remarks so make mini table have blank, blank, value

                // Create blank and value cells
                PdfPCell blankCell = new PdfPCell();
                PdfPCell valueCell = new PdfPCell();

                // Set up style
                blankCell.setBorderWidthBottom(0);
                blankCell.setBorderWidthTop(0);
                blankCell.setBorderWidthLeft(0);
                blankCell.setBorderWidthRight(0);
                blankCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                blankCell.setPadding(0);
                blankCell.setUseBorderPadding(true);
                valueCell = blankCell;

                // Add cells to mini table
                remarksMiniTable.addCell(blankCell);
                remarksMiniTable.addCell(blankCell);
                valueCell.setPhrase(cellValuePhrase);
                remarksMiniTable.addCell(valueCell);
            }

            // Set border styles depending on where we are in the table

            // Defaults
            PdfPCell mainTableCell = new PdfPCell();
            mainTableCell.setBorderWidthBottom(lineWidth);
            mainTableCell.setBorderWidthTop(lineWidth);
            mainTableCell.setBorderWidthLeft(lineWidth);
            mainTableCell.setBorderWidthRight(lineWidth);
            mainTableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

            // Row headers
            if (col == 0) {
                mainTableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
                mainTableCell.setBorderWidthLeft(headerLineWidth);
                mainTableCell.setBorderWidthRight(headerLineWidth);
            }

            // First data column
            if (col == 1) {
                mainTableCell.setBorderWidthLeft(headerLineWidth);
            }

            // Last data column
            if (col == 10) {
                mainTableCell.setBorderWidthRight(headerLineWidth);
            }

            // Last row
            if (row == model.getRowCount() - 1) {
                mainTableCell.setBorderWidthBottom(headerLineWidth);
            }

            // Write mini table to cell       
            mainTableCell.addElement(remarksMiniTable);

            //mainTableCell.addElement(userRemarksMiniTable);

            // Write cell to main table
            mainTable.addCell(mainTableCell);

        }
    }

    // Add table to document
    document.add(mainTable);

    if (!wj && hasRemarks)
        getTableKey();
}

From source file:org.viafirma.util.QRCodeUtil.java

License:Apache License

/**
 * @param texto/*from   w w  w .  j a  v  a 2  s  .co  m*/
 *            Texto a colocar
 * @param textoQR
 *            Imagen QR a colocar
 * @param codFirma
 *            Cdigo de Firma a generar.
 * @param url Url del servicio de verificacin desde donde se puede descargar el documento.
 * @param document
 *            Documeto destino
 * @param pageSize
 *            Tamao de la pgina
 * @return 
 * @throws BadElementException
 * @throws MalformedURLException
 * @throws IOException
 * @throws DocumentException
 * @throws ExcepcionErrorInterno
 */
private static float addContent(String texto, String url, String textoQR, String codFirma, Document document,
        Rectangle pageSize, boolean completo, boolean isSellado) throws BadElementException,
        MalformedURLException, IOException, DocumentException, ExcepcionErrorInterno {

    Image imagenCabezera = null;
    float widthCabecera = 0;
    float heightCabecera = 0;
    if (!isSellado) {
        // Recuperamos la imagen de cabecera
        imagenCabezera = Image.getInstance(QRCodeUtil.class.getResource(IMAGE_CABECERA));
        // Colocamos la imagen en la zona superior de la pgina
        imagenCabezera.setAbsolutePosition(0, pageSize.getHeight() - imagenCabezera.getHeight());
        heightCabecera = imagenCabezera.getHeight();
        widthCabecera = imagenCabezera.getWidth();
    }

    // Recuperamos el pie de firma
    Image imagenQR = Image.getInstance(QRCodeUtil.getInstance().generate(texto, url, textoQR, codFirma));

    float rescalado = pageSize.getWidth() / (widthCabecera + document.leftMargin() + document.rightMargin());
    float sizeCabecera = 0;
    if (rescalado < 1f && !isSellado) {
        // Requiere rescalado, la imagen es mayor que la pgina.
        imagenCabezera.scalePercent(rescalado * 100);
        sizeCabecera = rescalado * imagenCabezera.getHeight();
    }

    float sizeCabecerayPie = HEIGHT_QR_CODE_PDF + sizeCabecera + document.bottomMargin() + document.topMargin()
            + SPACE_SEPARACION;
    // float escaleQR = HEIGHT_QR_CODE_PDF / (imagenQR.getHeight() + 5);
    float escaleQR = (pageSize.getWidth() - document.leftMargin() - document.rightMargin())
            / (imagenQR.getWidth() + 6);

    // imagen.setSpacingAfter(120);
    if (!isSellado) {
        document.add(imagenCabezera);
    }
    // Aadimos una caja de texto si estamos mostrando el contenido del
    // fichero firmado.
    if (completo) {
        // Aadimos el espacio ocupado por la imagen
        Paragraph p = new Paragraph("");
        p.setSpacingAfter(heightCabecera * rescalado);
        document.add(p);

        // Aadimos una tabla con borde donde colocar el documento.
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorderWidth(10);
        PdfPCell celda = new PdfPCell();
        celda.setFixedHeight(pageSize.getHeight() - sizeCabecerayPie);
        table.addCell(celda);
        table.setSpacingAfter(SPACE_SEPARACION);
        document.add(table);
    }

    if (completo) {
        // La imagen la colocamos justo debajo
        imagenQR.setAbsolutePosition(document.leftMargin(),
                escaleQR * HEIGHT_QR_CODE_PDF - SPACE_SEPARACION * 2);
    } else {
        imagenQR.setAbsolutePosition(document.leftMargin(), pageSize.getHeight() - sizeCabecerayPie);
    }
    imagenQR.scalePercent(escaleQR * 100);
    document.add(imagenQR);

    return sizeCabecerayPie;
}

From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

private PdfPTable createLogoHeader() {
    float[] tableWidths;
    PdfPCell cell = new PdfPCell();
    //tableWidths = new float[]{ 1.5f, 2.5f };
    //PdfPTable infoTable = new PdfPTable(tableWidths);
    PdfPTable infoTable = new PdfPTable(1);
    try {//from  w  ww  .j av a 2s .  com
        String filename = "";
        if (props.getProperty("multisites") != null && "on".equalsIgnoreCase(props.getProperty("multisites"))) {
            DocumentDAO documentDao = (DocumentDAO) SpringUtils.getBean("documentDAO");
            SiteDao siteDao = (SiteDao) SpringUtils.getBean("siteDao");
            Site site = siteDao.getByLocation(reqFrm.siteName);
            if (site != null) {
                if (site.getSiteLogoId() != null) {
                    org.oscarehr.document.model.Document d = documentDao
                            .getDocument(String.valueOf(site.getSiteLogoId()));
                    String dir = props.getProperty("DOCUMENT_DIR");
                    filename = dir.concat(d.getDocfilename());
                } else {
                    //If no logo file uploaded for this site, use the default one defined in oscar properties file.
                    filename = props.getProperty("faxLogoInConsultation");
                }
            }
        } else {
            filename = props.getProperty("faxLogoInConsultation");
        }

        FileInputStream fileInputStream = new FileInputStream(filename);
        byte[] faxLogImage = new byte[1024 * 256];
        fileInputStream.read(faxLogImage);
        Image image = Image.getInstance(faxLogImage);
        image.scalePercent(80f);
        image.setBorder(0);
        cell = new PdfPCell(image);
        cell.setBorder(0);
        infoTable.addCell(cell);
    } catch (Exception e) {
        logger.error("Unexpected error.", e);
    }

    // The last cell in the table is extended to the maximum available height;
    // inserting a blank cell here prevents the last border used to underline text from
    // being displaced to the bottom of this table.
    cell.setPhrase(new Phrase(" ", font));
    cell.setBorder(0);
    cell.setColspan(2);
    infoTable.addCell(cell);
    return infoTable;

}

From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

private void addSignature(PdfPTable infoTable) {
    float[] tableWidths;
    PdfPCell cell;//from   ww w . j a  va 2 s.  co m
    tableWidths = new float[] { 0.55f, 2.75f };
    PdfPTable table = new PdfPTable(tableWidths);
    cell = new PdfPCell(new Phrase(getResource("msgSignature") + ":", infoFont));
    cell.setBorder(0);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_BOTTOM);
    table.addCell(cell);
    try {
        DigitalSignatureDao digitalSignatureDao = (DigitalSignatureDao) SpringUtils
                .getBean("digitalSignatureDao");
        DigitalSignature digitalSignature = digitalSignatureDao.find(Integer.parseInt(reqFrm.signatureImg));
        if (digitalSignature != null) {
            Image image = Image.getInstance(digitalSignature.getSignatureImage());
            image.scalePercent(80f);
            image.setBorder(0);
            cell = new PdfPCell(image);
            cell.setBorder(0);
            table.addCell(cell);
            cell = new PdfPCell(table);
            cell.setBorder(0);
            cell.setPadding(0);
            cell.setColspan(1);
            infoTable.addCell(cell);

            return;
        }
    } catch (Exception e) {
        logger.error("Unexpected error.", e);
    }
}

From source file:permit.InvoicePdf.java

License:Open Source License

/**
 * handles the letter header//from  ww  w  .  j a  v a  2  s.c  om
 */
PdfPTable getHeader() {
    //
    String str = "";
    String spacer = "   ";
    PdfPTable headTable = null;
    try {
        //
        // for http url use
        //
        Image image = Image.getInstance(url + "js/images/city_logo3.jpg");
        Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
        float[] widths = { 25f, 40f, 35f }; // percentages
        headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        image.scalePercent(15f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        headTable.addCell(cell);
        //
        float[] width = { 33f };
        PdfPTable midTable = new PdfPTable(width);
        midTable.setWidthPercentage(33);
        midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("City of Bloomington ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Planning and Transportation Department ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("bloomington.in.gov", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        headTable.addCell(midTable);
        //
        PdfPTable rightTable = new PdfPTable(width);
        rightTable.setWidthPercentage(33);
        rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        phrase = new Phrase();
        ch = new Chunk("401 N Morton St Suite 130 ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov",
                fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        headTable.addCell(rightTable);
    } catch (Exception ex) {
        logger.error(ex);
    }
    return headTable;
}

From source file:permit.PermitPdf.java

License:Open Source License

/**
 * handles the letter header// w  w w .  j  a  v a2s . c o m
 */
PdfPTable getHeader() {
    //
    String str = "";
    String spacer = "   ";
    //
    PdfPTable headTable = null;
    try {
        //
        // for http url use
        //
        Image image = Image.getInstance(url + "js/images/city_logo3.jpg");

        Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
        float[] widths = { 25f, 40f, 35f }; // percentages
        headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        // image.setWidthPercentage(33.0f);
        image.scalePercent(15f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        headTable.addCell(cell);
        //
        float[] width = { 33f };
        PdfPTable midTable = new PdfPTable(width);
        midTable.setWidthPercentage(33);
        midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("City of Bloomington ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Planning and Transportation Department ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("bloomington.in.gov", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        midTable.addCell(cell);
        //
        headTable.addCell(midTable);
        //
        PdfPTable rightTable = new PdfPTable(width);
        rightTable.setWidthPercentage(33);
        rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        phrase = new Phrase();
        ch = new Chunk("401 N Morton St Suite 130 ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov",
                fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        rightTable.addCell(cell);
        headTable.addCell(rightTable);
    } catch (Exception ex) {
        logger.error(ex);
    }
    return headTable;
}

From source file:ppro.contoller.ExportController.java

private Image getImage(String imageName) throws IOException, BadElementException {
    final Image image = Image.getInstance(getAbsolutePath(imageName));
    image.scalePercent(90f);
    return image;
}