Example usage for com.lowagie.text.pdf BaseFont createFont

List of usage examples for com.lowagie.text.pdf BaseFont createFont

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BaseFont createFont.

Prototype

public static BaseFont createFont(String name, String encoding, boolean embedded)
        throws DocumentException, IOException 

Source Link

Document

Creates a new font.

Usage

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Write the findings to the protocol./*  w w  w.j a  va2 s .  c o  m*/
 * 
 * @param protocol
 *            the protocol
 * @param attachExtRefs
 *            true if the external references should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the findings to the protocol
 */
protected void writeFindings(Protocol protocol, boolean attachExtRefs) throws ExportException {
    try {
        /*
         * Define fonts
         */
        Font plainFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9, Font.NORMAL,
                Color.WHITE);

        Font boldFontTitle = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10,
                Font.NORMAL, Color.WHITE);

        Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                10);

        Font boldFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font italicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        Font boldItalicFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

        /*
         * Write findings
         */
        PdfPTable tableBase = new PdfPTable(1);
        tableBase.setWidthPercentage(100);
        tableBase.setSplitRows(false);
        tableBase.getDefaultCell().setBorderWidth(0);
        tableBase.getDefaultCell().setPadding(0);

        for (Finding f : protocol.getFindings()) {
            tableBase.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 1));
            PdfPCell cellFinding = new PdfPCell();
            cellFinding.setBorderColor(Color.GRAY);
            cellFinding.setBorderWidth(0.5f);

            PdfPTable tableTitle = new PdfPTable(3);
            tableTitle.setWidthPercentage(100);

            /*
             * Print title of the finding
             */
            Phrase phraseTitle = new Phrase(translate("Finding") + " " + f.getId(), boldFontTitle);

            PdfPCell cellTitle = new PdfPCell(phraseTitle);
            cellTitle.setBackgroundColor(bgColorTitle);
            cellTitle.setBorderWidth(0);
            cellTitle.setPadding(padding);
            cellTitle.setPaddingBottom(padding * 1.5f);
            cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT);

            tableTitle.addCell(cellTitle);

            /*
             * Print severity of the finding
             */
            Phrase phraseSeverity = new Phrase(findMgmt.getLocalizedSeverity(f), plainFontTitle);

            PdfPCell cellSeverity = new PdfPCell(phraseSeverity);
            cellSeverity.setBackgroundColor(bgColorTitle);
            cellSeverity.setBorderWidth(0);
            cellSeverity.setPadding(padding);
            cellSeverity.setPaddingTop(padding * 1.1f);
            cellSeverity.setHorizontalAlignment(Element.ALIGN_CENTER);

            tableTitle.addCell(cellSeverity);

            /*
             * Print the meeting date and time of the finding
             */
            String meetingDate = sdfDate.format(protocol.getDate().getTime());

            PdfPCell cellMeeting = new PdfPCell(new Phrase(meetingDate, plainFontTitle));
            cellMeeting.setBackgroundColor(bgColorTitle);
            cellMeeting.setBorderWidth(0);
            cellMeeting.setPadding(padding);
            cellMeeting.setPaddingTop(padding * 1.1f);
            cellMeeting.setHorizontalAlignment(Element.ALIGN_RIGHT);

            tableTitle.addCell(cellMeeting);

            /*
             * Description
             */
            Phrase phraseDesc = new Phrase(f.getDescription(), plainFont);
            phraseDesc.setLeading(leading);

            PdfPCell cellDesc = new PdfPCell();
            cellDesc.addElement(phraseDesc);
            cellDesc.setBorderWidth(0);
            cellDesc.setPadding(padding);
            cellDesc.setColspan(3);

            tableTitle.addCell(cellDesc);

            cellFinding.addElement(tableTitle);

            /*
             * List point used for lists
             */
            Phrase phraseListPoint = new Phrase("", boldFont);
            phraseListPoint.setLeading(leading * 0.93f);

            PdfPCell cellListPoint = new PdfPCell();
            cellListPoint.addElement(phraseListPoint);
            cellListPoint.setBorderWidth(0);
            cellListPoint.setPadding(padding);
            cellListPoint.setPaddingLeft(padding * 2);

            /*
             * Table of references
             */
            if (f.getReferences().size() > 0
                    || (f.getExternalReferences().size() > 0 && attachExtRefs == true)) {
                PdfPTable tableRefs = new PdfPTable(new float[] { 0.04f, 0.96f });
                tableRefs.setWidthPercentage(100);

                PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("References:"), boldItalicFont));
                cellRefTitle.setBorderWidth(0);
                cellRefTitle.setPadding(padding);
                cellRefTitle.setPaddingTop(padding * 3);
                cellRefTitle.setPaddingBottom(0);
                cellRefTitle.setColspan(2);

                tableRefs.addCell(cellRefTitle);

                /*
                 * Textual references
                 */
                for (String ref : f.getReferences()) {
                    Phrase phraseRef = new Phrase(ref, plainFont);
                    phraseRef.setLeading(leading);

                    PdfPCell cellRef = new PdfPCell();
                    cellRef.addElement(phraseRef);
                    cellRef.setBorderWidth(0);
                    cellRef.setPadding(padding);

                    tableRefs.addCell(cellListPoint);

                    tableRefs.addCell(cellRef);
                }

                /*
                 * External file references
                 */
                if (attachExtRefs == true) {
                    for (File ref : findMgmt.getExtReferences(f)) {
                        Phrase phraseRef = new Phrase();
                        phraseRef.add(new Chunk(ref.getName(), plainFont));
                        phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont));
                        phraseRef.setFont(plainFont);
                        phraseRef.setLeading(leading);

                        PdfPCell cellRef = new PdfPCell();
                        cellRef.addElement(phraseRef);
                        cellRef.setBorderWidth(0);
                        cellRef.setPadding(padding);

                        tableRefs.addCell(cellListPoint);

                        cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref));

                        tableRefs.addCell(cellRef);
                    }
                }

                cellFinding.addElement(tableRefs);
            }

            /*
             * Table of aspects
             */
            if (f.getAspects().size() > 0) {
                PdfPTable tableAspects = new PdfPTable(new float[] { 0.04f, 0.96f });
                tableAspects.setWidthPercentage(100);

                PdfPCell cellAspTitle = new PdfPCell(new Phrase(translate("Aspects:"), boldItalicFont));
                cellAspTitle.setBorderWidth(0);
                cellAspTitle.setPadding(padding);
                cellAspTitle.setPaddingTop(padding * 3);
                cellAspTitle.setPaddingBottom(0);
                cellAspTitle.setColspan(2);

                tableAspects.addCell(cellAspTitle);

                for (String asp : f.getAspects()) {
                    Phrase phraseAsp = new Phrase(asp, plainFont);
                    phraseAsp.setLeading(leading);

                    PdfPCell cellAsp = new PdfPCell();
                    cellAsp.addElement(phraseAsp);
                    cellAsp.setBorderWidth(0);
                    cellAsp.setPadding(padding);

                    tableAspects.addCell(cellListPoint);

                    tableAspects.addCell(cellAsp);
                }

                cellFinding.addElement(tableAspects);
            }

            /*
             * Vertical strut at the end of the table
             */
            PdfPTable tableStrut = new PdfPTable(1);
            tableStrut.setWidthPercentage(100);
            tableStrut.addCell(createVerticalStrut(padding, 1));

            cellFinding.addElement(tableStrut);

            tableBase.addCell(cellFinding);
        }

        pdfDoc.add(tableBase);
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot put findings into the PDF document."));
    }
}

