Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell PdfPCell.

Prototype

public PdfPCell(PdfPCell cell) 

Source Link

Document

Constructs a deep copy of a PdfPCell.

Usage

From source file:com.exam.server.ConvertPDF.java

private static void createTable(Section subCatPart, ArrayList<DeviceDTO> input) throws BadElementException {
    //                PdfPTable table = new PdfPTable(input.size()+1);
    PdfPTable table = new PdfPTable(6);
    System.out.println("size::" + input.size());

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Part2 Id"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//  w  w  w.  j  ava2s.  c  o m

    c1 = new PdfPCell(new Phrase("Id Company"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Address"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase("Data1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase("Time1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase("Time2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    for (int i = 0; i < input.size(); i++) {
        table.addCell("" + input.get(i).getPart2Id());
        table.addCell("" + input.get(i).getIdCompany());
        table.addCell(input.get(i).getAddress1());
        table.addCell(input.get(i).getData1());
        table.addCell(input.get(i).getTime1());
        table.addCell(input.get(i).getTime2());
    }

    subCatPart.add(table);

}

From source file:com.geek.tutorial.itext.table.PDFTable.java

License:Open Source License

public PDFTable() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("table_example.pdf"));
    document.open();/*from w  w  w .j  a  va  2 s  .com*/

    PdfPTable table = new PdfPTable(3);
    //table.setTotalWidth(216f);
    //table.setLockedWidth(true);
    PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
    cell.setColspan(3);
    table.addCell(cell);
    table.addCell("1.1");
    table.addCell("2.1");
    table.addCell("3.1");
    table.addCell("1.2");
    table.addCell("2.2");
    table.addCell("3.2");

    document.add(table);

    document.close();

}

From source file:com.geek.tutorial.itext.table.SimplePDFTableColspan.java

License:Open Source License

public SimplePDFTableColspan() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("SimplePDFTableColspan.pdf"));
    document.open();//from  w  w  w  .  jav  a  2  s  .  c  o  m

    PdfPTable table = new PdfPTable(2);

    PdfPCell cell = new PdfPCell(new Paragraph("column span 2"));
    cell.setColspan(2);
    table.addCell(cell);

    table.addCell("1");
    table.addCell("2");
    table.addCell("3");
    table.addCell("4");
    table.addCell("5");
    table.addCell("6");

    document.add(table);
    document.close();
}

From source file:com.gtdfree.test.TableBorders.java

License:Open Source License

private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading,
        float padding, Rectangle borders, boolean ascender, boolean descender) {
    Paragraph p = new Paragraph(text, font);
    p.setLeading(leading);//ww  w  . ja  v  a2  s.  c  o m

    PdfPCell cell = new PdfPCell(p);
    cell.setLeading(leading, 0);
    cell.setVerticalAlignment(vAlignment);
    cell.setHorizontalAlignment(hAlignment);
    cell.cloneNonPositionParameters(borders);
    cell.setUseAscender(ascender);
    cell.setUseDescender(descender);
    cell.setUseBorderPadding(true);
    cell.setPadding(padding);
    return cell;
}

From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java

License:Open Source License

