Search code examples
pdffontspostscript

Determine fonts used in postscript (.ps) file


Given a postscript file that has the following header

%!PS-Adobe-3.0

I would like to list all fonts used in the file. The output does not have to be perfect, but I need to make sure I get all references to any font being used. I am aware there are different types of fonts, and that a font may or may not be embedded in the postscript file.

My current best idea is to grep/search for the word Font case insensitively and go from there.

  • Will this get me all the font references?
  • Any better way to achieve this?

I tend to use .NET/C# for development purposes, but any solution is appreciated.

Thanks,

Bernard

UPDATE: lhf's answer solved the problem, due to formatting and length constraints I am adding a working usage example based on his recommendations.

Windows batch file that can be saved to a .cmd file and run from the command prompt:

REM Prerequisites: 
REM - GPL Ghostscript 8.64 @ http://pages.cs.wisc.edu/~ghost/doc/GPL/gpl864.htm
REM - pdffonts @ 3.02pl4 win32 download @ http://www.foolabs.com/xpdf/download.html

REM Add directories to path, contains ps2pdf and its dependency gswin32c.exe
SET PATH=%PATH%;C:\Program Files\gs\gs8.64\lib;C:\Program Files\gs\gs8.64\bin
REM Add pdffonts directory to path
SET PATH=%PATH%;c:\temp\path-toxpdf-3.02pl4-win32

REM Convert postscript file to pdf file
call ps2pdf input.ps temp.pdf

REM list pdf file fonts
call pdffonts temp.pdf

Sample output:

name                                 type              emb sub uni object ID 
------------------------------------ ----------------- --- --- --- ---------
DQRDAA+BCC128Medium-Identity-H       CID TrueType      yes yes no      21  0
MIAVUG+Verdana-Identity-H            CID TrueType      yes yes no      13  0
BKNKQN+Verdana-Identity-H            CID TrueType      yes yes no      10  0

Solution

  • Convert the file to pdf and then use pdffonts if you have it.

    If you're into PS programming, you could run a mock PS intepreter (in PS) that ignores most things except findfont.