Search in sources :

Example 1 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project Openfire by igniterealtime.

the class EmailSenderUtility method createPdfAttachment.

public void createPdfAttachment(OutputStream outputStream) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, outputStream);
    document.open();
    document.addTitle("Monitoring Report");
    document.addSubject("PDF Document");
    document.addKeywords("iText, email");
    document.addAuthor("JMX");
    document.addCreator("JMX");
    Timestamp stamp = new Timestamp(System.currentTimeMillis());
    Date date = new Date(stamp.getTime());
    //Make the Get call to get the data from Jolokia endpoint.
    HttpClient httpClient = new HttpClient();
    String monData = httpClient.getMemoryData();
    Log.info("Monitoring Data JSON:" + monData);
    //Converting json string to java object for easy manipulation.
    Map outNode = new Genson().deserialize(monData, Map.class);
    Map requestNode = (Map) outNode.get("request");
    Map valueNode = (Map) outNode.get("value");
    HashMap<String, String> monitoringData = new HashMap<String, String>();
    monitoringData.put("Current Date", date.toString());
    monitoringData.put("Report Date", outNode.get("timestamp").toString());
    monitoringData.put("Maximum Heap Memory", valueNode.get("max").toString());
    monitoringData.put("Committed Heap Memory", valueNode.get("committed").toString());
    monitoringData.put("Init Heap Memory", valueNode.get("init").toString());
    monitoringData.put("Used Heap Memory", valueNode.get("used").toString());
    Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
    PdfPTable table = new PdfPTable(2);
    table.setSpacingBefore(5);
    table.addCell(new Phrase("Monitor", boldFont));
    table.addCell(new Phrase("Value", boldFont));
    for (Map.Entry<String, String> entry : monitoringData.entrySet()) {
        table.addCell(entry.getKey());
        System.out.println(entry.getKey());
        if (entry.getValue() != "" && entry.getValue() != null) {
            table.addCell(entry.getValue());
            System.out.println(entry.getValue());
        } else {
            table.addCell("NOT AVAILABLE");
        }
    }
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    document.add(table);
    document.close();
}
Also used : Genson(com.owlike.genson.Genson) Timestamp(java.sql.Timestamp) Date(java.util.Date) PdfPTable(com.itextpdf.text.pdf.PdfPTable)

Example 2 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project summer-bean by cn-cerc.

the class InvoiceTemplate method output.

@Override
public void output(Document document, PdfWriter writer) throws DocumentException, IOException {
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // 设置中文字体和字体样式
    Font f8 = new Font(bfChinese, 8, Font.NORMAL);
    Font f18 = new Font(bfChinese, 18, Font.NORMAL);
    document.addTitle(this.getFileName());
    // 页标题
    Paragraph title = new Paragraph(this.getFileName(), f18);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);
    // 空一行
    document.add(new Paragraph(" ", f18));
    // 创建一个N列的表格控件
    PdfPTable pdfTable = new PdfPTable(2);
    // 设置报表为无边框
    pdfTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    // 设置表格占PDF文档100%宽度
    pdfTable.setWidthPercentage(100);
    // 水平方向表格控件左对齐
    pdfTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    // 创建一个表格的表头单元格
    PdfPCell pdfTableHeaderCell = new PdfPCell();
    // 设置表格的表头单元格颜色
    pdfTableHeaderCell.setBackgroundColor(new BaseColor(240, 240, 240));
    pdfTableHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    // 设置表头栏位
    pdfTableHeaderCell.setPhrase(new Paragraph("名称", f8));
    pdfTable.addCell(pdfTableHeaderCell);
    pdfTableHeaderCell.setPhrase(new Paragraph("信息", f8));
    pdfTable.addCell(pdfTableHeaderCell);
    // 创建一个表格的正文内容单元格
    PdfPCell pdfTableContentCell_1 = new PdfPCell();
    pdfTableContentCell_1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    pdfTableContentCell_1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    PdfPCell pdfTableContentCell_2 = new PdfPCell();
    pdfTableContentCell_2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    pdfTableContentCell_2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    // 表格内容行数的填充
    dataSet.first();
    while (dataSet.fetch()) {
        Record record = dataSet.getCurrent();
        for (Column column : this.getColumns()) {
            pdfTableContentCell_1.setPhrase(new Phrase(column.getName(), f8));
            pdfTable.addCell(pdfTableContentCell_1);
            String field = column.getCode();
            pdfTableContentCell_2.setPhrase(new Paragraph(record.getString(field), f8));
            pdfTable.addCell(pdfTableContentCell_2);
        }
    }
    document.add(pdfTable);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) BaseColor(com.itextpdf.text.BaseColor) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Column(cn.cerc.jexport.excel.Column) BaseFont(com.itextpdf.text.pdf.BaseFont) Record(cn.cerc.jdb.core.Record) Phrase(com.itextpdf.text.Phrase) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) Paragraph(com.itextpdf.text.Paragraph)

Example 3 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project summer-bean by cn-cerc.

the class Template method output.

