6

We are currently working with a selection of publishers to generate online books from their PDF's. Our legacy app uses flex, so for this we are converting the PDF to SWF files using PDF2SWF by SWFTools.

The problem that we are having is that the text within the SWF document is not being highlighted by our flex reader when the user performs a search. After a quick investigation we found that when extracting text we need to embed the fonts that are used by the PDF document:

http://wiki.swftools.org/wiki/How_do_I_highlight_text_in_the_SWF%3F

pdf2swf -F $YOUR_FONTS_DIR$ -f input.pdf -o output.swf

As you can see from the code above, we need a path to a font directory containig the fonts found within that PDF.

Since we will be converting a large number of PDF's, is it possible to access the font files directly through the PDF rather than having a lot of fonts stored within our app?

Additional Information

Our app is written in Java.

We are currently using PDFBox and Ghostscript within the app, so if any solutions use these libraries than that would be a preferred option, but we are open to all ideas.

1

1 Answer 1

7

PDF files don't contain font 'files' they may not even contain any fonts at all, though this is rare. The embedded font data can be in a bewildering variety of formats:

  • type 1 PostScript fonts
  • type 3 PostScript
  • fonts TrueType fonts
  • PostScript CFF fonts
  • CIDFonts with type 1 PostScript outlines
  • CIDFonts with type 3 PostScript outlines
  • CIDFonts with TrueType outlines
  • CIDFonts with CFF outlines
  • CIDFonts with bitmap images

Will your application be able to read all these font formats ? If you want to use them then you must use the fonts embedded in the PDF file as these will very often be subset fonts, and supplied with a custom Encoding, which means that even if you have the original font, you can't use it because the Encoding will not be correct.

Of course it may be that these PDF files are all created in a consistent way and do not use embedded fonts, but I have my doubts....

5
  • Note that CIDFonts generally don't map to Unicode character codes, so if your PDFs contain these you'll struggle to map document characters to Unicode characters to search for anyway.
    – Rup
    Commented Jan 6, 2012 at 15:14
  • @KenS - thanks for your answer. Your doubts are correct, the PDF's are using embedded subset fonts. I don't suppose you have a source to support your answer? Commented Jan 6, 2012 at 15:16
  • 1
    @Rup - thanks for pointing that out. We're going to be supporting a wide range of languages, but not any script style ones (Japanese, Korean etc) Commented Jan 6, 2012 at 15:20
  • 2
    Not sure which part of my answer you want a source for? The PDF Reference lists all the supported font types. To follow up Rup's answer, any embedded subset font will use character codes which do not correspond to ASCII or Unicode code points. In fact most PDF documents contain text which does not use Unicode. As I maintain the Ghostscript txtwrite device for extracting usable text from PDF I can say with assurance that this is a difficult task and while its possible to get better than 80% reliability, its not possible to extract text from all PDF files. NB CIDFonts are used for Latin too.
    – KenS
    Commented Jan 7, 2012 at 10:02
  • Thanks. Sorry, when I asked I was looking for source supporting the first part of your answer, ie, the variety of formats which the fonts could have been embedded. Thanks again for the great answer, +1 Commented Jan 8, 2012 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.