Search in sources :

Example 1 with Phrase

use of com.itextpdf.text.Phrase 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 2 with Phrase

use of com.itextpdf.text.Phrase in project bamboobsc by billchen198318.

the class PersonalReportPdfCommand method createHead.

private void createHead(PdfPTable table, VisionVO vision, Context context) throws Exception {
    String bgColor = "#F2F2F2";
    String fnColor = "#000000";
    PdfPCell cell = new PdfPCell();
    cell.addElement(new Phrase("Personal Balance SourceCard", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(MAX_COLSPAN);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(vision.getTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(MAX_COLSPAN);
    table.addCell(cell);
    String dateType = (String) context.get("dateType");
    String year = (String) context.get("startYearDate");
    String empId = (String) context.get("empId");
    String account = (String) context.get("account");
    String fullName = "";
    String jobTitle = "";
    String departmentName = "";
    String dateTypeName = "Year";
    if ("1".equals(dateType)) {
        dateTypeName = "In the first half";
    }
    if ("2".equals(dateType)) {
        dateTypeName = "In the second half";
    }
    EmployeeVO employee = new EmployeeVO();
    employee.setEmpId(empId);
    employee.setAccount(account);
    DefaultResult<EmployeeVO> result = this.employeeService.findByUK(employee);
    if (result.getValue() != null) {
        fullName = result.getValue().getEmpId() + " - " + result.getValue().getFullName();
        jobTitle = result.getValue().getEmpId() + " - " + result.getValue().getFullName();
        List<String> appendIds = this.organizationService.findForAppendOrganizationOids(result.getValue().getEmpId());
        List<String> appendNames = this.organizationService.findForAppendNames(appendIds);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; appendNames != null && i < appendNames.size(); i++) {
            sb.append(appendNames.get(i)).append(Constants.ID_DELIMITER);
        }
        departmentName = sb.toString();
    }
    cell = new PdfPCell();
    cell.addElement(new Phrase("Job Title", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(jobTitle, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Department", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(departmentName, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("name: " + fullName, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Annual assessment: " + year, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getObjectiveTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getKpiTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Maximum\nTarget\nMinimum", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Weight", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Formula", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Score", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(dateTypeName, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    cell.setRowspan(1);
    table.addCell(cell);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) EmployeeVO(com.netsteadfast.greenstep.vo.EmployeeVO) Phrase(com.itextpdf.text.Phrase)

Example 3 with Phrase

use of com.itextpdf.text.Phrase in project bamboobsc by billchen198318.

the class PersonalReportPdfCommand method createBody.

private void createBody(PdfPTable table, VisionVO vision) throws Exception {
    String bgColor = "#ffffff";
    String fnColor = "#000000";
    for (PerspectiveVO perspective : vision.getPerspectives()) {
        for (ObjectiveVO objective : perspective.getObjectives()) {
            int kx = 0;
            for (KpiVO kpi : objective.getKpis()) {
                PdfPCell cell = new PdfPCell();
                if (kx == 0) {
                    cell.addElement(new Phrase(objective.getName(), this.getFont(fnColor, true)));
                    this.setCellBackgroundColor(cell, bgColor);
                    cell.setColspan(1);
                    cell.setRowspan(objective.getRow());
                    table.addCell(cell);
                }
                cell = new PdfPCell();
                cell.addElement(new Phrase(kpi.getName(), this.getFont(fnColor, true)));
                this.setCellBackgroundColor(cell, bgColor);
                cell.setColspan(1);
                table.addCell(cell);
                cell = new PdfPCell();
                cell.addElement(new Phrase("max: " + kpi.getMax() + "\n" + "target: " + kpi.getTarget() + "\n" + "min: " + kpi.getMin() + "\n" + "unit: " + kpi.getUnit(), this.getFont(fnColor, true)));
                this.setCellBackgroundColor(cell, bgColor);
                cell.setColspan(1);
                table.addCell(cell);
                cell = new PdfPCell();
                cell.addElement(new Phrase(kpi.getWeight() + "%", this.getFont(fnColor, true)));
                this.setCellBackgroundColor(cell, bgColor);
                cell.setColspan(1);
                table.addCell(cell);
                cell = new PdfPCell();
                cell.addElement(new Phrase(kpi.getFormula().getName(), this.getFont(fnColor, true)));
                this.setCellBackgroundColor(cell, bgColor);
                cell.setColspan(1);
                table.addCell(cell);
                // 只顯示一筆日期分數資料
                DateRangeScoreVO dateRangeScore = kpi.getDateRangeScores().get(0);
                cell = new PdfPCell();
                cell.addElement(new Phrase(BscReportSupportUtils.parse2(dateRangeScore.getScore()), this.getFont(dateRangeScore.getFontColor(), true)));
                this.setCellBackgroundColor(cell, dateRangeScore.getBgColor());
                cell.setColspan(1);
                table.addCell(cell);
                kx++;
            }
        }
    }
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) DateRangeScoreVO(com.netsteadfast.greenstep.vo.DateRangeScoreVO) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) Phrase(com.itextpdf.text.Phrase)

Example 4 with Phrase

use of com.itextpdf.text.Phrase in project bamboobsc by billchen198318.

the class KpiReportPdfCommand method createDateRange.

private void createDateRange(PdfPTable table, VisionVO vision, Context context, int maxRows) throws Exception {
    String frequency = (String) context.get("frequency");
    String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim();
    String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim();
    String startDate = StringUtils.defaultString((String) context.get("startDate")).trim();
    String endDate = StringUtils.defaultString((String) context.get("endDate")).trim();
    String date1 = startDate;
    String date2 = endDate;
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        date1 = startYearDate + "/01/01";
        date2 = endYearDate + "/12/" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12);
    }
    Map<String, Object> headContentMap = new HashMap<String, Object>();
    this.fillHeadContent(context, headContentMap);
    String content = "Frequency: " + BscMeasureDataFrequency.getFrequencyMap(false).get(frequency) + " Date range: " + date1 + " ~ " + date2 + "\n" + StringUtils.defaultString((String) headContentMap.get("headContent"));
    PdfPCell cell = null;
    cell = new PdfPCell();
    cell.addElement(new Phrase(content, this.getFont(BscReportPropertyUtils.getFontColor(), false)));
    this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor());
    cell.setColspan(maxRows);
    table.addCell(cell);
    for (PerspectiveVO perspective : vision.getPerspectives()) {
        for (ObjectiveVO objective : perspective.getObjectives()) {
            for (KpiVO kpi : objective.getKpis()) {
                cell = new PdfPCell();
                cell.addElement(new Phrase(kpi.getName(), this.getFont(kpi.getFontColor(), false)));
                this.setCellBackgroundColor(cell, kpi.getBgColor());
                cell.setColspan(4);
                cell.setRowspan(2);
                table.addCell(cell);
                for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
                    cell = new PdfPCell();
                    cell.addElement(new Phrase(dateScore.getDate(), this.getFont(dateScore.getFontColor(), false)));
                    this.setCellBackgroundColor(cell, dateScore.getBgColor());
                    table.addCell(cell);
                }
                for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
                    Image image = Image.getInstance(BscReportSupportUtils.getByteIcon(kpi, dateScore.getScore()));
                    image.setWidthPercentage(20f);
                    cell = new PdfPCell();
                    cell.addElement(new Phrase(BscReportSupportUtils.parse2(dateScore.getScore()), this.getFont(dateScore.getFontColor(), false)));
                    cell.addElement(image);
                    this.setCellBackgroundColor(cell, dateScore.getBgColor());
                    table.addCell(cell);
                }
            }
        }
    }
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) HashMap(java.util.HashMap) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) DateRangeScoreVO(com.netsteadfast.greenstep.vo.DateRangeScoreVO) Phrase(com.itextpdf.text.Phrase) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.text.Image)