public void output(Document document, PdfWriter writer) throws DocumentException, IOException {
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // 设置中文字体和字体样式
    Font f8 = new Font(bfChinese, 8, Font.NORMAL);
    Font f18 = new Font(bfChinese, 18, Font.NORMAL);
    document.addTitle(this.getFileName());
    // 页标题
    Paragraph title = new Paragraph(this.getFileName(), f18);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);
    // 空一行
    document.add(new Paragraph(" ", f18));
    // 创建一个N列的表格控件
    PdfPTable pdfTable = new PdfPTable(this.getColumns().size());
    // 设置表格占PDF文档100%宽度
    pdfTable.setWidthPercentage(100);
    // 水平方向表格控件左对齐
    pdfTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    // 创建一个表格的表头单元格
    PdfPCell pdfTableHeaderCell = new PdfPCell();
    // 设置表格的表头单元格颜色
    pdfTableHeaderCell.setBackgroundColor(new BaseColor(240, 240, 240));
    pdfTableHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    for (Column column : this.getColumns()) {
        Paragraph item = new Paragraph(column.getName(), f8);
        pdfTableHeaderCell.setPhrase(item);
        pdfTable.addCell(pdfTableHeaderCell);
    }
    // 创建一个表格的正文内容单元格
    PdfPCell pdfTableContentCell = new PdfPCell();
    pdfTableContentCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    pdfTableContentCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    // 表格内容行数的填充
    dataSet.first();
    while (dataSet.fetch()) {
        Record record = dataSet.getCurrent();
        for (Column column : this.getColumns()) {
            String field = column.getCode();
            pdfTableContentCell.setPhrase(new Paragraph(record.getString(field), f8));
            pdfTable.addCell(pdfTableContentCell);
        }
    }
    document.add(pdfTable);
// //将表格添加到新的文档
// doc.add(table);
// //创建新的一页
// doc.newPage();
// //添加图片
// Image image = Image.getInstance(
// "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");
// //添加到文档
// doc.add(image);
// //设置对象方式
// image.setAlignment(Element.ALIGN_CENTER);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) BaseColor(com.itextpdf.text.BaseColor) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Column(cn.cerc.jexport.excel.Column) BaseFont(com.itextpdf.text.pdf.BaseFont) Record(cn.cerc.jdb.core.Record) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) Paragraph(com.itextpdf.text.Paragraph)

Example 4 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project bamboobsc by billchen198318.

the class KpiReportPdfCommand method createPdf.

private String createPdf(Context context) throws Exception {
    BscReportPropertyUtils.loadData();
    // 2015-04-18 add
    BscReportSupportUtils.loadExpression();
    String visionOid = (String) context.get("visionOid");
    VisionVO vision = null;
    BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context);
    for (VisionVO visionObj : treeObj.getVisions()) {
        if (visionObj.getOid().equals(visionOid)) {
            vision = visionObj;
        }
    }
    FontFactory.register(BscConstants.PDF_ITEXT_FONT);
    String fileName = UUID.randomUUID().toString() + ".pdf";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    OutputStream os = new FileOutputStream(fileFullPath);
    //Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    Document document = new Document(PageSize.A4, 10, 10, 10, 10);
    document.left(100f);
    document.top(150f);
    PdfWriter writer = PdfWriter.getInstance(document, os);
    document.open();
    int dateRangeRows = 4 + vision.getPerspectives().get(0).getObjectives().get(0).getKpis().get(0).getDateRangeScores().size();
    PdfPTable table = new PdfPTable(MAX_COLSPAN);
    PdfPTable dateRangeTable = new PdfPTable(dateRangeRows);
    PdfPTable chartsTable = new PdfPTable(2);
    PdfPTable signTable = new PdfPTable(1);
    table.setWidthPercentage(100f);
    dateRangeTable.setWidthPercentage(100f);
    chartsTable.setWidthPercentage(100f);
    signTable.setWidthPercentage(100f);
    this.createHead(table, vision);
    this.createBody(table, vision);
    this.createDateRange(dateRangeTable, vision, context, dateRangeRows);
    this.putCharts(chartsTable, context);
    this.putSignature(signTable, context);
    document.add(chartsTable);
    document.add(table);
    document.add(dateRangeTable);
    document.add(signTable);
    document.close();
    writer.close();
    os.flush();
    os.close();
    os = null;
    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file, "kpi-report.pdf");
    file = null;
    return oid;
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) PdfPTable(com.itextpdf.text.pdf.PdfPTable) BscStructTreeObj(com.netsteadfast.greenstep.bsc.model.BscStructTreeObj) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Document(com.itextpdf.text.Document) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) File(java.io.File)

Example 5 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project pancm_project by xuwujing.

the class PdfHelper method generatePDF.

