pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Corinna Kinchin <corinna.kinc...@gmail.com>
Subject Creating PDF files with OTF fonts
Date Mon, 27 Oct 2014 14:29:16 GMT
Good afternoon all!

I have a newbie question which I'm hoping for some help with:

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:

            doc = new PDDocument();

            PDPage page = new PDPage();

            String testOtfFontFile =
            String testTtfFontFile = "c:/windows/fonts/arial.ttf";
            String testPdfFile = "c:/tmp/pdfboxtest.pdf";

            CFFFont font = loadCFFFont(testOtfFontFile);

            PDFont ttfFont = PDTrueTypeFont.loadTTF(doc, new

            PDPageContentStream contentStream = new PDPageContentStream(doc,
            // How to set the CFFFont?
            contentStream.setFont(ttfFont, 12);
            contentStream.moveTextPositionByAmount(100, 700);
            System.out.println(testPdfFile + " created!");

I can load a CFFFont using this code: (loadCFFFont()):

                CFFFont cff = null;
                input = new FileInputStream(file);
                byte[] bytes = IOUtils.toByteArray(input);
                CFFParser cffParser = new CFFParser();
                cff = cffParser.parse(bytes).get(0);

... 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 ...

Thank you!

... Corinna

Palm Gate
Co Kerry
+353 64 66 28964

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message