You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by hamena314 <ha...@freenet.de> on 2016/08/16 19:25:17 UTC

How to implement OTF-fonts into a PDF with Apache PDFBox 2.x?

Hey there!

I am trying to use an OTF-font for creating a PDF with PDFBox 2.0.2 in 
Java 8.

I've tried different methods and read what google could find, but it was 
not that much to this topic: 
http://stackoverflow.com/questions/26651261/using-pdfbox-to-create-pdf-referencing-otf-fonts

|String pfbPath = "MyFont.otf"; PDFont font = new PDType1Font(doc, new 
FileInputStream(pfbPath)); |

Leaves a blank PDF, since I am using a .otf and not a .pfb.

This wont work either, PDFBox ignores the font and loads one of the 
standard fonts:

|PDType0Font font = PDType0Font.load(doc, new File("MyFont.otf")); |

||Implementing and using normal .ttf-files works fine, but I have no 
clue how to deal with an .otf.

I know that I simply could take an online-converter and create a 
.ttf-file from the .otf, but the font was created by an external company 
and their license does not seem to allow any modification to the font or 
the file itself.

Since the referenced StackOverflow-question is more than a year old, is 
it now somehow possible to use OTF-Fonts while creating a PDF?

Thanks in advance!

Kind regards,

Marcus

Re: How to implement OTF-fonts into a PDF with Apache PDFBox 2.x?

Posted by John Hewson <jo...@jahewson.com>.
> On 16 Aug 2016, at 13:48, Tilman Hausherr <TH...@t-online.de> wrote:
> 
> Am 16.08.2016 um 21:25 schrieb hamena314:
>> |PDType0Font font = PDType0Font.load(doc, new File("MyFont.otf")); | 
> 
> 
> I wonder if this would work:
> 
> OTFParser otfp = new OTFParser(true);
> TrueTypeFont ttf = otfp.parse(new File("MyFont.otf"));
> PDType0Font font = PDType0Font.load(doc, ttf, true);

No, it won’t. Unfortunately we don’t support embedding OTFs. One reason for this is that we don’t have an OTF subsetter.

— John

> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: How to implement OTF-fonts into a PDF with Apache PDFBox 2.x?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 16.08.2016 um 21:25 schrieb hamena314:
> |PDType0Font font = PDType0Font.load(doc, new File("MyFont.otf")); | 


I wonder if this would work:

OTFParser otfp = new OTFParser(true);
TrueTypeFont ttf = otfp.parse(new File("MyFont.otf"));
PDType0Font font = PDType0Font.load(doc, ttf, true);




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org