Example usage for com.itextpdf.text.pdf PdfPTable setWidthPercentage

List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setWidthPercentage.

Prototype

public void setWidthPercentage(final float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createSignature(Document doc) throws DocumentException {

    Calendar currDate = Calendar.getInstance();

    StringBuilder sbSignature = new StringBuilder().append(company.getCity()).append(", ")
            .append(DateUtils.getDay(currDate.getTime())).append(" de ")
            .append(DateUtils.getMonthName(currDate)).append(" de ")
            .append(DateUtils.getYear(currDate.getTime()));

    StringBuilder sbUser = new StringBuilder().append("P.P_________________________________________________ \n")
            .append("Nome: ").append(company.getUserResponsable().getName()).append("\n")
            .append("RG: " + company.getUserResponsable().getRg());

    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);
    table.setHeaderRows(0);//from   w w  w  .ja v a  2  s. c o  m
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    insertCell(table, sbSignature.toString(), Element.ALIGN_LEFT, fontHeaderTable, false);
    insertCell(table, sbUser.toString(), Element.ALIGN_LEFT, fontHeaderTable, false);

    doc.add(Chunk.NEWLINE);
    doc.add(table);
}

From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createParagraph(Document doc) throws DocumentException {

    float[] columnWidths = { 2f, 2f };
    PdfPTable table = new PdfPTable(columnWidths);
    table.setWidthPercentage(100f);

    StringBuilder sbHeader = new StringBuilder()
            .append("SECRETARIA DE ESTADO DOS NEGCIOS DA SEGURANA PBLICA \n")
            .append("POL?CIA CIVIL DO ESTADO DE ").append(company.getState()).append("\n")
            .append("DEPARTAMENTO DE IDENTIFICAO E REGISTROS DIVERSOS \n")
            .append("DIVISO DE PRODUTOS CONTROLADOS \n");

    StringBuilder sbHeaderMonth = new StringBuilder().append("MAPA TRIMESTRAL DEMONSTRATIVO DO ESTOQUE \n")
            .append("DE COMPRAS, VENDAS E CONSUMO \n").append("REFERENTE AO ")
            .append(mapProduct.getNumTrimester()).append(" TRIMESTRE DO ANO DE ").append(mapProduct.getYear())
            .append(".");

    StringBuilder sbCompany = new StringBuilder().append("Empresa: ").append(company.getName().toUpperCase())
            .append(" estabelecida  ").append(company.getStreet().toUpperCase()).append(" Cidade: ")
            .append(company.getCity()).append(", Estado: ").append(company.getState()).append(", CEP: ")
            .append(company.getCep()).append(", Fone: (").append(company.getUserResponsable().getPhoneDDD())
            .append(") ").append(company.getUserResponsable().getPhoneNumber()).append(", Fax: (")
            .append(company.getUserResponsable().getPhoneDDD()).append(") ")
            .append(company.getUserResponsable().getNumFax());

    // insert column headings
    insertCell(table, sbHeader.toString(), Element.ALIGN_LEFT, fontParagraph);
    insertCell(table, sbHeaderMonth.toString(), Element.ALIGN_LEFT, fontText);

    Paragraph paragraphText = new Paragraph(sbCompany.toString());
    paragraphText.setFont(fontHeaderTable);

    doc.add(Chunk.NEWLINE);//from   w  w  w.ja  v a 2  s  .  c o m
    doc.add(table);
    doc.add(Chunk.NEWLINE);
    doc.add(paragraphText);
    doc.add(Chunk.NEWLINE);
}

From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createProductsTable(Document doc) throws DocumentException {

    DecimalFormat dc = new DecimalFormat("########0.00");

    // specify column widths
    float[] columnWidths = { 2f, 2f, 2f, 2f, 2f, 2.5f };
    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    // set table width a percentage of the page width
    table.setWidthPercentage(100f);

    // insert column headings
    insertCell(table, "PRODUTO", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "SALDO DO TRIMESTRE ANTERIOR", Element.ALIGN_CENTER, fontHeaderTableSmall);
    insertCell(table, "COMPRAS", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "VENDAS", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "CONSUMO", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "ESTOQUE PARA O TRIMESTRE SEGUINTE", Element.ALIGN_CENTER, fontHeaderTableSmall);

    table.setHeaderRows(1);/*from   ww w .  j  a va 2 s  .co m*/

    for (InvoiceInventoryMapEntity productMap : listProductMapVO) {

        BigDecimal qtdNextPeriod = productMap.getQtdInventoryPreviusTrimester()
                .add(productMap.getQtdBuyProduct()).subtract(productMap.getQtdSellProduct())
                .subtract(productMap.getQtdUtilization());

        // Cria a tabela com os Produtos
        insertCell(table, productMap.getProduct().getName(), Element.ALIGN_CENTER, fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdInventoryPreviusTrimester()), Element.ALIGN_CENTER,
                fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdBuyProduct()), Element.ALIGN_CENTER, fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdSellProduct()), Element.ALIGN_CENTER,
                fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdUtilization()), Element.ALIGN_CENTER,
                fontHeaderTableSmall);
        insertCell(table, dc.format(qtdNextPeriod), Element.ALIGN_CENTER, fontHeaderTableSmall);
    }

    doc.add(table);
}

