Maksym
Maksym

Reputation: 363

Extract fonts from PDF programmatically or by calling external util

I am developing PDF to e-book converter which will run on a server.

I need to programmatically extract embedded fonts from PDF file to finish the project. Now I am able to extract images and text, but to display content in the Flash Player precisely I need the fonts to be extracted from PDF and compiled to SWF to be loaded by Flex application at run time.

I am wondering if it's possible, as such tool as pdf2swf.exe from SWFTools is able to do this. I have decompiled the swf file produced by the tool and there were fonts embedded.

The extracted fonts will be used for displaying the same content from PDF file only, just in Flash player. So i think it will not be any rights violation? Moreover, people who will use the converter have all rights for the PDF files content.

So I see next workflow: 1. Call pdf2swf.exe to produce SWF file with fonts embedded; 2. Call some tool (Which one?) to parse previous SWF to SWFs with separate fonts. 3. Load the SWFs with fonts to Flex application at run time to correctly display content.

It would be great if there is some tool to extract fonts from PDF directly to SWFs.

Upvotes: 0

Views: 957

Answers (3)

131
131

Reputation: 3361

You can extract glyphs (not direct fonts) from PDF using mutools [1].

You can then convert glyphs to fonts using FontForge [2] (beware, crappy)

[1] http://mupdf.googlecode.com/files/mupdf-1.3-windows.zip

[2] http://garr.dl.sourceforge.net/project/fontforge/fontforge-executables/FontForgeSetup_2012-07-31_Windows.exe

Upvotes: 1

mark stephens
mark stephens

Reputation: 449

If the font is subsetted, you will need to use the same subsetting as in the PDF file to make and sense of it.

Upvotes: 1

bhups
bhups

Reputation: 14895

I am not sure there is any free tool that provides direct extraction of font from PDF via CLI. But using first work-flow (using swftools 0.9.0) you can achieve this. Let say you want to do it in ruby:

//extract all the font ids
fontids=`swfextract.exe #{swf_file}|grep Fonts|cut -d\) -f 2|sed -e "s/ //g"`
//extract all the fonts into output.swf
system("swfextract -F #{fontids} #{swf_file}")
.

Upvotes: 1

Related Questions