Example usage for com.lowagie.text Font Font

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

Introduction

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

Prototype


public Font(int family, float size, int style) 

Source Link

Document

Constructs a Font.

Usage

From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java

License:Educational Community License

public EvalPDFReportBuilder(OutputStream outputStream) {
    document = new Document();
    try {/*from ww w . j  a v a  2 s  .  c o m*/
        pdfWriter = PdfWriter.getInstance(document, outputStream);
        pdfWriter.setStrictImageSequence(true);
        document.open();

        // attempting to handle i18n chars better
        // BaseFont evalBF = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H,
        // BaseFont.EMBEDDED);
        // paragraphFont = new Font(evalBF, 9, Font.NORMAL);
        // paragraphFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL);

        titleTextFont = new Font(Font.TIMES_ROMAN, 22, Font.BOLD);
        boldTextFont = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
        questionTextFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD);
        paragraphFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL);
        paragraphFontBold = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD);
        frontTitleFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, frontTitleSize, Font.NORMAL);
        frontAuthorFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.NORMAL);
        frontInfoFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.NORMAL);
    } catch (Exception e) {
        throw UniversalRuntimeException.accumulate(e, "Unable to start PDF Report");
    }
}

From source file:org.silverpeas.components.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) {
    try {//  www  .  j  av  a2s. c om
        String activity = "";
        if (step.getResolvedState() != null) {
            State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState());
            activity = resolvedState.getLabel(getRole(), getLanguage());
        }

        String sAction;
        try {
            if ("#question#".equals(step.getAction())) {
                sAction = getString("processManager.question");
            } else if ("#response#".equals(step.getAction())) {
                sAction = getString("processManager.response");
            } else if ("#reAssign#".equals(step.getAction())) {
                sAction = getString("processManager.reAffectation");
            } else {
                Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction());
                sAction = action.getLabel(getRole(), getLanguage());
            }
        } catch (WorkflowException we) {
            sAction = "##";
        }

        String actor = step.getUser().getFullName();

        String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage());

        String header = "";
        if (StringUtil.isDefined(activity)) {
            header += activity + " - ";
        }
        header += sAction + " (" + actor + " - " + date + ")";

        Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL);

        PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader));
        pCell.setFixedHeight(28);
        pCell.setBackgroundColor(new Color(239, 239, 239));
        pCell.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPTable pTable = new PdfPTable(1);
        pTable.setWidthPercentage(100);
        pTable.addCell(pCell);

        document.add(pTable);
    } catch (Exception e) {
        SilverLogger.getLogger(this).error(e.getMessage(), e);
    }
}