From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createInvoiceTable(Document doc) throws DocumentException {

    doc.add(Chunk.NEWLINE);/*from   w  ww. j a v  a 2 s.c  o m*/

    // Ajusta o cabealho
    float[] columnHeader = { 1f };
    PdfPTable tableHeader = new PdfPTable(columnHeader);
    tableHeader.setWidthPercentage(100f);
    insertCell(tableHeader, "\n RELAO DE COMPRAS DURANTE  O TRIMESTRE \n", Element.ALIGN_CENTER, fontText);

    doc.add(tableHeader);

    doc.add(Chunk.NEWLINE);

    // specify column widths
    float[] columnWidths = { 2f, 2f, 2f, 2f, 2f, 2f, 2.5f, 2f };
    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    // set table width a percentage of the page width
    table.setWidthPercentage(100f);

    // insert column headings
    insertCell(table, "Data:", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "Empresa Vendedora", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "Endereo", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "Cidade/UF", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "CEP", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "N. nota Fiscal", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "Produto", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "Quantidade", Element.ALIGN_CENTER, fontHeaderTable);

    table.setHeaderRows(1);

    for (InvoiceProductEntity invoiceProduct : this.listInvoices) {
        insertCell(table, DateUtils.format(invoiceProduct.getInvoice().getDateCreate()), Element.ALIGN_CENTER,
                fontHeaderTable);
        insertCell(table, invoiceProduct.getInvoice().getProvider().getCnpj(), Element.ALIGN_CENTER,
                fontHeaderTable);
        insertCell(table, invoiceProduct.getInvoice().getProvider().getStreet(), Element.ALIGN_CENTER,
                fontHeaderTable);
        insertCell(table, invoiceProduct.getInvoice().getProvider().getCity(), Element.ALIGN_CENTER,
                fontHeaderTable);
        insertCell(table, invoiceProduct.getInvoice().getProvider().getCep(), Element.ALIGN_CENTER,
                fontHeaderTable);
        insertCell(table, invoiceProduct.getInvoice().getNumInvoice(), Element.ALIGN_CENTER, fontHeaderTable);
        insertCell(table, invoiceProduct.getProduct().getProductOfficial().getName(), Element.ALIGN_CENTER,
                fontHeaderTable);
        insertCell(table, invoiceProduct.getQtdProduct() + invoiceProduct.getTypeQtdProduct(),
                Element.ALIGN_CENTER, fontHeaderTable);
    }

    doc.add(table);
}

From source file:com.solidmaps.webapp.report.MapExercitoPdfGenerator.java

License:Open Source License

private void createFooter(Document doc) throws DocumentException {

    Calendar cal = Calendar.getInstance();
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);

    table.setHeaderRows(0);//  w ww  .  java 2  s  .c  o m

    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    StringBuilder sbData = new StringBuilder();
    sbData.append(company.getCity()).append(" / ").append(company.getState()).append(", ")
            .append(cal.get(Calendar.DAY_OF_MONTH)).append(" de ").append(DateUtils.getMonthName(cal))
            .append(" de ").append(cal.get(Calendar.YEAR)).append("\n\n");

    insertCell(table, sbData.toString(), Element.ALIGN_RIGHT, fontHeaderTableBig, false);

    insertCell(table, "_________________________________________________ \n Nome: "
            + company.getUserResponsable().getName() + " \n Cargo: " + company.getUserResponsable().getOffice(),
            Element.ALIGN_RIGHT, fontHeaderTable, false);

    doc.add(Chunk.NEWLINE);

    doc.add(table);
}

From source file:com.solidmaps.webapp.report.MapExercitoPdfGenerator.java

License:Open Source License