@Override
public byte[] export(String htmlTable) throws DocumentException {
    com.lowagie.text.Document doc = new com.lowagie.text.Document();

    Document document = null;/*  www  .  ja v a  2 s.  c o m*/
    try {
        document = parser.parse(htmlTable);
    } catch (JDOMException | IOException ex) {
        throw new DocumentException(ex);
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    PdfWriter.getInstance(doc, out);

    doc.open();

    PdfPTable table = new PdfPTable(columnLength(document));

    List<PdfPCell> cells = getHeaders(document);
    for (PdfPCell cell : cells) {
        table.addCell(cell);
    }

    List<String> data = getBodyValues(document);
    for (String item : data) {
        table.addCell(new PdfPCell(new Phrase(item)));
    }

    doc.add(table);
    doc.close();

    return out.toByteArray();
}

From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java

License:Open Source License

private List<PdfPCell> getHeaders(Document document) {
    List<PdfPCell> result = new ArrayList<>();

    Element tr = document.getRootElement().getChild("thead").getChildren().get(0);

    for (Element th : tr.getChildren()) {
        PdfPCell cell = new PdfPCell(new Phrase(th.getText(), new Font(Font.BOLD)));
        result.add(cell);/*from ww  w  . jav a2 s  .com*/
    }

    return result;
}

From source file:com.huateng.system.util.PdfUtil.java

License:Open Source License

public static void create(String mchtId, String selMchtId, String path, List<Object[]> list,
        LinkedHashMap<String, List<Object[]>> map, Set<String> set) throws Exception {

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    //// ww w  .j  av a2 s  .co  m
    Font font17 = new Font(bfChinese, 17, Font.BOLD);
    Font font8 = new Font(bfChinese, 8, Font.NORMAL);
    Font font9 = new Font(bfChinese, 9, Font.NORMAL);
    Font font9Bold = new Font(bfChinese, 9, Font.BOLD);
    Font font8Red = new Font(bfChinese, 8, Font.NORMAL);
    font8Red.setColor(Color.RED);
    Font font8Green = new Font(bfChinese, 8, Font.NORMAL);
    font8Green.setColor(Color.GREEN);

    logger.info("Starting build document...");

    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();
    LINECANVAS border = new LINECANVAS();

    //
    float[] widths = { 0.1f, 0.35f, 0.35f, 0.1f, 0.1f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.getDefaultCell().setFixedHeight(12);

    //CELL
    PdfPCell cellMchntId = new PdfPCell(new Paragraph(mchtId, font8));
    cellMchntId.setBorder(PdfPCell.BOTTOM);
    cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellMchntName = new PdfPCell(new Paragraph(InformationUtil.getMchtName(mchtId), font8));
    cellMchntName.setBorder(PdfPCell.BOTTOM);
    cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER);

    String point = InformationUtil.getCurPaperPoint(selMchtId);
    PdfPCell cellPoint;
    cellPoint = new PdfPCell(new Paragraph(point, font8Red));
    cellPoint.setBorder(PdfPCell.NO_BORDER);
    cellPoint.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellLevel;
    String level = InformationUtil.getCurPaperLevel(selMchtId);
    if (Integer.valueOf(point) >= 60) {
        cellLevel = new PdfPCell(new Paragraph(level, font8Green));
    } else {
        cellLevel = new PdfPCell(new Paragraph(level, font8Red));
    }
    cellLevel.setBorder(PdfPCell.NO_BORDER);
    cellLevel.setHorizontalAlignment(Element.ALIGN_CENTER);

    //
    Image img = Image.getInstance(
            ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif"));
    img.scalePercent(70);
    float w = img.getScaledWidth();
    float h = img.getScaledHeight();
    writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h);

    //
    PdfPCell cell = new PdfPCell(new Paragraph("?", font17));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(5);
    cell.setFixedHeight(h);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setFixedHeight(20);
    cell.setColspan(5);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    table.addCell(new Paragraph("?", font8));
    table.addCell(cellMchntId);
    table.addCell(" ");
    table.addCell(new Paragraph(": ", font8));
    table.addCell(cellPoint);

    table.addCell(new Paragraph("??", font8));
    table.addCell(cellMchntName);
    table.addCell(" ");
    table.addCell(new Paragraph(": ", font8));
    table.addCell(cellLevel);

    document.add(table);
    document.add(new Paragraph("\n\n"));

    //?
    PdfPTable t = new PdfPTable(1);

    Iterator<Object[]> it0 = list.iterator();
    int i = 1;
    while (it0.hasNext()) {
        Object[] obj = it0.next();
        PdfPCell c = new PdfPCell();
        c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font9Bold));
        List<Object[]> opts = map.get(obj[0].toString());
        String opt = "";
        Iterator<Object[]> it1 = opts.iterator();
        while (it1.hasNext()) {
            Object[] o = it1.next();
            if (set.contains(o[0])) {
                opt += "? ";
                opt += o[1].toString();
                opt += "         ";
            } else {
                opt += " ";
                opt += o[1].toString();
                opt += "         ";
            }
        }
        c.addElement(new Paragraph(opt.trim(), font9));
        c.setBorder(PdfPCell.NO_BORDER);
        if (i - 1 != list.size()) {
            c.setCellEvent(border);
        }
        t.addCell(c);
    }

    PdfPTable oTable = new PdfPTable(1);
    oTable.setWidthPercentage(100);
    PdfPCell ce = new PdfPCell(t);
    ce.setBorderColor(Color.GRAY);
    oTable.addCell(ce);

    document.add(oTable);

    document.close();

    logger.info("Finish build document...");
}

