Example usage for com.lowagie.text Font NORMAL

List of usage examples for com.lowagie.text Font NORMAL

Introduction

In this page you can find the example usage for com.lowagie.text Font NORMAL.

Prototype

int NORMAL

To view the source code for com.lowagie.text Font NORMAL.

Click Source Link

Document

this is a possible style.

Usage

From source file:org.eclipse.osee.framework.ui.skynet.util.TableWriterAdaptor.java

License:Open Source License

public void writeRow(Table table, String... cellData) {
    for (String cellText : cellData) {
        Cell cell = new Cell();
        cell.setHeader(false);//from   www.  j  a  v a2 s . co m
        cell.setColspan(1);
        Font font = FontFactory.getFont("Times New Roman", BaseFont.CP1252, BaseFont.EMBEDDED, 9, Font.NORMAL,
                WebColors.getRGBColor("#000000"));
        Paragraph paragraph = new Paragraph(cellText, font);
        cell.add(paragraph);
        table.addCell(cell);
    }
}

From source file:org.egov.infra.web.displaytag.export.EGovPdfView.java

License:Open Source License

/**
 * Initialize the main info holder table.
 * @throws BadElementException for errors during table initialization
 *//*  w w w .ja v  a2  s.  co m*/
protected void initTable() throws BadElementException {
    this.tablePDF = new Table(this.model.getNumberOfColumns());
    this.tablePDF.setCellsFitPage(true);
    this.tablePDF.setWidth(100);

    this.tablePDF.setPadding(2);
    this.tablePDF.setSpacing(0);

    this.smallFont = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.NORMAL, new Color(0, 0, 0));
    /*
     * try { BaseFont btKannada = BaseFont.createFont("Tunga", "Identity-H", BaseFont.NOT_EMBEDDED); } catch (DocumentException e) {   } catch (IOException e) {   }
     */

}

From source file:org.jcryptool.visual.crt.export.FileExporter.java

License:Open Source License

/**
 * creates the PDF output-file using iText library
 */// w  w w  . jav a2 s  . c  o m