private void createProductsTable(Document doc) throws DocumentException {

    Paragraph paragraph = new Paragraph("RESUMO GERAL");
    paragraph.setFont(fontText);/*w  w w.  j a va2 s  . com*/

    DecimalFormat dc = new DecimalFormat("########0.00");

    // specify column widths
    float[] columnWidths = { 2f, 2f, 2f, 2f, 2f, 2f, 2.5f };
    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    // set table width a percentage of the page width
    table.setWidthPercentage(100f);

    // insert column headings
    insertCell(table, "PRODUTO:", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "GUIA DE TR?FEGO N:", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "ENTRADA", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "ESTOQUE DO TRIMESTRE ANTERIOR", Element.ALIGN_CENTER, fontHeaderTableSmall);
    insertCell(table, "CONSUMO", Element.ALIGN_CENTER, fontHeaderTable);
    insertCell(table, "ESTOQUE PARA O TRIMESTRE SEGUINTE", Element.ALIGN_CENTER, fontHeaderTableSmall);
    insertCell(table, "PROCEDNCIA (RAZO SOCIAL, ENDEREO,CIDADE, CEP, E  N.DO CERTIFICADO DE REGISTRO)",
            Element.ALIGN_CENTER, fontHeaderTableTiny);

    table.setHeaderRows(1);

    for (InvoiceInventoryMapEntity productMap : listProductMapVO) {

        String companyCell = "PROCEDNCIA (" + company.getName() + ", " + company.getStreet() + ", "
                + company.getCity() + ", " + company.getCep() + ", " + license.getNumRegister() + ")";

        // Calcula o estoque para o Trimestre seguinte
        BigDecimal qtdNextPeriod = productMap.getQtdInventoryPreviusTrimester()
                .add(productMap.getQtdBuyProduct()).subtract(productMap.getQtdSellProduct())
                .subtract(productMap.getQtdUtilization());

        // Cria a tabela com os Produtos
        insertCell(table, productMap.getProduct().getName(), Element.ALIGN_CENTER, fontHeaderTableSmall);
        insertCell(table, productMap.getTrafficGuide(), Element.ALIGN_CENTER, fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdBuyProduct()), Element.ALIGN_CENTER, fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdInventoryPreviusTrimester()), Element.ALIGN_CENTER,
                fontHeaderTableSmall);
        insertCell(table, dc.format(productMap.getQtdUtilization()), Element.ALIGN_CENTER,
                fontHeaderTableSmall);
        insertCell(table, dc.format(qtdNextPeriod), Element.ALIGN_CENTER, fontHeaderTableSmall);
        insertCell(table, companyCell, Element.ALIGN_CENTER, fontHeaderTableSmall);
    }

    doc.add(paragraph);
    doc.add(table);

    doc.add(Chunk.NEWLINE);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void createTable(Document doc, RequerimentFederalEnum type, LicensePFEntity license,
        List<ProductOfficialEntity> listProducts) throws DocumentException {

    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(4);
    // set table width a percentage of the page width
    table.setWidthPercentage(100f);

    this.createCompany(table, license);

    // Alterao Cadastral
    this.createAlteracaoCadastral(table, type);

    // Descrio/*w  w w. ja  v  a  2  s  .  c  om*/
    this.insertHeaderCell(table, "3 - DESCREVER AS PRINCIPAIS ALTERAES OCORRIDAS", 4);
    this.insertCell(table, this.createProductsText(listProducts, type), 4);

    // Uso Oficial
    this.insertCellProtocol(table, license);

    // Footer
    this.createFooter(table);

    // Table pai
    PdfPTable tableFather = new PdfPTable(1);
    tableFather.setWidthPercentage(100f);
    PdfPCell cellFather = new PdfPCell(table);
    cellFather.setBorderWidth(2);
    tableFather.addCell(cellFather);

    doc.add(this.createHeader());
    doc.add(tableFather);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellProtocol(PdfPTable table, LicensePFEntity license) {

    PdfPTable tableProtocol = new PdfPTable(1);
    tableProtocol.setWidthPercentage(100f);

    Paragraph officialPhrase = new Paragraph("USO OFICIAL" + SEPARATOR, FONT_PARAGRAPH);
    officialPhrase.setAlignment(Element.ALIGN_LEFT);

    Paragraph protocolPhrase = new Paragraph("ETIQUETA PROTOCOLO" + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE
            + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR, FONT_PROTOCOL);
    protocolPhrase.setAlignment(Element.ALIGN_LEFT);

    Paragraph obsPhrase = new Paragraph("Observao Importante!" + SEPARATOR, FONT_HEADER);

    Paragraph obsStringPhrase = new Paragraph(
            "Protocolar este Anexo somente quando no conjugado com a alterao efetiva ou a renovao da licena.",
            FONT_PARAGRAPH);/*w ww . ja va  2s. c  om*/

    Paragraph fullPhrase = new Paragraph();
    fullPhrase.add(officialPhrase);
    fullPhrase.add(protocolPhrase);
    fullPhrase.add(obsPhrase);
    fullPhrase.add(obsStringPhrase);

    PdfPCell cell = new PdfPCell(fullPhrase);

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(5f);

    tableProtocol.addCell(cell);

    PdfPCell cellProtocol = new PdfPCell(tableProtocol);
    cellProtocol.setColspan(2);

    table.addCell(cellProtocol);
    table.addCell(this.createCellEtiqueta(license));
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private PdfPCell createCellEtiqueta(LicensePFEntity license) {
    PdfPTable tableProtocol = new PdfPTable(3);
    tableProtocol.setWidthPercentage(100f);

    this.insertCell(tableProtocol, "LOCAL E DATA" + SEPARATOR_DOUBLE + license.getCompany().getState() + ", "
            + DateUtils.format(Calendar.getInstance()), 3);

    this.insertCell(tableProtocol,
            "REPRESENTANTE LEGAL" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getName(), 3);

    this.insertCell(tableProtocol, "IDENTIDADE (N - RGO - UF)" + SEPARATOR_DOUBLE
            + license.getCompany().getUserResponsable().getRg(), 2);
    this.insertCell(tableProtocol,
            "CPF" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getCpf(), 1);

    this.insertCell(tableProtocol,
            "DDD" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getPhoneDDD(), 1);
    this.insertCell(tableProtocol,
            "TELEFONE" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getPhoneNumber(), 1);
    this.insertCell(tableProtocol,
            "FAX" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getNumFax(), 1);

    this.insertCell(tableProtocol, "ASSINATURA" + SEPARATOR_DOUBLE + "________________________________________",
            3);/*from   w w w  . ja  v  a 2 s  .co m*/

    PdfPCell cell = new PdfPCell(tableProtocol);
    cell.setColspan(4);

    return cell;
}

From source file:com.timesheet.export.PdfGenerator.java

@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    /* Add header*/
    Font fontHeader = FontFactory.getFont(FontFactory.TIMES_ROMAN, 22, Font.BOLD);
    Paragraph headerPara = new Paragraph("Time sheet report", fontHeader);
    headerPara.setSpacingAfter(20f);//from  w  w w  .  j a va2s  . c  o  m
    document.add(headerPara);

    /*Add user info*/
    User userProfile = (User) model.get("userprofile");
    Font fontUserInfo = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
    document.add(new Paragraph("Name : " + userProfile.getName(), fontUserInfo));
    document.add(new Paragraph("User no. : " + userProfile.getUserIdentifier(), fontUserInfo));
    document.add(new Paragraph("Department : " + userProfile.getDepartment(), fontUserInfo));
    document.add(new Paragraph("Email : " + userProfile.getEmail(), fontUserInfo));
    Paragraph spacing = new Paragraph("");
    spacing.setSpacingAfter(20f);
    document.add(spacing);

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100.0f);
    table.setWidths(new float[] { 5.0f, 3.0f, 3.0f, 3.0f, 10.0f });
    table.setSpacingBefore(10);

    // define font for table header row
    Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);
    //font.setColor(BaseColor.WHITE);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    //cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPadding(5);
    cell.setBorderWidth(2.0f);
    cell.setBorder(Rectangle.BOTTOM);
    // get data model which is passed by the Spring container
    List<Booking> bookings = (List<Booking>) model.get("bookings");

    // write table header
    cell.setPhrase(new Phrase("Project", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Option", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Date", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Duration", font));
    table.addCell(cell);
    // write table header
    cell.setPhrase(new Phrase("Description", font));
    table.addCell(cell);

    int sum = 0;

    Font fontData = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11);

    for (Booking booking : bookings) {
        PdfPCell cell1 = new PdfPCell(new Phrase(
                booking.getProject().getProjectId() + "-" + booking.getProject().getName(), fontData));
        cell1.setBorder(Rectangle.BOTTOM);
        cell1.setPadding(5);
        table.addCell(cell1);
        PdfPCell cell2 = new PdfPCell(new Phrase(booking.getBookingOption().getOptionLabel(), fontData));
        cell2.setBorder(Rectangle.BOTTOM);
        cell2.setPadding(5);
        table.addCell(cell2);
        PdfPCell cell3 = new PdfPCell(new Phrase(formatDate(booking.getBookingDate()), fontData));
        cell3.setBorder(Rectangle.BOTTOM);
        cell3.setPadding(5);
        table.addCell(cell3);
        int hh = booking.getDuration() / 60;
        int mm = booking.getDuration() % 60;
        PdfPCell cell4 = new PdfPCell(new Phrase(hh + ":" + mm, fontData));
        cell4.setBorder(Rectangle.BOTTOM);
        cell4.setPadding(5);
        table.addCell(cell4);
        PdfPCell cell5 = new PdfPCell(
                new Phrase(StringEscapeUtils.escapeHtml(booking.getDescription()), fontData));
        cell5.setBorder(Rectangle.BOTTOM);
        cell5.setPadding(5);
        table.addCell(cell5);

        sum += booking.getDuration();
    }

    document.add(table);

    int sumHH = sum / 60;
    int sumMM = sum % 60;

    document.add(new Paragraph("Sum : " + sumHH + ":" + sumMM, fontUserInfo));
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}