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

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

Introduction

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

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:com.shiyq.itext.PdfUtil.java

private static PdfPTable createTableHead(PdfPTable table, String[] head, FontSelector selector) {
    Phrase str = selector.process("?");
    table.addCell(str);
    for (int i = 0; i < head.length; i++) {
        str = selector.process(head[i]);
        table.addCell(str);//from   w w  w .  j av  a 2  s. c  o m
    }
    return table;
}

From source file:com.shiyq.itext.PdfUtil.java

private static PdfPTable createTableCell(PdfPTable table, Map<String, Object> map, String[] code,
        FontSelector selector, int index) {
    Phrase str = selector.process(String.valueOf(index + 1));
    table.addCell(str);
    for (int i = 0; i < code.length; i++) {
        str = selector.process((String) map.get(code[i]));
        table.addCell(str);/*from   w  ww  .ja  v a  2 s. c  o  m*/
    }
    return table;
}

From source file:com.skatettoo.reportes.Generador.java

public String generarPDF() throws Exception {
    try {/*from  ww  w . j a va2  s.c om*/
        String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("img");
        path = path.substring(0, path.indexOf("\\build"));
        path = path + "\\web\\img\\";
        Document doc = new Document(PageSize.A4, 36, 36, 10, 10);
        PdfPTable tabla = new PdfPTable(4);
        PdfWriter.getInstance(doc, new FileOutputStream(path + "\\archivo\\reporte.pdf\\"));
        doc.open();
        Image img = Image.getInstance(path + "Skatetoo4.png");
        img.scaleAbsolute(40, 40);
        img.setAlignment(Element.ALIGN_LEFT);
        doc.add(img);
        doc.addTitle(this.titulo);
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        tabla.setWidthPercentage(100);
        tabla.setWidths(new float[] { 1.4f, 0.8f, 0.8f, 0.8f });
        Object font = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de tatuadores", (Font) font));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingTop(0f);
        cell.setPaddingBottom(7f);
        cell.setBackgroundColor(new BaseColor(0, 0, 0));
        cell.setBorder(0);
        cell.setBorderWidthBottom(2f);
        tabla.addCell(cell);
        tabla.addCell("Tatuador");
        tabla.addCell("Cantidad de diseos");
        tabla.addCell("Citas realizadas");
        tabla.addCell("Noticias publicadas");
        for (Usuario u : this.getUsu()) {
            tabla.addCell(u.getNombre() + " " + u.getApellido());
            tabla.addCell(String.valueOf(u.getDisenioList().size()));
            tabla.addCell(String.valueOf(u.getCitaList1().size()));
            tabla.addCell(String.valueOf(u.getNoticiaList().size()));
        }
        doc.add(tabla);
        doc.bottomMargin();
        /* doc.add(new Paragraph("Tatuador mas solicitado"));
         for(Usuario u : this.getUs()){
        doc.add(new Paragraph(u.getNombre() + " " + u.getApellido()));
         }*/
        doc.close();
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext externalContext = context.getExternalContext();

        externalContext.responseReset();
        externalContext.setResponseContentType("application/pdf");
        externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\"");

        FileInputStream inputStream = new FileInputStream(new File(path + "\\archivo\\reporte.pdf\\"));
        OutputStream outputStream = externalContext.getResponseOutputStream();

        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }

        inputStream.close();
        context.responseComplete();
    } catch (Exception e) {
        throw e;
    }
    return "";
}

From source file:com.softwaremagico.tm.pdf.complete.characteristics.CharacteristicColumn.java

License:Open Source License

private PdfPCell createContent(CharacterPlayer characterPlayer, List<CharacteristicDefinition> content) {
    float[] widths = { 3f, 1f, 0.1f };
    PdfPTable table = new PdfPTable(widths);
    BaseElement.setTablePropierties(table);
    table.getDefaultCell().setBorder(0);

    for (CharacteristicDefinition characteristic : content) {
        Paragraph paragraph = new Paragraph();
        paragraph.add(new Paragraph(getTranslator().getTranslatedText(characteristic.getId()),
                new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE)));
        paragraph.add(new Paragraph(" (",
                new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE)));
        if (characterPlayer == null) {
            paragraph.add(new Paragraph(GAP,
                    new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE)));
        } else {//from ww w .j av  a 2 s. c  o  m
            paragraph.add(
                    new Paragraph(characterPlayer.getStartingValue(characteristic.getCharacteristicName()) + "",
                            new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme
                                    .getHandWrittingFontSize(FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE))));
        }
        paragraph.add(new Paragraph(")",
                new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.CHARACTERISTICS_LINE_FONT_SIZE)));

        PdfPCell characteristicTitle = new PdfPCell(paragraph);
        characteristicTitle.setBorder(0);
        characteristicTitle.setMinimumHeight(ROW_WIDTH / content.size());
        table.addCell(characteristicTitle);

        // Rectangle
        if (characterPlayer == null) {
            table.addCell(createRectangle());
        } else {
            table.addCell(createRectangle(characterPlayer.getValue(characteristic.getCharacteristicName())
                    + getCharacteristicSpecialRepresentation(characterPlayer,
                            characteristic.getCharacteristicName())));
        }

        // Margin
        PdfPCell margin = new PdfPCell();
        margin.setBorder(0);
        table.addCell(margin);
    }

    PdfPCell cell = new PdfPCell();
    cell.addElement(table);
    BaseElement.setCellProperties(cell);

    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.characteristics.CharacteristicsTableFactory.java

License:Open Source License

