Example usage for com.lowagie.text FontFactory getFont

List of usage examples for com.lowagie.text FontFactory getFont

Introduction

In this page you can find the example usage for com.lowagie.text FontFactory getFont.

Prototype


public static Font getFont(String fontname, float size, int style) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java

License:Open Source License

protected void writeCustomerSectionTitle(Document pdfDoc, String customerNameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    paragraph.add(new Chunk(customerNameLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {//ww w  .  jav a2 s . co m
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java

License:Open Source License

protected void writeCustomerSectionResult(Document pdfDoc, String resultLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    paragraph.add(new Chunk(resultLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {/*from w w w  . ja v a2 s.  co  m*/
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java

License:Open Source License

protected void writeMessageEntryLines(Document pdfDoc, List<String[]> messageLines) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

    Paragraph paragraph;// w w  w.  j a  v  a2  s.  c om
    String messageEntry;
    for (String[] messageLine : messageLines) {
        paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_LEFT);
        messageEntry = StringUtils.rightPad(messageLine[0], (12 - messageLine[0].length()), " ") + " - "
                + messageLine[1].toUpperCase();
        paragraph.add(new Chunk(messageEntry, font));

        //  blank line
        paragraph.add(new Chunk("", font));

        try {
            pdfDoc.add(paragraph);
        } catch (DocumentException e) {
            LOG.error("iText DocumentException thrown when trying to write content.", e);
            throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
        }
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.LockboxServiceImpl.java

License:Open Source License

protected void writeBatchGroupSectionTitle(com.lowagie.text.Document pdfDoc, String batchSeqNbr,
        java.sql.Date procInvDt, String cashControlDocNumber) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD);

    String lineText = "CASHCTL " + rightPad(cashControlDocNumber, 12) + " " + "BATCH GROUP: "
            + rightPad(batchSeqNbr, 5) + " "
            + rightPad((procInvDt == null ? "NONE" : procInvDt.toString()), 35);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    Chunk chunk = new Chunk(lineText, font);
    chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5);
    paragraph.add(chunk);//from ww w  . j  a  va2 s. c  om

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    } catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.LockboxServiceImpl.java

License:Open Source License

protected void writeDetailLine(com.lowagie.text.Document pdfDoc, String detailLineText) {
    if (ObjectUtils.isNotNull(detailLineText)) {
        Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

        Paragraph paragraph = new Paragraph();
        paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
        paragraph.add(new Chunk(detailLineText, font));

        try {//from   www  .ja  v a 2 s  . c o m
            pdfDoc.add(paragraph);
        } catch (DocumentException e) {
            LOG.error("iText DocumentException thrown when trying to write content.", e);
            throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
        }
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method creates the report file and invokes the methods that write the data
 * /*ww  w  .j a v  a2  s  . co m*/
 * @param reportLog
 * @param errorMsg
 */
public void generateReport(List<String[]> reportLog, String errorMsg, String sDepreciationDate) {
    try {
        DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
        LOG.debug("createReport() started");
        this.document = new Document();

        String destinationDirectory = SpringContext.getBean(ConfigurationService.class)
                .getPropertyValueAsString(KFSConstants.REPORTS_DIRECTORY_KEY);

        SimpleDateFormat sdf = new SimpleDateFormat(CamsConstants.DateFormats.YEAR_MONTH_DAY_NO_DELIMITER + "_"
                + CamsConstants.DateFormats.MILITARY_TIME_NO_DELIMITER);

        String filename = destinationDirectory + File.separator + "cam" + File.separator
                + CamsConstants.Report.FILE_PREFIX + "_" + CamsConstants.Depreciation.REPORT_FILE_NAME + "_"
                + sdf.format(dateTimeService.getCurrentDate()) + "." + CamsConstants.Report.REPORT_EXTENSION;

        Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);

        PageHelper helper = new PageHelper();
        helper.runDate = dateTimeService.getCurrentDate();
        helper.headerFont = headerFont;
        helper.title = CamsConstants.Depreciation.DEPRECIATION_REPORT_TITLE;

        writer = PdfWriter.getInstance(this.document, new FileOutputStream(filename));
        writer.setPageEvent(helper);

        this.document.open();

        // Generate body of document.
        this.generateReportLogBody(reportLog);
        this.generateReportErrorLog(errorMsg);

    } catch (Exception e) {
        throw new RuntimeException(
                "DepreciationReport.generateReport(List<String[]> reportLog, List<String> errorLog) - Error on report generation: "
                        + e.getMessage());
    } finally {
        if ((this.document != null) && this.document.isOpen()) {
            this.document.close();
        }
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method adds the log lines into the report
 * //from   w  w w .  j  a  va  2  s .  c om
 * @param reportLog
 */
private void generateReportLogBody(List<String[]> reportLog) {
    try {
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
        int columnwidths[];
        columnwidths = new int[] { 40, 15 };

        Table aTable = new Table(2, linesPerPage);
        int rowsWritten = 0;
        for (String[] columns : reportLog) {
            if (pageNumber == 0 || line >= linesPerPage) {
                if (pageNumber > 0) {
                    this.document.add(aTable);
                }
                int elementsLeft = reportLog.size() - rowsWritten;
                int rowsNeeded = (elementsLeft >= linesPerPage ? linesPerPage : elementsLeft);
                this.document.newPage();

                this.generateColumnHeaders();

                aTable = new Table(2, rowsNeeded); // 12 columns, 11 rows.

                aTable.setAutoFillEmptyCells(true);
                aTable.setPadding(3);
                aTable.setWidths(columnwidths);
                aTable.setWidth(100);
                aTable.setBorder(Rectangle.NO_BORDER);

                line = 0;
                pageNumber++;
            }
            rowsWritten++;

            Cell cell;
            cell = new Cell(new Phrase(columns[0], font));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            aTable.addCell(cell);

            cell = new Cell(new Phrase(columns[1], font));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            aTable.addCell(cell);
            line++;
        }
        this.document.add(aTable);
    } catch (DocumentException de) {
        throw new RuntimeException(
                "DepreciationReport.generateReportLogBody(List<String[]> reportLog) - error: "
                        + de.getMessage());
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method adds any error to the report
 * //from   www  .  j av a 2  s  . co m
 * @param errorMsg
 */
private void generateReportErrorLog(String errorMsg) {
    try {
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
        Paragraph p1 = new Paragraph();

        int rowsWritten = 0;
        if (!errorMsg.equals("")) {
            this.generateErrorColumnHeaders();

            p1 = new Paragraph(new Chunk(errorMsg, font));
            this.document.add(p1);
            line++;
        }
    } catch (Exception de) {
        throw new RuntimeException(
                "DepreciationReport.generateReportErrorLog(List<String> reportLog) - Report Generation Failed: "
                        + de.getMessage());
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method creates a report group for the error message on the report
 * /*from  w w  w.j  a va2 s  . c  om*/
 * @throws DocumentException
 */
private void generateErrorColumnHeaders() throws DocumentException {
    try {
        int headerwidths[] = { 60 };

        Table aTable = new Table(1, 1); // 2 columns, 1 rows.

        aTable.setAutoFillEmptyCells(true);
        aTable.setPadding(3);
        aTable.setWidths(headerwidths);
        aTable.setWidth(100);

        Cell cell;

        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);

        cell = new Cell(new Phrase("Error(s)", font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setGrayFill(0.9f);
        aTable.addCell(cell);

        this.document.add(aTable);

    } catch (Exception e) {
        throw new RuntimeException(
                "DepreciationReport.generateErrorColumnHeaders() - Error: " + e.getMessage());
    }
}

From source file:org.kuali.kfs.module.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method creates the headers for the report statistics
 *//*from  w  w  w  . j  a v a 2s .c om*/
private void generateColumnHeaders() {
    try {
        int headerwidths[] = { 40, 15 };

        Table aTable = new Table(2, 1); // 2 columns, 1 rows.

        aTable.setAutoFillEmptyCells(true);
        aTable.setPadding(3);
        aTable.setWidths(headerwidths);
        aTable.setWidth(100);

        Cell cell;

        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);

        cell = new Cell(new Phrase(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
                CamsKeyConstants.Depreciation.MSG_REPORT_DEPRECIATION_HEADING1), font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setGrayFill(0.9f);
        aTable.addCell(cell);

        cell = new Cell(new Phrase(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
                CamsKeyConstants.Depreciation.MSG_REPORT_DEPRECIATION_HEADING2), font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setGrayFill(0.9f);
        aTable.addCell(cell);
        this.document.add(aTable);

    } catch (Exception e) {
        throw new RuntimeException("DepreciationReport.generateColumnHeaders() - Error: " + e.getMessage());
    }
}