You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Benjamin Eder (Jira)" <ji...@apache.org> on 2020/07/30 12:22:00 UTC
[jira] [Commented] (PDFBOX-2482) Support for creating PDF
containing OTF fonts
[ https://issues.apache.org/jira/browse/PDFBOX-2482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17167877#comment-17167877 ]
Benjamin Eder commented on PDFBOX-2482:
---------------------------------------
I am currently testing for a project whether we can use OTF fonts with PDFBox. It is working just fine using:
{code:java}
OTFParser otfParser = new OTFParser();
OpenTypeFont otf = otfParser.parse(new File("C:/Users/beder/Downloads/code/CODE Light.otf"));
PDFont font = PDType0Font.load(document, otf, false);
{code}
Since support for subsetting is not there yet (https://issues.apache.org/jira/browse/PDFBOX-3758) we have to set the third parameter of PDType0Font.load(..) to false. The resulting PDF is of course a bit bigger, but that is not a blocker for me.
> Support for creating PDF containing OTF fonts
> ---------------------------------------------
>
> Key: PDFBOX-2482
> URL: https://issues.apache.org/jira/browse/PDFBOX-2482
> Project: PDFBox
> Issue Type: New Feature
> Components: FontBox, Writing
> Affects Versions: 2.0.0
> Reporter: Corinna Kinchin
> Priority: Major
> Fix For: 3.0.0 PDFBox
>
>
> Good morning!
> I have tried posting this question on the users list and stackOverflow, but no luck ... other than Tilman Hausher's suggestion that I log an enhancement request ... so here it is - it would be beyond wonderful if you might consider supporting OTF fonts in PDF.
> Here's the background - I've just (last week) downloaded the latest PDFbox source from github and am trying to create a HelloWorldOTF.java, based on the HelloWorldTTF.java example, with the hope of creating a PDF file which uses an OTF font (in this case, Adobe Caslon Pro Regular) to add text to the output PDF.
> Here's what I have so far:
> {code:java}
> doc = new PDDocument();
> PDPage page = new PDPage();
> doc.addPage(page);
> String testOtfFontFile = "c:/windows/fonts/ACaslonPro-Regular.otf";
> String testTtfFontFile = "c:/windows/fonts/arial.ttf";
> String testPdfFile = "c:/tmp/pdfboxtest.pdf";
> CFFFont font = loadCFFFont(testOtfFontFile);
> PDFont ttfFont = PDTrueTypeFont.loadTTF(doc, new File(testTtfFontFile));
> PDPageContentStream contentStream = new PDPageContentStream(doc,
> page);
> contentStream.beginText();
> // How to set the CFFFont?
> contentStream.setFont(ttfFont, 12);
> contentStream.moveTextPositionByAmount(100, 700);
> contentStream.drawString(text);
> contentStream.endText();
> contentStream.close();
> doc.save(testPdfFile);
> System.out.println(testPdfFile + " created!");
> {code}
> I can load a CFFFont using this code: (loadCFFFont()):
> {code:java}
> CFFFont cff = null;
> input = new FileInputStream(file);
> byte[] bytes = IOUtils.toByteArray(input);
> CFFParser cffParser = new CFFParser();
> cff = cffParser.parse(bytes).get(0);
> {code}
> ... but can't for the life of me figure out how to get from a CFFFont to a PDFont in order to be able to use it to set the font via setFont().
> Any help or pointers would be hugely appreciated ...
> Thanks a million for reading this far ;)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org