You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by ta...@insb.uscourts.gov on 2009/03/23 21:55:34 UTC
How to tell if a font is embedded
I have a Java program, using PDFBox, that scans through a PDF for
unsupported fonts. The support fonts are in a Collection called
this.oFont. I only need to compare fonts that are not embedded. Is there
a way in PDFBox to determine if a font is embedded? Currently, the
program is checking for a plus sign ("+") in the base font. If a plus
sign is found, the font is assumed to be embedded. Below is a chunk of
Java code to scan a PDF for fonts:
loLoop1 = loPdfCatalog.getAllPages().iterator();
// Iterator object for
all pages in catalog
while(loLoop1.hasNext()) { // Process PDF pages...
++lnPdfPage; // Process next page
loPdfPage = (PDPage) loLoop1.next(); // Get PDF page object
////// Check for unsupported fonts
lcRecCode = REC_FONT; // Validating fonts
if (RestrictPDF(lcRecCode)) { // If OK to validate
fonts...
loLoop2 =
loPdfPage.findResources().getFonts().values().iterator();
// Iterator object for
fonts on page
while(loLoop2.hasNext()) { // Process fonts on
page...
lcPdfFont = ((PDFont) loLoop2.next()).getBaseFont();
// Get base font
if (lcPdfFont.indexOf("+") == -1) { // If font is not
embedded...
lcPdfFont = lcPdfFont.replaceAll("\\W.*", "");
// Remove extra
information from base font
if (!this.oFont.contains(lcPdfFont)) {
// If font is not
supported...
HandleError(new Throwable(lcPdfFont), lcRecCode,
lnPdfPage);
// Generate an error
this.oFont.add(lcPdfFont); // Prevent font from
being reported again
}
}
}
}
Thanks in advance for your help!
Tim