2

I am trying to load .woff and .woff2 fonts and getting below exception. Help me to resolve this.

Note: I can't attach the font file since not having permission to share.

public void pdfExport() {    
        try {
            PDFont font = PDType1Font.TIMES_ROMAN;
            PDDocument document = new PDDocument();
            File file = new File("C:\\Users\\Desktop\\font_test\\font.woff");
            String path = file.getAbsolutePath();
            if (!StringUtils.isBlank(path)) {
                font = PDType0Font.load(document, file);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

An exception is below.

java.io.IOException: head is mandatory at org.apache.fontbox.ttf.TTFParser.parseTables(TTFParser.java:181) at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:150) at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:106) at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:78)

Romil Patel
  • 12,879
  • 7
  • 47
  • 76
Richard
  • 90
  • 11
  • 1
    PDFBox doesn't support woff. It supports TrueType fonts. Convert it to TrueType. – Tilman Hausherr May 21 '19 at 15:56
  • Thanks for your reply @TilmanHausherr . Is there any other jar/java method available to use .woff and .woff2 font types without converting it to .ttf type? – Richard May 22 '19 at 14:39
  • 1
    Sorry, I don't know (and certainly not in PDFBox). I googled for "convert woff to truetype" and that gives results, but I have not tried any of these myself. – Tilman Hausherr May 22 '19 at 15:57
  • @TilmanHausherr Do you have any idea on below qustion? https://stackoverflow.com/questions/56526107/how-to-draw-square-in-pdf-if-any-character-not-available-in-the-font-file-using – Richard Jun 11 '19 at 04:15

0 Answers0