From source file:org.revager.export.ReviewProtocolPDFExporter.java

License:Open Source License

@Override
protected void writeContent() throws ExportException {
    try {// w w w  .j  a  v  a2 s.co m
        /*
         * Write the title page of the protocol
         */
        writeTitlePage(Application.getInstance().getMeetingMgmt().getMeetings(), attachProdExtRefs);

        /*
         * Write attendees of the whole review
         */
        int numOfAtts = Application.getInstance().getAttendeeMgmt().getNumberOfAttendees();

        if (showSignFields == true && numOfAtts > 0) {
            Font introFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED),
                    10);

            pdfDoc.newPage();

            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100);

            PdfPCell cellSignIntro = new PdfPCell(new Phrase(
                    translate("The following persons participated in the whole review:"), introFont));
            cellSignIntro.setBorderWidth(0);
            cellSignIntro.setPadding(padding);
            cellSignIntro.setPaddingBottom(PDFTools.cmToPt(0.8f));

            table.addCell(cellSignIntro);

            pdfDoc.add(table);

            writeAttendees(null, false, false, true);
        }

        /*
         * Write the meetings of this review
         */
        for (Meeting m : Application.getInstance().getMeetingMgmt().getMeetings()) {

            Protocol prot = m.getProtocol();

            if (prot != null) {
                pdfDoc.newPage();

                writeMeeting(m, attachFindExtRefs, false);
            }
        }
    } catch (Exception e) {
        /*
         * Not part of unit testing because this exception is only thrown if
         * an internal error occurs.
         */
        throw new ExportException(translate("Cannot create PDF document."));
    }
}

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