From source file:com.huateng.system.util.PdfUtil.java

License:Open Source License

public static void create(String path, List<Object[]> list, LinkedHashMap<String, List<Object[]>> map)
        throws Exception {

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    ////from   w w  w.j  a v a  2 s . c o m
    Font font17 = new Font(bfChinese, 17, Font.BOLD);
    Font font8 = new Font(bfChinese, 8, Font.NORMAL);
    Font font10 = new Font(bfChinese, 10, Font.NORMAL);
    Font font10Bold = new Font(bfChinese, 10, Font.BOLD);
    Font font8Red = new Font(bfChinese, 8, Font.NORMAL);
    font8Red.setColor(Color.RED);
    Font font8Green = new Font(bfChinese, 8, Font.NORMAL);
    font8Green.setColor(Color.GREEN);

    logger.info("Starting build document...");

    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();
    LINECANVAS border = new LINECANVAS();

    //
    float[] widths = { 0.1f, 0.35f, 0.55f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.getDefaultCell().setFixedHeight(12);

    //CELL
    PdfPCell cellMchntId = new PdfPCell(new Paragraph("XXXXXXXXXXXXXXX", font8));
    cellMchntId.setBorder(PdfPCell.BOTTOM);
    cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellMchntName = new PdfPCell(new Paragraph("?", font8));
    cellMchntName.setBorder(PdfPCell.BOTTOM);
    cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER);

    //
    Image img = Image.getInstance(
            ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif"));
    img.scalePercent(70);
    float w = img.getScaledWidth();
    float h = img.getScaledHeight();
    writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h);

    //
    PdfPCell cell = new PdfPCell(new Paragraph("?", font17));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(3);
    cell.setFixedHeight(h);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setFixedHeight(20);
    cell.setColspan(3);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    table.addCell(new Paragraph("?", font8));
    table.addCell(cellMchntId);
    table.addCell(" ");

    table.addCell(new Paragraph("??", font8));
    table.addCell(cellMchntName);
    table.addCell(" ");

    document.add(table);
    document.add(new Paragraph("\n\n"));

    //?
    PdfPTable t = new PdfPTable(1);

    Iterator<Object[]> it0 = list.iterator();
    int i = 1;
    while (it0.hasNext()) {
        Object[] obj = it0.next();
        PdfPCell c = new PdfPCell();
        c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font10Bold));
        List<Object[]> opts = map.get(obj[0].toString());
        String opt = "";
        Iterator<Object[]> it1 = opts.iterator();
        while (it1.hasNext()) {
            Object[] o = it1.next();
            opt += " ";
            opt += o[1].toString();
            opt += "         ";
        }
        c.addElement(new Paragraph(opt.trim(), font10));
        c.setBorder(PdfPCell.NO_BORDER);
        if (i - 1 != list.size()) {
            c.setCellEvent(border);
        }
        t.addCell(c);
    }

    PdfPTable oTable = new PdfPTable(1);
    oTable.setWidthPercentage(100);
    PdfPCell ce = new PdfPCell(t);
    ce.setBorderColor(Color.GRAY);
    oTable.addCell(ce);

    document.add(oTable);

    document.close();

    logger.info("Finish build document...");
}

From source file:com.itext.test.FirstPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    //PdfPTable//from  w ww. j a v a 2 s . c  o  m
    PdfPTable table = new PdfPTable(3);
    //PdfPTable
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //PDFPCell
    PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
    //PdfPCellHorizontalAlignment?
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    //celltable
    table.addCell(c1);
    //PDFPCell
    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Table Header 3"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("1.0");
    table.addCell("1.1");
    table.addCell("1.2");
    table.addCell("2.1");
    table.addCell("2.2");
    table.addCell("2.3");

    subCatPart.add(table);

}

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Creates the pdf footer./*from ww  w. j  av  a2s. c o m*/
 *
 * @param pdfPTable
 *            the pdf P table
 * @param font
 *            the font
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void createPdfFooter(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException {
    final float width = pdfPTable.getWidthPercentage();
    final int headerWidth = (int) width;
    font = getFont();
    final PdfPCell footerCell = new PdfPCell(new Phrase(getFooter(), font));
    footerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    footerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    footerCell.setColspan(headerWidth);
    footerCell.setBorder(0);
    footerCell.setUseDescender(true);
    pdfPTable.addCell(footerCell);
    pdfPTable.setFooterRows(1);
}