public void exportToPDF() {
    Font fontSupscript = new Font(Font.HELVETICA, 6, Font.NORMAL);
    Font fontSymbol = new Font(Font.SYMBOL, 12, Font.NORMAL);

    try {
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();

        document.add(new Paragraph("Chinese Remainder Theorem"));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Equations:"));
        document.add(new Paragraph(" "));
        for (int i = 0; i < valueA.length; i++) {
            document.add(new Paragraph("x = " + valueA[i] + " mod " + valueModuli[i]));
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Compute"));
        document.add(new Paragraph(" "));

        Chunk space = new Chunk(" ");
        Chunk spaceBig = new Chunk("    ");
        Chunk index = new Chunk("i", fontSupscript);
        index.setTextRise(-3.0f);
        Chunk m = new Chunk("m");
        Chunk equal = new Chunk("=");
        Chunk openB = new Chunk("(");
        Chunk closeB = new Chunk(")");
        Chunk p = new Chunk("P", fontSymbol);
        Chunk comma = new Chunk(",");
        Chunk range = new Chunk("i=0 to n-1");
        Chunk bigM = new Chunk("M");
        Chunk div = new Chunk("/");

        document.add(m);
        document.add(space);
        document.add(equal);
        document.add(space);
        document.add(p);
        document.add(space);
        document.add(openB);
        document.add(space);
        document.add(m);
        document.add(index);
        document.add(space);
        document.add(closeB);
        document.add(comma);
        document.add(spaceBig);
        document.add(bigM);
        document.add(space);
        document.add(equal);
        document.add(space);
        document.add(m);
        document.add(space);
        document.add(div);
        document.add(space);
        document.add(m);
        document.add(index);
        document.add(comma);
        document.add(spaceBig);
        document.add(range);

        document.add(new Paragraph(" "));
        document.add(new Paragraph("m = " + crt.getModulus()));
        document.add(new Paragraph(" "));
        for (int i = 0; i < valueBigM.length; i++) {
            m = new Chunk("m");
            index = new Chunk(String.valueOf(i), fontSupscript);
            index.setTextRise(-3.0f);
            Chunk value = new Chunk(valueBigM[i].toString());

            document.add(m);
            document.add(index);
            document.add(new Chunk(" = "));
            document.add(value);
            document.add(new Paragraph());
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph("To get the inverse you can use the extended euclidean."));
        document.add(new Paragraph(" "));

        Chunk y = new Chunk("y");
        Chunk equiv = new Chunk("=");
        Chunk mod = new Chunk("mod");
        index = new Chunk("i", fontSupscript);
        index.setTextRise(-3.0f);

        document.add(y);
        document.add(index);
        document.add(bigM);
        document.add(index);
        document.add(space);
        document.add(equiv);
        document.add(space);
        document.add(new Chunk("1"));
        document.add(space);
        document.add(mod);
        document.add(space);
        document.add(m);
        document.add(index);
        document.add(comma);
        document.add(spaceBig);
        document.add(range);

        document.add(new Paragraph(" "));
        for (int i = 0; i < valueBigM.length; i++) {
            index = new Chunk(String.valueOf(i), fontSupscript);
            index.setTextRise(-3.0f);
            Chunk value = new Chunk(valueInverse[i].toString());

            document.add(new Chunk("y"));
            document.add(index);
            document.add(new Chunk(" = "));
            document.add(value);
            document.add(new Paragraph());
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph("To get one solution of the simultaneous congruences."));
        document.add(new Paragraph(" "));

        Chunk sum = new Chunk("S", fontSymbol);
        index = new Chunk("i", fontSupscript);
        index.setTextRise(-3.0f);

        document.add(new Chunk("x = "));
        document.add(sum);
        document.add(space);
        document.add(new Chunk());
        document.add(new Chunk("a"));
        document.add(index);
        document.add(new Chunk("y"));
        document.add(index);
        document.add(bigM);
        document.add(index);
        document.add(space);
        document.add(new Chunk("mod"));
        document.add(space);
        document.add(m);
        document.add(comma);
        document.add(spaceBig);
        document.add(range);
        document.add(new Chunk("."));

        document.add(new Paragraph(" "));
        document.add(new Paragraph("One solution is: " + crt.getFinalResult()));

        document.close();

    } catch (FileNotFoundException e) {
        LogUtil.logError(e);
    } catch (DocumentException e) {
        LogUtil.logError(e);
    }
}

From source file:org.kuali.coeus.common.impl.print.PrintingServiceImpl.java

License:Open Source License

/**
 * @param pdfBytesList List containing the PDF data bytes
 * @param bookmarksList List of bookmarks corresponding to the PDF bytes.
 * @return/* w w  w . j a v  a2  s  .c om*/
 * @throws PrintingException
 */

protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList,
        boolean headerFooterRequired) throws PrintingException {
    Document document = null;
    PdfWriter writer = null;
    ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream();
    int totalNumOfPages = 0;
    PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()];
    int pdfReaderCount = 0;
    for (byte[] fileBytes : pdfBytesList) {
        LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount));
        PdfReader reader = null;
        try {
            reader = new PdfReader(fileBytes);
            pdfReaderArr[pdfReaderCount] = reader;
            pdfReaderCount = pdfReaderCount + 1;
            totalNumOfPages += reader.getNumberOfPages();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    HeaderFooter footer = null;
    if (headerFooterRequired) {
        Calendar calendar = dateTimeService.getCurrentCalendar();
        String dateString = formateCalendar(calendar);
        StringBuilder footerPhStr = new StringBuilder();
        footerPhStr.append(" of ");
        footerPhStr.append(totalNumOfPages);
        footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76));
        footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76));
        footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60));
        footerPhStr.append(dateString);
        Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK);
        Phrase beforePhrase = new Phrase("Page ", font);
        Phrase afterPhrase = new Phrase(footerPhStr.toString(), font);
        footer = new HeaderFooter(beforePhrase, afterPhrase);
        footer.setAlignment(Element.ALIGN_BASELINE);
        footer.setBorderWidth(0f);
    }
    for (int count = 0; count < pdfReaderArr.length; count++) {
        PdfReader reader = pdfReaderArr[count];
        int nop;
        if (reader == null) {
            LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count));
            continue;
        } else {
            nop = reader.getNumberOfPages();
        }

        if (count == 0) {
            document = nop > 0 ? new com.lowagie.text.Document(reader.getPageSizeWithRotation(1))
                    : new com.lowagie.text.Document();
            try {
                writer = PdfWriter.getInstance(document, mergedPdfReport);
            } catch (DocumentException e) {
                LOG.error(e.getMessage(), e);
                throw new PrintingException(e.getMessage(), e);
            }
            if (footer != null) {
                document.setFooter(footer);
            }
            // writer.setPageEvent(new Watermark()); // add watermark object here
            document.open();
        }

        PdfContentByte cb = writer.getDirectContent();
        int pageCount = 0;
        while (pageCount < nop) {
            document.setPageSize(reader.getPageSize(++pageCount));
            document.newPage();
            if (footer != null) {
                document.setFooter(footer);
            }
            PdfImportedPage page = writer.getImportedPage(reader, pageCount);

            cb.addTemplate(page, 1, 0, 0, 1, 0, 0);

            PdfOutline root = cb.getRootOutline();
            if (pageCount == 1) {
                String pageName = bookmarksList.get(count);
                cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName),
                        pageName);
            }
        }
    }
    if (document != null) {
        try {
            document.close();
            return mergedPdfReport.toByteArray();
        } catch (Exception e) {
            LOG.error("Exception occured because the generated PDF document has no pages", e);
        }
    }
    return null;
}

From source file:org.kuali.coeus.s2sgen.impl.print.S2SPrintingServiceImpl.java

License:Educational Community License

/**
 * @param pdfBytesList List containing the PDF data bytes
 * @param bookmarksList List of bookmarks corresponding to the PDF bytes.
 *///ww w .  j ava  2 s. c  o m
protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList,
        boolean headerFooterRequired) {
    Document document = null;
    PdfWriter writer = null;
    ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream();
    int totalNumOfPages = 0;
    PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()];
    int pdfReaderCount = 0;
    for (byte[] fileBytes : pdfBytesList) {
        LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount));
        PdfReader reader = null;
        try {
            reader = new PdfReader(fileBytes);
            pdfReaderArr[pdfReaderCount] = reader;
            pdfReaderCount = pdfReaderCount + 1;
            totalNumOfPages += reader.getNumberOfPages();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    HeaderFooter footer = null;
    if (headerFooterRequired) {
        Calendar calendar = Calendar.getInstance();
        String dateString = formateCalendar(calendar);
        StringBuilder footerPhStr = new StringBuilder();
        footerPhStr.append(" of ");
        footerPhStr.append(totalNumOfPages);
        footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76));
        footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76));
        footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60));
        footerPhStr.append(dateString);
        Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK);
        Phrase beforePhrase = new Phrase("Page ", font);
        Phrase afterPhrase = new Phrase(footerPhStr.toString(), font);
        footer = new HeaderFooter(beforePhrase, afterPhrase);
        footer.setAlignment(Element.ALIGN_BASELINE);
        footer.setBorderWidth(0f);
    }
    for (int count = 0; count < pdfReaderArr.length; count++) {
        PdfReader reader = pdfReaderArr[count];
        int nop;
        if (reader == null) {
            LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count));
            continue;
        } else {
            nop = reader.getNumberOfPages();
        }

        if (count == 0) {
            document = nop > 0 ? new Document(reader.getPageSizeWithRotation(1)) : new Document();
            try {
                writer = PdfWriter.getInstance(document, mergedPdfReport);
            } catch (DocumentException e) {
                LOG.error(e.getMessage(), e);
                throw new S2SException(e.getMessage(), e);
            }
            if (footer != null) {
                document.setFooter(footer);
            }
            document.open();
        }

        PdfContentByte cb = writer.getDirectContent();
        int pageCount = 0;
        while (pageCount < nop) {
            document.setPageSize(reader.getPageSize(++pageCount));
            document.newPage();
            if (footer != null) {
                document.setFooter(footer);
            }
            PdfImportedPage page = writer.getImportedPage(reader, pageCount);

            cb.addTemplate(page, 1, 0, 0, 1, 0, 0);

            PdfOutline root = cb.getRootOutline();
            if (pageCount == 1) {
                String pageName = bookmarksList.get(count);
                cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName),
                        pageName);
            }
        }
    }
    if (document != null) {
        try {
            document.close();
            return mergedPdfReport.toByteArray();
        } catch (Exception e) {
            LOG.error("Exception occured because the generated PDF document has no pages", e);
        }
    }
    return null;
}

From source file:org.kuali.kfs.gl.report.TransactionReport.java

License:Open Source License

/**
 * Generates transaction report/*from   w w w.j a v a  2s .  c o m*/
 * 
 * @param errorSortedList list of error'd transactions
 * @param reportErrors map containing transactions and the errors associated with each transaction
 * @param reportSummary list of summary objects
 * @param runDate date report is run
 * @param title title of report
 * @param fileprefix file prefix of report file
 * @param destinationDirectory destination of where report file will reside
 */
public void generateReport(List<Transaction> errorSortedList, Map<Transaction, List<Message>> reportErrors,
        List<Summary> reportSummary, Date runDate, String title, String fileprefix,
        String destinationDirectory) {
    LOG.debug("generateReport() started");

    Font headerFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD);
    Font textFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

    Document document = new Document(PageSize.A4.rotate());

    PageHelper helper = new PageHelper();
    helper.runDate = runDate;
    helper.headerFont = headerFont;
    helper.title = title;

    try {
        DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);

        String filename = destinationDirectory + "/" + fileprefix + "_";
        filename = filename + dateTimeService.toDateTimeStringForFilename(runDate);
        filename = filename + ".pdf";
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        writer.setPageEvent(helper);

        document.open();
        appendReport(document, headerFont, textFont, errorSortedList, reportErrors, reportSummary, runDate);
    } catch (DocumentException de) {
        LOG.error("generateReport() Error creating PDF report", de);
        throw new RuntimeException("Report Generation Failed: " + de.getMessage());
    } catch (FileNotFoundException fnfe) {
        LOG.error("generateReport() Error writing PDF report", fnfe);
        throw new RuntimeException("Report Generation Failed: Error writing to file " + fnfe.getMessage());
    } finally {
        if ((document != null) && document.isOpen()) {
            document.close();
        }
    }
}

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

License:Open Source License

protected void writeInvoiceSectionMessage(com.lowagie.text.Document pdfDoc, String resultLine) {
    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(resultLine, font));

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

    try {/* w  w  w.  j  a 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;/*from  w  w w. j  av a2 s .  c o m*/
    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 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 {/*www .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.cam.report.DepreciationReport.java

License:Open Source License

/**
 * This method creates the report file and invokes the methods that write the data
 * /*  w w  w . jav  a  2  s .  c om*/
 * @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();
        }
    }
}