Let's say I have an "SomeFont.otf" and I want to use the one of the fonts
it holds to write some text into a pdf file and embed the font. The
following code works fine if I have Type 1 font:

    PDFontDescriptorDictionary fd = new PDFontDescriptorDictionary();
    PDType1Font font = new PDType1Font();
    PDDocument doc = //get PDDocument
    PDPage page = //get page

    font.setFontDescriptor(fd);

    File otfFile = new File("SomeFont.otf");
    InputStream in = new FileInputStream(otfFile);
    PDStream fontStream = new PDStream(doc, in, false);
    fontStream.addCompression();
    fd.setFontFile3(fontStream);
    page.getResources().addFont(font);

But what should I do if it's not Type 1? There are appropriate classes for
other font types and a factory which picks right font class reading type
from COSDictionary object if we are reading the font from pdf. How to do
the same thing reading from *.otf file.

Thanks.

Reply via email to