From source file:org.silverpeas.components.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepContent(HistoryStep step, com.lowagie.text.Document document) {
    try {//from ww w . ja  v  a2  s . co m
        Form form;
        if ("#question#".equals(step.getAction()) || "#response#".equals(step.getAction())) {
            // TODO
            form = null;
        } else {
            form = getProcessInstance().getProcessModel().getPresentationForm(step.getAction(), getRole(),
                    getLanguage());
        }

        XmlForm xmlForm = (XmlForm) form;
        if (xmlForm != null && step.getActionRecord() != null) {
            DataRecord data = step.getActionRecord();

            // Force simpletext displayers because itext cannot display HTML Form fields (select,
            // radio...)
            float[] colsWidth = { 25, 75 };
            PdfPTable tableContent = new PdfPTable(colsWidth);
            tableContent.setWidthPercentage(100);
            String fieldValue = "";
            Font fontLabel = new Font(Font.HELVETICA, 10, Font.BOLD);
            Font fontValue = new Font(Font.HELVETICA, 10, Font.NORMAL);
            List<FieldTemplate> fieldTemplates = xmlForm.getFieldTemplates();
            for (FieldTemplate fieldTemplate1 : fieldTemplates) {
                try {
                    GenericFieldTemplate fieldTemplate = (GenericFieldTemplate) fieldTemplate1;

                    String fieldLabel = fieldTemplate.getLabel("fr");
                    Field field = data.getField(fieldTemplate.getFieldName());
                    String componentId = step.getProcessInstance().getProcessModel().getModelId();

                    // wysiwyg field
                    if ("wysiwyg".equals(fieldTemplate.getDisplayerName())) {
                        String file = WysiwygFCKFieldDisplayer.getFile(componentId,
                                getProcessInstance().getInstanceId(), fieldTemplate.getFieldName(),
                                getLanguage());

                        // Extract the text content of the html code
                        Source source = new Source(new FileInputStream(file));
                        fieldValue = source.getTextExtractor().toString();
                    } // Field file type
                    else if (FileField.TYPE.equals(fieldTemplate.getDisplayerName())
                            && StringUtil.isDefined(field.getValue())) {
                        SimpleDocument doc = AttachmentServiceProvider.getAttachmentService()
                                .searchDocumentById(new SimpleDocumentPK(field.getValue(), componentId), null);
                        if (doc != null) {
                            fieldValue = doc.getFilename();
                        }
                    } // Field date type
                    else if ("date".equals(fieldTemplate.getTypeName())) {
                        fieldValue = DateUtil.getOutputDate(field.getValue(), "fr");
                    } // Others fields type
                    else {
                        fieldTemplate.setDisplayerName("simpletext");
                        fieldValue = field.getValue(getLanguage());
                    }

                    PdfPCell cell = new PdfPCell(new Phrase(fieldLabel, fontLabel));
                    cell.setBorderWidth(0);
                    cell.setPaddingBottom(5);
                    tableContent.addCell(cell);

                    cell = new PdfPCell(new Phrase(fieldValue, fontValue));
                    cell.setBorderWidth(0);
                    cell.setPaddingBottom(5);
                    tableContent.addCell(cell);
                } catch (Exception e) {
                    SilverLogger.getLogger(this).error(e.getMessage(), e);
                }
            }
            document.add(tableContent);
        }
    } catch (Exception e) {
        SilverLogger.getLogger(this).error(e.getMessage(), e);
    }
}

From source file:org.tn5250jlpr.SCS2PDF.java

License:Open Source License

public void openOutputFile(String path) {
    try {/* w  ww .  j  av a  2s . c  o  m*/
        System.out.println("Opening file");
        if (document == null) {
            document = new Document();
            bos = PdfWriter.getInstance(document, new FileOutputStream(path + ".pdf"));
            //            document.setPageSize(new Rectangle(0.0f,
            //                                                0.0f,
            //                                                getPointFromInches(13),
            //                                                getPointFromInches(11)));

            BaseFont bf = BaseFont.createFont("Courier", "Cp1252", false);
            font = new Font(bf, 11, Font.NORMAL);
        }
    } catch (IOException _ex) {
        System.out.println("Cannot open");

    } catch (Exception _ex) {
        System.out.println("Cannot open");
    }

}

From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java

License:Apache License

/**
 * @param table/*from   ww w.j  av a  2 s.co m*/
 * @param footer
 * @param header
 * @return
 */
