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

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

Introduction

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

Prototype

public PdfPTable(final PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java

public void reportefinanzas(Map<String, Object> model, HttpServletResponse hsr1, List<CuentaBancaria> cuenta)
        throws Exception {
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();//from  w  ww . j  av a  2s  . c o  m
    document.addTitle("Sapito PDFs");
    document.addSubject("Pdf de sapito");
    Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30);
    font1.setColor(BaseColor.BLACK);
    Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24);
    font2.setColor(BaseColor.BLACK);
    document.add(new Paragraph("TAILS 2015", font1));
    document.add(new Paragraph("Reportes Direccin\n", font2));

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    document.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    document.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    document.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Reporte de Finanzas"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);
    //-------------------------  CONTENIDO -------------------------------------------------------
    document.add(title); //Titulo del PDF

    TextoPdf x = (TextoPdf) model.get("todoTexto");
    document.add(new Paragraph(x.getTodoTexto()));

    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100.0f);
    table.setWidths(new float[] { 2.0f });
    table.setSpacingBefore(10);

    // define font for table header row
    Font font = FontFactory.getFont(FontFactory.COURIER_BOLD);
    font.setColor(BaseColor.WHITE);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    cell.setBackgroundColor(BaseColor.BLUE);
    cell.setPadding(5);

    // write table header 
    cell.setPhrase(new Phrase("Total de dinero que se tiene en CUENTAS BANCARIAS", font));
    table.addCell(cell);

    for (int i = 0; i < cuenta.size(); i++) {
        a = cuenta.get(i).getHaber();
        b = b + a;
    }
    String bla = b + " ";
    table.addCell(bla);

    document.add(table);

    //-------------------------- FIN CONTENIDO -----------------
    document.close();

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}

From source file:com.sapito.pdf.PDFView.PDFGeneratorVentas.java

public void crearPDFFactura(HttpServletResponse hsr1) throws Exception {
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();/*from  w w  w  . j a  va 2s  .  co  m*/
    document.addTitle("Sapito PDFs");
    document.addSubject("Pdf de sapito");

    //------------------------ TAIS  ______________________________
    Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg"));
    document.add(tais);

    //---------------------  BODY    ---------------------------------------------------------
    Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png"));
    body.setAlignment(Image.UNDERLYING);
    body.setTransparency(new int[] { 0x00, 0x10 });
    body.setAbsolutePosition(50, 250);
    document.add(body);
    //-------------------------------------------------------------------------------------------
    Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg"));
    footer.setAbsolutePosition(50, 20);
    document.add(footer);
    //----------------------  TITLE ---------------------------
    String titulo = "Facturas"; //Cambiar el titulo del PDF aqui
    Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK);
    Chunk c = new Chunk(titulo + " \n ", f);
    c.setBackground(BaseColor.WHITE);
    Paragraph title = new Paragraph(c);
    title.setAlignment(Element.ALIGN_CENTER);
    //-------------------------  CONTENIDO -------------------------------------------------------
    document.add(title); //Titulo del PDF
    PdfPTable table = new PdfPTable(1);

    table.addCell("Hola");
    table.addCell("Soy");
    table.addCell("el");
    table.addCell("pdf");
    table.addCell("del");
    table.addCell("sapito");
    document.add(table);

    document.close();

    byte[] bytes = baos.toByteArray();

    hsr1.setContentType("application/pdf");
    hsr1.setContentLength(bytes.length);
    hsr1.getOutputStream().write(bytes);
}

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

public static void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*  w w w.  java  2  s.c o  m*/
    //?
    int fontsize = 10;
    FontSelector selector = getSelector(fontsize);
    String title = "20165??";
    //?
    int titleFontSize = 20;
    //
    addTile(document, title, titleFontSize);
    String describe = "--2016-5-4 12:23:23 ";
    //
    addDescribe(document, describe, selector);
    String[] head = { "??", "?", "?", "????", "??", "",
            "", "??", "??", "???", "????" };
    String[] code = { "card_no", "card_type", "plate", "owner_name", "blance", "start_time", "end_time",
            "month_money", "spread_time", "spread_emp_no", "spread_emp_name" };
    List<Map<String, Object>> list = setList();
    PdfPTable table = new PdfPTable(head.length + 1);
    //
    createTableHead(table, head, selector);
    //
    createTableContent(table, list, code, selector);
    document.add(table);
    document.close();
}

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

public String generarPDF() throws Exception {
    try {//from w ww . ja v  a  2  s .  c  o  m
        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 {// ww w.j av a2  s . c  om
            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);/*ww w . j av a  2  s.com*/

    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);// w  w w  . j  a va2  s .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);//  www.j a va2 s .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_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  www . j av a2s.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   w  w  w  . j  a va  2s .c o  m
    table.addCell(createWhiteSeparator());
    table.addCell(createBlackSeparator());
    table.addCell(createWhiteSeparator());

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

    return cell;
}