pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Lehmkuehler <andr...@lehmi.de>
Subject Re: How to get the font type that an otf file holds?
Date Sun, 14 Apr 2013 17:18:24 GMT
Hi,

Am 11.04.2013 17:09, schrieb Vladimir Starostenkov:
> 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.
I'm afraid the font support is limited to Type1 and Truetype fonts, see [1], [2]

> Thanks.

BR
ANdreas Lehmkühler

[1] 
http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
[2] 
http://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java

Mime
View raw message