public PdfPTable pdfExport(Table table) {
    TableExportOptions exportOptions = table.getExportOptions();
    boolean showOnlyDisplayed = exportOptions.isShowOnlyDisplayedColumns();
    Font headfont = new Font(Font.UNDEFINED, Font.DEFAULTSIZE, Font.BOLD);

    Font bodyfont = new Font(exportOptions.getPdfFontSize(), exportOptions.getPdfFontSize(), Font.NORMAL);
    if (exportOptions.getPdfFontColour() != null) {
        Color fontColor = exportOptions.getPdfFontColour();
        bodyfont.setColor(fontColor);
        headfont.setColor(fontColor);
    }

    List<ITableColumn> columns = getTableColumns(showOnlyDisplayed, table);
    int columnCount = 0;
    for (int i = 0; i < columns.size(); i++) {
        TableColumn c = (TableColumn) columns.get(i);
        //hide select checkbox column
        if (!c.isExporatble())
            continue;

        columnCount++;

    }
    PdfPTable resulttable = new PdfPTable(columnCount);
    resulttable.setWidthPercentage(100f);

    if (StringUtils.isNotEmpty(exportOptions.getTableHeadline())) {
        PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableHeadline()));
        cell.setColspan(columns.size());
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);
    }

    for (int i = 0; i < columns.size(); i++) {
        TableColumn c = (TableColumn) columns.get(i);
        // hide select checkbox column
        if (!c.isExporatble())
            continue;

        String cellData = TextService.getString(c.getTitle());
        if (cellData.contains("<br/>") || cellData.contains("<br>")) {
            cellData = cellData.replaceAll("<br\\/>", "\\/");
            cellData = cellData.replaceAll("<br>", "\\/");
        }
        PdfPCell cell = new PdfPCell(new Paragraph((cellData), headfont));
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);

    }

    List tabledata = table.getDefaultModel().getFilteredList();
    if (tabledata.isEmpty()) {
        for (int i = 0; i < columns.size(); i++) {
            resulttable.addCell(new PdfPCell((new Phrase(""))));
        }
    }

    for (Iterator it = tabledata.iterator(); it.hasNext();) {
        DataBag dbag = (DataBag) it.next();
        for (int i = 0; i < columns.size(); i++) {
            TableColumn tableColumn = (TableColumn) columns.get(i);
            if (!tableColumn.isExporatble())
                continue;
            logger.debug("property: " + tableColumn.getProperty());
            IColumnRenderer renderer = tableColumn.getRenderer();
            Converter converter = tableColumn.getConverter();

            addObjectCell(bodyfont, resulttable, dbag, tableColumn, renderer, converter);
        }
    }

    if (StringUtils.isNotEmpty(exportOptions.getTableFooter())) {
        PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableFooter()));
        cell.setColspan(columnCount);
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);
    }

    resulttable.setHeaderRows(1);
    return resulttable;

}

From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java

License:Apache License

public void writeTo(Table table, OutputStream out) {
    TableExportOptions exportOptions = table.getExportOptions();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // set the page orientation Din-A4 Portrait or Landscape
    Rectangle page = PageSize.A4;
    if (exportOptions.getPdfPosition() != null
            && exportOptions.getPdfPosition().equals(TableExportOptions.PDF_LANDSCAPE)) {
        // landscape position
        page = PageSize.A4.rotate();/*from   www  .j ava  2 s  .  co  m*/
    } else if (exportOptions.getPdfPosition() != null
            && exportOptions.getPdfPosition().equals(TableExportOptions.PDF_PORTRAIT)) {
        // portrait position
        page = PageSize.A4;
    }
    if (exportOptions.getPdfPageColour() != null) {
        // page.setBackgroundColor(exportOptions.getPdfPageColour());
    }

    Document document = new Document(page);
    document.setMargins(36f, 36f, 50f, 40f);
    try {
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new PDFEvent(table));
        document.open();
        if (StringUtils.isNotEmpty(exportOptions.getHeadline())) {
            Font titleFont = new Font(Font.UNDEFINED, 18, Font.BOLD);
            Paragraph paragraph = new Paragraph(exportOptions.getHeadline(), titleFont);
            paragraph.setAlignment(Element.ALIGN_CENTER);
            document.add(paragraph);
            document.add(new Paragraph(" "));
            document.add(new Paragraph(" "));
        }

        PdfPTable pdftable = pdfExport(table);
        document.add(pdftable);
        document.newPage();
        document.close();

        baos.writeTo(out);
        out.flush();
        baos.close();
    } catch (DocumentException e) {
        logger.error("Error creating document!", e);
        throw new RuntimeException(e);
    } catch (IOException e) {
        logger.error("Error creating document!", e);
        throw new RuntimeException(e);
    } finally {

    }
}

From source file:oscar.eform.util.EFormPDFServlet.java

License:Open Source License