public static PdfPTable getCharacteristicsBasicsTable(CharacterPlayer characterPlayer) {
    float[] widths = { 1f, 1f, 1f, 1f };
    PdfPTable table = new PdfPTable(widths);
    setTablePropierties(table);//w ww . java 2  s.c om

    PdfPCell separator = createSeparator();
    separator.setColspan(widths.length);
    table.addCell(separator);

    Phrase content = new Phrase(getTranslator().getTranslatedText("characteristics").toUpperCase(),
            new Font(FadingSunsTheme.getTitleFont(), FadingSunsTheme.TITLE_FONT_SIZE));
    PdfPCell titleCell = new PdfPCell(content);
    setCellProperties(titleCell);
    titleCell.setColspan(widths.length);
    titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    titleCell.setFixedHeight(30);
    table.addCell(titleCell);
    table.getDefaultCell().setPadding(0);

    for (CharacteristicType type : CharacteristicType.values()) {
        try {
            table.addCell(new CharacteristicColumn(characterPlayer, type,
                    CharacteristicsDefinitionFactory.getInstance().getAll(type, Translator.getLanguage())));
        } catch (NullPointerException npe) {
            PdfExporterLog.errorMessage(CharacteristicsTableFactory.class.getName(), npe);
        }
    }

    return table;
}

From source file:com.softwaremagico.tm.pdf.complete.CharacterSheet.java

License:Open Source License

private PdfPTable createRearTable() throws InvalidXmlElementException {
    PdfPTable mainTable = new PdfPTable(REAR_TABLE_WIDTHS);
    mainTable.getDefaultCell().setBorder(0);
    mainTable.setWidthPercentage(100);/*  ww  w.  j  a va2s .  co m*/

    mainTable.addCell(new DescriptionTable(characterPlayer));
    PdfPCell cell = new PdfPCell(new AnnotationsTable());
    cell.setBorderWidth(0);
    cell.setColspan(2);
    mainTable.addCell(cell);

    PdfPCell blackSeparator = BaseElement.createBigSeparator(90);
    mainTable.addCell(blackSeparator);

    PdfPCell separatorCell = new PdfPCell(BaseElement.createWhiteSeparator());
    separatorCell.setColspan(2);
    mainTable.addCell(separatorCell);

    mainTable.addCell(new PropertiesTable(characterPlayer));

    PdfPCell psiCell = new PdfPCell(new OccultismsPowerTable(characterPlayer, PSI_ROWS));
    psiCell.setColspan(2);
    mainTable.addCell(psiCell);

    mainTable.addCell(BaseElement.createBigSeparator(90));

    mainTable.addCell(separatorCell);

    PdfPTable othersTable = new OthersTable();
    mainTable.addCell(othersTable);

    PdfPCell cyberneticsCell = new PdfPCell(new CyberneticsTable(characterPlayer));
    cyberneticsCell.setColspan(2);
    mainTable.addCell(cyberneticsCell);

    return mainTable;
}

From source file:com.softwaremagico.tm.pdf.complete.CharacterSheet.java

License:Open Source License

private PdfPTable createRearTablePsiExtended() throws InvalidXmlElementException {
    PdfPTable mainTable = new PdfPTable(REAR_TABLE_WIDTHS);
    mainTable.getDefaultCell().setBorder(0);
    mainTable.setWidthPercentage(100);//from ww w  .j  av  a 2s . c om

    mainTable.addCell(new DescriptionTable(characterPlayer));
    PdfPCell cell = new PdfPCell(new AnnotationsTable());
    cell.setBorderWidth(0);
    cell.setColspan(2);
    mainTable.addCell(cell);

    PdfPCell blackSeparator = BaseElement.createBigSeparator(90);
    mainTable.addCell(blackSeparator);

    PdfPCell separatorCell = new PdfPCell(BaseElement.createWhiteSeparator());
    separatorCell.setColspan(2);
    mainTable.addCell(separatorCell);

    mainTable.addCell(new PropertiesTable(characterPlayer));

    PdfPCell psiCell = new PdfPCell(new OccultismsPowerTable(characterPlayer, PSI_EXTENDED_ROWS));
    psiCell.setColspan(2);
    psiCell.setRowspan(3);
    mainTable.addCell(psiCell);

    mainTable.addCell(BaseElement.createBigSeparator(90));

    PdfPTable othersTable = new OthersTable();
    mainTable.addCell(othersTable);

    return mainTable;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

public static PdfPCell createSeparator() {
    float[] widths = { 1f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);/*from  ww w.  jav  a 2s. c  o  m*/
    table.addCell(createWhiteSeparator());
    table.addCell(createBlackSeparator());
    // table.addCell(createWhiteSeparator());

    PdfPCell cell = new PdfPCell();
    cell.addElement(table);
    setCellProperties(cell);

    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

public static PdfPCell createBigSeparator(int width) {
    float[] widths = { 1f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(width);/*from   ww w  .j a  va 2 s .c om*/
    table.addCell(createWhiteSeparator());
    table.addCell(createBlackSeparator());
    table.addCell(createWhiteSeparator());

    PdfPCell cell = new PdfPCell();
    cell.addElement(table);
    setCellProperties(cell);

    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.fighting.ArmourTable.java

License:Open Source License

private PdfPTable getArmourProperty(String text, boolean selected) {
    float[] widths = { 1f, 1f };
    PdfPTable table = new PdfPTable(widths);
    BaseElement.setTablePropierties(table);
    table.getDefaultCell().setBorder(0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    if (!selected) {
        table.addCell(createRectangle());
    } else {/*from ww  w. java 2  s  . c  o  m*/
        table.addCell(createRectangle("X"));
    }
    table.addCell(createEmptyElementLine(text));

    return table;
}