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:test.itext.html.AimsPdf.java

License:Open Source License

public static void addScreenShorts(Document doc, String text)
        throws BadElementException, IOException, DocumentException {

    Paragraph heading = new Paragraph("Screenshots",
            FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC));
    heading.setSpacingAfter(12f);//  w  w  w .  j  av a2  s.c o  m
    doc.add(heading);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(80);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    Image image = Image.getInstance("screen_shoot1.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot2.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot3.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot4.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot5.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot6.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    //      doc.add(new Paragraph("\n"));
    doc.add(table);
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

private static void writeData(Document doc, StringBuffer sb, String headingText)
        throws IOException, DocumentException {
    String data = Utility.replace(sb.toString(), "<p>&nbsp;</p>", "", Utility.REPLACE_ALL);
    data = Utility.replace(data, "</p>", "</p><br/>", Utility.REPLACE_ALL);
    data = Utility.replace(data, "</ul>", "</ul><br/>", Utility.REPLACE_ALL);
    data = Utility.replace(data, "</p><br/></td>", "</p></td>", Utility.REPLACE_ALL);

    System.out.println(data);//from   ww  w. ja  va2s .co  m
    Reader reader = new StringReader("<root>" + data + "</root>");

    if (headingText != null && headingText.length() > 0) {
        Paragraph heading = new Paragraph(headingText,
                FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC));
        heading.setSpacingAfter(12f);
        doc.add(heading);
    }

    ArrayList objects = HTMLWorker.parseToList(reader, style, null);
    for (int k = 0; k < objects.size(); ++k) {
        Element ele = (Element) objects.get(k);
        doc.add(ele);
    }

    reader.close();
}

From source file:uk.ac.bbsrc.tgac.miso.core.data.decorator.itext.ITextProjectDecorator.java

License:Open Source License

public void buildReport() throws DocumentException {
    report = new Document();
    PdfWriter writer = PdfWriter.getInstance(report, stream);
    report.open();//from   w  w w  . j  a  va 2  s  . c  o m
    report.add(new Paragraph("Project Summary"));
    PdfContentByte cb = writer.getDirectContent();
    cb.setLineWidth(2.0f); // Make a bit thicker than 1.0 default
    cb.setGrayStroke(0.9f); // 1 = black, 0 = white
    float x = 72f;
    float y = 200f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    report.add(new Paragraph(project.getAlias()));
    report.add(new Paragraph(project.getDescription()));

    PdfPTable t = new PdfPTable(1);
    t.setHorizontalAlignment(Element.ALIGN_CENTER);
    t.setWidthPercentage(100f); // this would be the 100 from setHorizontalLine
    t.setSpacingAfter(5f);
    t.setSpacingBefore(0f);
    t.getDefaultCell().setUseVariableBorders(true);
    t.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    t.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    t.getDefaultCell().setBorder(Rectangle.BOTTOM); // This generates the line
    t.getDefaultCell().setBorderWidth(1f); // this would be the 1 from setHorizontalLine
    t.getDefaultCell().setPadding(0);
    t.addCell("");
    report.add(t);

    x = 72f;
    y = 100f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    if (project.getSamples().size() > 0) {
        report.add(new Paragraph("Samples"));
        for (Sample sample : project.getSamples()) {
            Paragraph sPara = new Paragraph(sample.getAlias(), FontFactory.getFont("Helvetica", 12, Font.BOLD));
            sPara.setIndentationLeft(20);
            report.add(sPara);
            report.add(new Paragraph(sample.getDescription()));
        }
    }

    report.close();
}

From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java

License:Educational Community License

/**
 * Create a new attendance PDF writer//ww  w .  j a va  2s  .  co m
 * @param out The outputstream to write the PDF to.
 * @throws IOException If there is a problem writing to the outputstream.
 */
public PDFWriter(OutputStream out) throws IOException {

    document = new Document();
    try {
        pdfWriter = PdfWriter.getInstance(document, out);
        pdfWriter.setStrictImageSequence(true);
        document.open();

        tableHeadFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
        tableNameFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL);
        tableOtherFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL);
        titleFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.NORMAL);
        authorFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
        infoFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);

    } catch (Exception e) {
        throw new IOException("Unable to start PDF Report");
    }
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildBlankLine</code></h2>
 * /*from  w w w .j  a  v a  2s .c om*/
 * <p>
 *  build a 'blank' line     
 * </p>
 */
