Mohammed Mostafa
Mohammed Mostafa

Reputation: 71

Check embedded fonts in pdf using PDFBox

Please, I want to know which fonts extracted from pdf is embedded or not, how can I do this using PDFBox?

Upvotes: 2

Views: 6851

Answers (2)

Balin
Balin

Reputation: 81

In PDFBox2, you would get the fonts and their embedded-status like this:

PDResources resources = page.getResources();
Iterator<COSName> ite = resources.getFontNames();
while (ite.hasNext()) {
    COSName name = ite.next();
    PDFont font = resources.getFont(name);
    boolean isEmbedded = font.isEmbedded();
    // ... do something with the results ...
}

I found no way, though, to find out which characters of the font are embedded, and which are not.

Upvotes: 3

Khinsu
Khinsu

Reputation: 1487

May be you find an answere here

or

To get all fonts, you have to iterate through pdf pages and extract font as below:

PDDocument  doc = PDDocument.load("C:/test.pdf");
List<PDPage> pages = doc.getDocumentCatalog().getAllPages();
for(PDPage page:pages){
    Map<String,PDFont> pageFonts=page.getResources().getFonts();
}

Upvotes: 2

Related Questions