private void writeContent(Properties printCfg, Properties props, Properties measurements, float height,
        PdfContentByte cb) throws Exception {
    for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) {
        StringBuilder temp = new StringBuilder(e.nextElement().toString());
        String[] cfgVal = printCfg.getProperty(temp.toString()).split(" *, *");

        String[] fontType = null;
        int fontFlags = 0;
        if (cfgVal[4].indexOf(";") > -1) {
            fontType = cfgVal[4].split(";");
            if (fontType[1].trim().equals("italic"))
                fontFlags = Font.ITALIC;
            else if (fontType[1].trim().equals("bold"))
                fontFlags = Font.BOLD;
            else if (fontType[1].trim().equals("bolditalic"))
                fontFlags = Font.BOLDITALIC;
            else/* w  w w . j a v a2 s  .c  o m*/
                fontFlags = Font.NORMAL;
        } else {
            fontFlags = Font.NORMAL;
            fontType = new String[] { cfgVal[4].trim() };
        }

        String encoding = null;
        if (fontType[0].trim().equals("BaseFont.HELVETICA")) {
            fontType[0] = BaseFont.HELVETICA;
            encoding = BaseFont.CP1252; //latin1 encoding
        } else if (fontType[0].trim().equals("BaseFont.HELVETICA_OBLIQUE")) {
            fontType[0] = BaseFont.HELVETICA_OBLIQUE;
            encoding = BaseFont.CP1252;
        } else if (fontType[0].trim().equals("BaseFont.ZAPFDINGBATS")) {
            fontType[0] = BaseFont.ZAPFDINGBATS;
            encoding = BaseFont.ZAPFDINGBATS;
        } else {
            fontType[0] = BaseFont.COURIER;
            encoding = BaseFont.CP1252;
        }

        BaseFont bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED);
        String propValue = props.getProperty(temp.toString());
        //if not in regular config then check measurements
        if (propValue == null) {
            propValue = measurements.getProperty(temp.toString(), "");
        }

        ColumnText ct = new ColumnText(cb);
        // write in a rectangle area
        if (cfgVal.length >= 9) {
            Font font = new Font(bf, Integer.parseInt(cfgVal[5].trim()), fontFlags);
            ct.setSimpleColumn(Integer.parseInt(cfgVal[1].trim()),
                    (height - Integer.parseInt(cfgVal[2].trim())), Integer.parseInt(cfgVal[7].trim()),
                    (height - Integer.parseInt(cfgVal[8].trim())), Integer.parseInt(cfgVal[9].trim()),
                    (cfgVal[0].trim().equals("left") ? Element.ALIGN_LEFT
                            : (cfgVal[0].trim().equals("right") ? Element.ALIGN_RIGHT : Element.ALIGN_CENTER)));

            ct.setText(new Phrase(12, propValue, font));
            ct.go();
            continue;
        }

        // draw line directly
        if (temp.toString().startsWith("__$line")) {
            cb.setRGBColorStrokeF(0f, 0f, 0f);
            cb.setLineWidth(Float.parseFloat(cfgVal[4].trim()));
            cb.moveTo(Float.parseFloat(cfgVal[0].trim()), Float.parseFloat(cfgVal[1].trim()));
            cb.lineTo(Float.parseFloat(cfgVal[2].trim()), Float.parseFloat(cfgVal[3].trim()));
            cb.stroke();

        } else if (temp.toString().startsWith("__")) {
            cb.beginText();
            cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
            cb.showTextAligned(
                    (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                            : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                    : PdfContentByte.ALIGN_CENTER)),
                    (cfgVal.length >= 7 ? (cfgVal[6].trim()) : propValue), Integer.parseInt(cfgVal[1].trim()),
                    (height - Integer.parseInt(cfgVal[2].trim())), 0);
            cb.endText();
        } else { // write prop text
            cb.beginText();
            cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim()));
            cb.showTextAligned(
                    (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT
                            : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT
                                    : PdfContentByte.ALIGN_CENTER)),
                    (cfgVal.length >= 7 ? ((propValue.equals("") ? "" : cfgVal[6].trim())) : propValue),
                    Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0);

            cb.endText();
        }
    }
}

From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java

License:Open Source License

/**
 * Prints the consultation request.//from w ww  .  ja  v  a 2s.  com
 * @throws IOException when an error with the output stream occurs
 * @throws DocumentException when an error in document construction occurs
 */