private void buildBlankLine() throws DocumentException {

    if (++rowCount < pageLength) {
        PdfPCell cell;
        for (int c = 0; c < reportColumns.length; c++) {
            cell = new PdfPCell(
                    new Paragraph(" ", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));
            cell.setBorder(0);
            cell.setBackgroundColor(totalColor);
            reportBody.addCell(cell);

        }
    }
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildDetilLine</code></h2>
 * /* w w w .  j a v  a 2 s. c  o  m*/
 * <p>
 *  create and print a detail line on the report    
 * </p>
 * 
 * 
 * @param   String [] record - report record to print
 * 
 */
private void buildDetilLine(String[] record) throws DocumentException {
    newpage = isNewPage(++rowCount);
    PdfPCell cell;

    if (record != null) {
        for (int c = 0; c < reportColumns.length; c++) {
            ReportColumn column = (ReportColumn) reportColumns[c];
            String value = " ";

            if (record != null) {
                if (column.getLevelBreak() > 0)
                    value = column.getAccumulator().getPrintValue(newpage);
                else
                    value = record[c];
            }

            cell = new PdfPCell(
                    new Paragraph(value, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));

            cell.setBorder(0);
            cell.setNoWrap(true);

            cell.setBackgroundColor(detailColor);

            if (column.getAlignment().equals(ReportColumn.LEFT))
                cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
            else if (column.getAlignment().equals(ReportColumn.RIGHT))
                cell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
            else
                cell.setHorizontalAlignment(Cell.ALIGN_CENTER);

            reportBody.addCell(cell);

        }
    }
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildReportTitles</code></h2>
 * /*  w  w w . ja v  a2 s  . com*/
 * <p>
 *  Create the report headings        
 * </p>
 * 
 * @param   DataSet reportTable - the report data object
 * 
 */
private void buildReportTitles(DataSet reportTable)
        throws DocumentException, BadElementException, MalformedURLException, IOException {

    Paragraph title = new Paragraph();

    title.add(Image.getInstance(dataAccess.getImagePath() + "reportLogo.gif"));
    title.add(new Chunk(
            new SimpleDateFormat("                           " + "hh:mm:ss - dd MMM yyyy").format(new Date()),
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));

    title.add(new Chunk("           " + reportTable.getStringField(ReportColumn.REPORT_TITLE),
            FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)));

    HeaderFooter header = new HeaderFooter(title, false);
    header.setBorder(0);

    HeaderFooter footer = new HeaderFooter(
            new Phrase("page:", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)), true);
    footer.setAlignment(HeaderFooter.ALIGN_CENTER);

    document.setHeader(header);
    document.setFooter(footer);

    reportColumns = reportTable.getTableVector(ReportColumn.REPORT_DETAILS).toArray();

    topA = new ReportAccumulator(this, -1, reportColumns.length);
    bottomA = topA;

    reportBody = new PdfPTable(reportColumns.length);
    reportBody.setTotalWidth(1.100f);
    reportBody.setHeaderRows(1);

    float cW[] = new float[reportColumns.length];

    for (int c = 0; c < reportColumns.length; c++) {
        ReportColumn column = (ReportColumn) reportColumns[c];
        if (column.getLevelBreak() > 0) {
            ReportAccumulator r = new ReportAccumulator(this, c, reportColumns.length);
            bottomA.setChildAccumulator(r);
            r.setParentAccumulator(bottomA);
            column.setAccumulator(r);
            bottomA = r;
        }

        PdfPCell hdr = new PdfPCell(new Paragraph(column.getDescription(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));

        hdr.setBorder(Rectangle.BOTTOM);
        if (column.getAlignment().equals(ReportColumn.LEFT))
            hdr.setHorizontalAlignment(Cell.ALIGN_LEFT);
        else if (column.getAlignment().equals(ReportColumn.RIGHT))
            hdr.setHorizontalAlignment(Cell.ALIGN_RIGHT);
        else
            hdr.setHorizontalAlignment(Cell.ALIGN_CENTER);

        reportBody.addCell(hdr);
        cW[c] = (float) column.getLength();
    }
    reportBody.setWidths(cW);
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildTotalLine</code></h2>
 * /*from  w  ww .  j a v  a 2 s  .  c  om*/
 * <p>
 *  Create printed total lines        
 * </p>
 * 
 * @param   String[] record - A report total line
 * 
 */
private void buildTotalLine(String[] record) throws DocumentException {
    ++rowCount;
    PdfPCell cell;

    if (record != null) {
        for (int c = 0; c < reportColumns.length; c++) {
            ReportColumn column = (ReportColumn) reportColumns[c];
            String value = record[c];

            cell = new PdfPCell(
                    new Paragraph(value, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));

            cell.setBorder(0);
            cell.setNoWrap(true);

            cell.setBackgroundColor(totalColor);

            if (column.getAlignment().equals(ReportColumn.LEFT))
                cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
            else if (column.getAlignment().equals(ReportColumn.RIGHT))
                cell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
            else
                cell.setHorizontalAlignment(Cell.ALIGN_CENTER);

            reportBody.addCell(cell);

        }
    }
}