Example 5 with Phrase

use of com.itextpdf.text.Phrase in project bamboobsc by billchen198318.

the class OrganizationReportPdfCommand method createHead.

private void createHead(PdfPTable table, VisionVO vision, Context context) throws Exception {
    String bgColor = "#F2F2F2";
    String fnColor = "#000000";
    PdfPCell cell = new PdfPCell();
    cell.addElement(new Phrase("Department Balance SourceCard", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(MAX_COLSPAN);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(vision.getTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(MAX_COLSPAN);
    table.addCell(cell);
    String dateType = (String) context.get("dateType");
    String year = (String) context.get("startYearDate");
    String orgId = (String) context.get("orgId");
    String departmentName = "";
    String dateTypeName = "Year";
    if ("1".equals(dateType)) {
        dateTypeName = "In the first half";
    }
    if ("2".equals(dateType)) {
        dateTypeName = "In the second half";
    }
    OrganizationVO organization = new OrganizationVO();
    organization.setOrgId(orgId);
    DefaultResult<OrganizationVO> result = this.organizationService.findByUK(organization);
    if (result.getValue() != null) {
        organization = result.getValue();
        departmentName = organization.getName();
    }
    cell = new PdfPCell();
    cell.addElement(new Phrase("Department", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(departmentName, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(4);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(year + " " + dateTypeName, this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getPerspectiveTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getObjectiveTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getKpiTitle(), this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Weight", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Maximum\nTarget\nMinimum", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.addElement(new Phrase("Score", this.getFont(fnColor, true)));
    this.setCellBackgroundColor(cell, bgColor);
    cell.setColspan(1);
    table.addCell(cell);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) OrganizationVO(com.netsteadfast.greenstep.vo.OrganizationVO) Phrase(com.itextpdf.text.Phrase)

Aggregations

Phrase (com.itextpdf.text.Phrase)50 PdfPCell (com.itextpdf.text.pdf.PdfPCell)42 PdfPTable (com.itextpdf.text.pdf.PdfPTable)17 Paragraph (com.itextpdf.text.Paragraph)14 Image (com.itextpdf.text.Image)7 IOException (java.io.IOException)7 Chunk (com.itextpdf.text.Chunk)6 Font (com.itextpdf.text.Font)6 BadElementException (com.itextpdf.text.BadElementException)5 DocumentException (com.itextpdf.text.DocumentException)5 ArrayList (java.util.ArrayList)5 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)4 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)4 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)4 ObjetivoDisciplinaDTO (com.tomasio.projects.trainning.dto.ObjetivoDisciplinaDTO)4 BaseColor (com.itextpdf.text.BaseColor)3 List (com.itextpdf.text.List)3 ListItem (com.itextpdf.text.ListItem)3 BaseFont (com.itextpdf.text.pdf.BaseFont)3 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)3