public void printPdf() throws IOException, DocumentException {

    // Create the document we are going to write to
    document = new Document();
    PdfWriter.getInstance(document, os);

    document.setPageSize(PageSize.LETTER);
    document.addTitle(getResource("msgConsReq"));
    document.addCreator("OSCAR");
    document.open();

    // Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    headerFont = new Font(bf, 14, Font.BOLD);
    infoFont = new Font(bf, 12, Font.NORMAL);
    font = new Font(bf, 9, Font.NORMAL);
    boldFont = new Font(bf, 10, Font.BOLD);
    bigBoldFont = new Font(bf, 12, Font.BOLD);

    createConsultationRequest();

    document.close();
}

From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.EctConsultationFormRequestPrintPdf.java

License:Open Source License

private float addDynamicPositionedText(String name, String text, float dynamicHeight,
        EctConsultationFormRequestUtil reqForm) throws DocumentException, IOException {
    if (text != null && text.length() > 0) {
        Font boldFont = new Font(bf, FONTSIZE, Font.BOLD);
        Font font = new Font(bf, FONTSIZE, Font.NORMAL);
        float lineCount = (name.length() + text.length()) / 100;

        // if there is not enough room on the page for the text start on the next page
        if ((height - 264 - dynamicHeight - lineCount * LINEHEIGHT) < LINEHEIGHT * 3) {
            nextPage(reqForm);/*from w w  w  .j  a va2s  . co  m*/
            dynamicHeight = LINEHEIGHT - 152;
        }

        ct.setSimpleColumn(new Float(85), height - 264 - dynamicHeight - lineCount * LINEHEIGHT, new Float(526),
                height - 250 - dynamicHeight, LINEHEIGHT, Element.ALIGN_LEFT);
        ct.addText(new Phrase(name, boldFont));
        ct.addText(new Phrase(text, font));
        ct.go();
        dynamicHeight += lineCount * LINEHEIGHT + LINEHEIGHT * 2;
    }

    return dynamicHeight;
}

From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.EctConsultationFormRequestPrintPdf.java

License:Open Source License

private void setAppointmentInfo(EctConsultationFormRequestUtil reqForm) throws DocumentException {

    printClinicData(reqForm);//from  w  ww  .  ja v  a  2  s.  co m
    Font font = new Font(bf, FONTSIZE, Font.NORMAL);

    // Set consultant info
    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.referalDate, 190, height - 112, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT,
            reqForm.urgency.equals("1") ? "Urgent" : (reqForm.urgency.equals("2") ? "Non-Urgent" : "Return"),
            190, height - 125, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getServiceName(reqForm.service), 190, height - 139,
            0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getSpecailistsName(reqForm.specialist), 190,
            height - 153, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specPhone, 190, height - 166, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specFax, 190, height - 181, 0);
    cb.endText();
    ct.setSimpleColumn(new Float(190), height - 223, new Float(290), height - 181, LINEHEIGHT,
            Element.ALIGN_LEFT);
    ct.addText(new Phrase(reqForm.specAddr.replaceAll("<br>", "\n"), font));
    ct.go();

    // Set patient info
    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientName, 385, height - 112, 0);
    cb.endText();
    ct.setSimpleColumn(new Float(385), height - 153, new Float(585), height - 112, LINEHEIGHT,
            Element.ALIGN_LEFT);
    ct.addText(new Phrase(reqForm.patientAddress.replaceAll("<br>", " "), font));
    ct.go();

    cb.beginText();
    cb.setFontAndSize(bf, FONTSIZE);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientPhone, 385, height - 166, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientDOB, 385, height - 181, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, (reqForm.patientHealthCardType + " "
            + reqForm.patientHealthNum + " " + reqForm.patientHealthCardVersionCode).trim(), 440, height - 195,
            0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT,
            reqForm.appointmentHour + ":" + reqForm.appointmentMinute + " " + reqForm.appointmentPm + " "
                    + reqForm.appointmentDay + "/" + reqForm.appointmentMonth + "/" + reqForm.appointmentYear,
            440, height - 208, 0);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientChartNo, 385, height - 222, 0);
    cb.endText();
}