// 生成PDF文件
public void generatePDF(Document document) throws Exception {
    // 段落
    Paragraph title = new Paragraph("武汉市公安局交通管理局科技管理处工程委托单", TITLE_FONT);
    // 设置文字居中 0靠左   1,居中     2,靠右
    title.setAlignment(1);
    // 设置左缩进
    title.setIndentationLeft(12);
    // 设置右缩进
    title.setIndentationRight(12);
    // 设置首行缩进
    title.setFirstLineIndent(24);
    // 行间距
    title.setLeading(20f);
    // 设置段落上空白
    title.setSpacingBefore(5f);
    // 设置段落下空白
    title.setSpacingAfter(10f);
    // 表格
    PdfPTable table = createTable(new float[] { 90, 150, 90, 150 });
    table.addCell(createCell("派工单号  BSYJH20201113001", TEXT_FONT, Element.ALIGN_RIGHT, 4, false));
    table.addCell(createCell("验收日期", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("2020/12/5", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("工程类别", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("信号灯", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("施工单位", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("毕昇云", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("工程验收金额", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("8600.00 元", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table.addCell(createCell("    工程内容:", TEXT_FONT, Element.ALIGN_LEFT, Element.ALIGN_LEFT, 4, 140f));
    PdfPTable table2 = createTable(new float[] { 30, 55, 55, 55, 30, 30, 45, 45, 45, 45 });
    table2.addCell(createCell("序号", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("项目编号", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("名称", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("型号", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("数量", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("单位", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("单价", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("预算金额", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("结算金额", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    table2.addCell(createCell("监理确认量", TEXT_FONT, Element.ALIGN_CENTER, 25f));
    Integer totalQuantity = 0;
    for (int i = 0; i < 5; i++) {
        table2.addCell(createCell(String.valueOf(i + 1), TEXT_FONT));
        table2.addCell(createCell("108", TEXT_FONT));
        table2.addCell(createCell("交通信号灯安装1-满屏机动灯", TEXT_FONT));
        table2.addCell(createCell("JD400-3—FM31", TEXT_FONT));
        table2.addCell(createCell("1", TEXT_FONT));
        table2.addCell(createCell("套", TEXT_FONT));
        table2.addCell(createCell("2300", TEXT_FONT));
        table2.addCell(createCell("2300", TEXT_FONT));
        table2.addCell(createCell("2300", TEXT_FONT));
        table2.addCell(createCell("", TEXT_FONT));
        totalQuantity++;
    }
    table2.addCell(createCell(String.valueOf(totalQuantity + 1), TEXT_FONT));
    table2.addCell(createCell("", TEXT_FONT));
    table2.addCell(createCell("总价", TEXT_FONT, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 5, 25f));
    table2.addCell(createCell("8600", TEXT_FONT));
    table2.addCell(createCell("8600", TEXT_FONT));
    table2.addCell(createCell("", TEXT_FONT));
    PdfPTable table3 = createTable(new float[] { 85, 350 });
    table3.addCell(createCell("  监理单位(盖章) \n \n  签          字\n \n  日          期", TEXT_FONT, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, 0, 80f));
    table3.addCell(createCell("", TEXT_FONT));
    PdfPTable table4 = createTable(new float[] { 85, 350 });
    table4.addCell(createCell("  业主单位(盖章) \n \n  签          字\n \n  日          期", TEXT_FONT, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, 0, 80f));
    table4.addCell(createCell("", TEXT_FONT));
    PdfPTable table5 = createTable(new float[] { 85, 350 });
    table5.addCell(createCell("  维护单位(盖章) \n \n  签          字\n \n  日          期", TEXT_FONT, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, 0, 80f));
    table5.addCell(createCell("", TEXT_FONT));
    document.add(title);
    document.add(table);
    document.add(table2);
    document.add(table5);
    document.add(table3);
    document.add(table4);
    // 添加图片
    Image image;
    for (int i = 0; i < 6; i++) {
        image = Image.getInstance("https://img-blog.csdn.net/20180801174617455?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzg0ODcxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70");
        image.setAlignment(Image.ALIGN_LEFT);
        // 依照比例缩放
        image.scalePercent(40);
        // image.setAbsolutePosition(1*i,1*i);
        document.add(image);
    }
}
Also used : PdfPTable(com.itextpdf.text.pdf.PdfPTable)

Aggregations

PdfPTable (com.itextpdf.text.pdf.PdfPTable)44 PdfPCell (com.itextpdf.text.pdf.PdfPCell)24 Paragraph (com.itextpdf.text.Paragraph)18 Phrase (com.itextpdf.text.Phrase)17 DocumentException (com.itextpdf.text.DocumentException)12 Font (com.itextpdf.text.Font)8 IOException (java.io.IOException)8 ExceptionConverter (com.itextpdf.text.ExceptionConverter)6 Document (com.itextpdf.text.Document)5 BadElementException (com.itextpdf.text.BadElementException)4 BaseFont (com.itextpdf.text.pdf.BaseFont)4 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)4 PdfWriter (com.itextpdf.text.pdf.PdfWriter)4 FileOutputStream (java.io.FileOutputStream)4 BaseColor (com.itextpdf.text.BaseColor)3 Chapter (com.itextpdf.text.Chapter)3 Chunk (com.itextpdf.text.Chunk)3 Image (com.itextpdf.text.Image)3 ListItem (com.itextpdf.text.ListItem)3 PdfReader (com.itextpdf.text.pdf.PdfReader)3