License:Educational Community License

public void addTitlePage(String evaltitle, String groupNames, String startDate, String endDate,
        String responseInformation, byte[] bannerImageBytes, String evalSystemTitle, String informationTitle) {
    try {//from  w  w  w.  j a va 2 s.  co  m
        float pagefooter = paragraphFont.getSize();

        PdfContentByte cb = pdfWriter.getDirectContent();

        float docMiddle = (document.right() - document.left()) / 2 + document.leftMargin();

        Paragraph emptyPara = new Paragraph(" ");
        emptyPara.setSpacingAfter(100.0f);

        // Title
        Paragraph titlePara = new Paragraph("\n\n\n" + evaltitle, frontTitleFont);
        titlePara.setAlignment(Element.ALIGN_CENTER);
        document.add(titlePara);

        // Groups

        Paragraph groupPara = new Paragraph(groupNames, frontAuthorFont);
        groupPara.setSpacingBefore(25.0f);
        groupPara.setAlignment(Element.ALIGN_CENTER);
        document.add(groupPara);

        // Little info area? I don't know, it was on the mockup though
        Paragraph infoPara = new Paragraph(informationTitle, frontInfoFont);
        infoPara.setAlignment(Element.ALIGN_CENTER);
        infoPara.setSpacingBefore(90.0f);
        document.add(infoPara);

        // Started on
        Paragraph startedPara = new Paragraph(startDate, frontInfoFont);
        startedPara.setAlignment(Element.ALIGN_CENTER);
        startedPara.setSpacingBefore(25.0f);
        document.add(startedPara);

        // Ended on
        Paragraph endedPara = new Paragraph(endDate, frontInfoFont);
        endedPara.setAlignment(Element.ALIGN_CENTER);
        endedPara.setSpacingBefore(25.0f);
        document.add(endedPara);

        // Reply Rate
        Paragraph replyRatePara = new Paragraph(responseInformation, frontInfoFont);
        replyRatePara.setAlignment(Element.ALIGN_CENTER);
        replyRatePara.setSpacingBefore(25.0f);
        document.add(replyRatePara);

        // Logo and Tagline
        cb.beginText();
        cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, evalSystemTitle, docMiddle, document.bottom() + 20, 0);
        cb.endText();

        if (bannerImageBytes != null) {
            Image banner = Image.getInstance(bannerImageBytes);
            cb.addImage(banner, banner.getWidth(), 0, 0, banner.getHeight(),
                    docMiddle - (banner.getWidth() / 2), document.bottom() + 35);
        }

        document.newPage();

        responseArea = new ColumnText(cb);
        responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2,
                document.bottom() + pagefooter);
        responseArea.go();
    } catch (DocumentException | IOException de) {
        throw UniversalRuntimeException.accumulate(de, "Unable to create title page");
    }
}

From source file:org.sonar.report.pdf.Events.java

License:Open Source License

private void printPageNumber(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();//from www .j  a v  a  2  s. com
    float textBase = document.bottom() - 20;
    try {
        cb.setFontAndSize(BaseFont.createFont("Helvetica", BaseFont.WINANSI, false), 12);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    cb.beginText();
    cb.setTextMatrix(document.right() - 10, textBase);
    cb.showText(String.valueOf(writer.getPageNumber()));
    cb.endText();
    cb.saveState();
}

From source file:org.sonarqube.report.extendedpdf.ExtendedEvents.java

License:Open Source License

private void printPageNumber(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();// ww  w .j  a v  a2 s .  c  om
    float textBase = document.bottom() - 45;
    try {
        cb.setFontAndSize(BaseFont.createFont("Helvetica", BaseFont.WINANSI, false), 12);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    cb.beginText();
    cb.setTextMatrix(document.right() - 10, textBase);
    cb.showText(String.valueOf(writer.getPageNumber()));
    cb.endText();
    cb.saveState();
}

From source file:org.tn5250j.spoolfile.SpoolExportWizard.java

License:Open Source License

/**
 * Open the correct type of output file depending on selection(s)
 *//*from ww  w .j  a va2s  .c o m*/
public void openOutputFile() {

    try {

        // update status
        updateStatus("Opening File");

        // default to txt extention
        String suffix = ".txt";
        String fileName = "";

        // if pdf then change to pdf extenstion
        if (cvtType.getSelectedIndex() == 0)
            suffix = ".pdf";

        // for e-mailing setup a temporary file
        if (email.isSelected()) {
            File dir = new File(System.getProperty("user.dir"));

            //  setup the temp file name
            String tempFile = spooledFile.getText().trim() + '_' + jobName.getText().trim() + '_'
                    + user.getText().trim() + '_' + spooledFileNumber.getText().trim() + '_'
                    + number.getText().trim();

            // create the temporary file
            File f = File.createTempFile(tempFile, suffix, dir);

            System.out.println(f.getName());
            System.out.println(f.getCanonicalPath());

            conicalPath = f.getCanonicalPath();

            // set it to delete on exit
            f.deleteOnExit();

            // create the file
            fw = new FileOutputStream(f);
        } else

        if (ifs.isSelected()) {
            fileName = ifsPathInfo.getText().trim();
            ifsfw = new IFSFileOutputStream(splfile.getSystem(), fileName);
        } else {
            fileName = pcPathInfo.getText().trim();
            fw = new FileOutputStream(fileName);
        }

        // if not PDF then this is all we have to do so return
        if (cvtType.getSelectedIndex() > 0)
            return;

        // On pdf's then we need to create a PDF document
        if (document == null) {

            document = new Document();

            // create the pdf writer based on selection of pc or ifs file
            if (ifs.isSelected()) {
                bos = PdfWriter.getInstance(document, ifsfw);
            } else {
                bos = PdfWriter.getInstance(document, fw);
            }

            // create the base font
            BaseFont bf = BaseFont.createFont("Courier", "Cp1252", false);

            // set the default size of the font to 9.0
            float fontsize = 9.0f;

            // if we have a font selectd then try to use it
            if (fontSize.getText().length() > 0)
                fontsize = Float.parseFloat(fontSize.getText().trim());

            // create the pdf font to use within the document
            font = new com.lowagie.text.Font(bf, fontsize, com.lowagie.text.Font.NORMAL);

            // set the PDF properties of the supplied properties
            if (author.getText().length() > 0)
                document.addAuthor(author.getText());
            if (title.getText().length() > 0)
                document.addTitle(title.getText());
            if (subject.getText().length() > 0)
                document.addSubject(subject.getText());

            // set the page sizes and the page orientation
            String ps = (String) pageSize.getSelectedItem();

            if (ps.equals("A3")) {
                if (portrait.isSelected())
                    document.setPageSize(PageSize.A3);
                else
                    document.setPageSize(PageSize.A3.rotate());

            }

            if (ps.equals("A4")) {
                if (portrait.isSelected())
                    document.setPageSize(PageSize.A4);
                else
                    document.setPageSize(PageSize.A4.rotate());
            }

            if (ps.equals("A5")) {
                if (portrait.isSelected())
                    document.setPageSize(PageSize.A5);
                else
                    document.setPageSize(PageSize.A5.rotate());
            }
            if (ps.equals("LETTER")) {
                if (portrait.isSelected())
                    document.setPageSize(PageSize.LETTER);
                else
                    document.setPageSize(PageSize.LETTER.rotate());
            }
            if (ps.equals("LEGAL")) {
                if (portrait.isSelected())
                    document.setPageSize(PageSize.LEGAL);
                else
                    document.setPageSize(PageSize.LEGAL.rotate());
            }
            if (ps.equals("LEDGER")) {
                if (portrait.isSelected())
                    document.setPageSize(PageSize.LEDGER);
                else
                    document.setPageSize(PageSize.LEDGER.rotate());
            }
        }
    } catch (IOException _ex) {
        System.out.println("Cannot open 1 " + _ex.getMessage());

    } catch (Exception _ex2) {
        System.out.println("Cannot open 2 " + _ex2.getMessage());
    }

}

From source file:org.tn5250jlpr.SCS2PDF.java

License:Open Source License

public void openOutputFile(String path) {
    try {//from  w ww .j  a va2s . 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.unitime.timetable.util.PdfFont.java

License:Open Source License

private static Font createFont(float size, boolean fixed, boolean bold, boolean italic) {
    String font = null;/*from   w  w  w .  j  av a2 s.c o  m*/
    if (fixed)
        font = ApplicationProperty.PdfFontFixed.value();
    else if (bold) {
        if (italic)
            font = ApplicationProperty.PdfFontBoldItalic.value();
        else
            font = ApplicationProperty.PdfFontBold.value();
    } else if (italic)
        font = ApplicationProperty.PdfFontItalic.value();
    else
        font = ApplicationProperty.PdfFontNormal.value();
    if (font != null && !font.isEmpty()) {
        try {
            BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true);
            if (base != null)
                return new Font(base, size);
        } catch (Throwable t) {
        }
    }
    font = (fixed ? ApplicationProperty.PdfFontFixed.value() : ApplicationProperty.PdfFontNormal.value());
    if (font != null && !font.isEmpty()) {
        try {
            BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true);
            if (base != null)
                return new Font(base, size, italic && bold ? Font.BOLDITALIC
                        : italic ? Font.ITALIC : bold ? Font.BOLD : Font.NORMAL);
        } catch (Throwable t) {
        }
    }
    if (fixed)
        return FontFactory.getFont(bold ? italic ? FontFactory.COURIER_BOLDOBLIQUE : FontFactory.COURIER_BOLD
                : italic ? FontFactory.COURIER_OBLIQUE : FontFactory.COURIER, size);
    else
        return FontFactory
                .getFont(bold ? italic ? FontFactory.HELVETICA_BOLDOBLIQUE : FontFactory.HELVETICA_BOLD
                        : italic ? FontFactory.HELVETICA_OBLIQUE : FontFactory.HELVETICA, size);
}

From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java

License:Open Source License

/**
 * Utility method which uses iText libraries to determine the family name(s) for the font at the given path.
 * The iText APIs seem to indicate there can be more than one name, but this method will return a set of them.
 * Use a name from this list when referencing the font in CSS for PDF output. Note that family names as reported
 * by iText may vary from those reported by the AWT Font class, e.g. "Arial Unicode MS" for iText and
 * "ArialUnicodeMS" for AWT./* ww  w .  j a  v a2  s . c  o  m*/
 *
 * @param path local path to the font file
 * @param encoding same as what you would use for {@link #addFont(String, String, boolean)}
 * @param embedded same as what you would use for {@link #addFont(String, String, boolean)}
 * @return set of all family names for the font file, as reported by iText libraries
 */
public static Set getDistinctFontFamilyNames(String path, String encoding, boolean embedded) {
    BaseFont font = null;
    try {
        font = BaseFont.createFont(path, encoding, embedded);
        String[] fontFamilyNames = TrueTypeUtil.getFamilyNames(font);
        Set distinct = new HashSet();
        for (int i = 0; i < fontFamilyNames.length; i++) {
            distinct.add(fontFamilyNames[i]);
        }
        return distinct;
    } catch (DocumentException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java

License:Open Source License

public void addFont(String path, String fontFamilyNameOverride, String encoding, boolean embedded,
        String pathToPFB) throws DocumentException, IOException {
    String lower = path.toLowerCase();
    if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
        BaseFont font = BaseFont.createFont(path, encoding, embedded);

        String[] fontFamilyNames;
        if (fontFamilyNameOverride != null) {
            fontFamilyNames = new String[] { fontFamilyNameOverride };
        } else {/*from w ww.  ja v a2 s  . c  om*/
            fontFamilyNames = TrueTypeUtil.getFamilyNames(font);
        }

        for (int i = 0; i < fontFamilyNames.length; i++) {
            String fontFamilyName = fontFamilyNames[i];
            FontFamily fontFamily = getFontFamily(fontFamilyName);

            FontDescription descr = new FontDescription(font);
            try {
                TrueTypeUtil.populateDescription(path, font, descr);
            } catch (Exception e) {
                throw new XRRuntimeException(e.getMessage(), e);
            }

            fontFamily.addFontDescription(descr);
        }
    } else if (lower.endsWith(".ttc")) {
        String[] names = BaseFont.enumerateTTCNames(path);
        for (int i = 0; i < names.length; i++) {
            addFont(path + "," + i, fontFamilyNameOverride, encoding, embedded, null);
        }
    } else if (lower.endsWith(".afm") || lower.endsWith(".pfm")) {
        if (embedded && pathToPFB == null) {
            throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
        }

        BaseFont font = BaseFont.createFont(path, encoding, embedded, false, null, readFile(pathToPFB));

        String fontFamilyName;
        if (fontFamilyNameOverride != null) {
            fontFamilyName = fontFamilyNameOverride;
        } else {
            fontFamilyName = font.getFamilyFontName()[0][3];
        }

        FontFamily fontFamily = getFontFamily(fontFamilyName);

        FontDescription descr = new FontDescription(font);
        // XXX Need to set weight, underline position, etc.  This information
        // is contained in the AFM file (and even parsed by Type1Font), but
        // unfortunately it isn't exposed to the caller.
        fontFamily.addFontDescription(descr);
    } else {
        throw new IOException("Unsupported font type");
    }
}