Remove embedded fonts from a pdf.

gs -sDEVICE=pswrite -sOutputFile=- -q -dNOPAUSE With-Fonts.pdf -c quit | ps2pdf - > No-Fonts.pdf
It's sometimes useful to strip the embedded fonts from a pdf, for importing into something like Inkscape. Be warned, this will increase the size of a pdf substantially. I tried this with only gs writing with -sDEVICE=pdfwrite but it doesn't seem to work, so I just pipe postscript output to ps2pdf for the same effect.

1
By: qubyte
2009-03-25 03:46:00
gs

What Others Think

On my ubuntu/debian system, there is a pdf2ps command (a script), which invokes gs in a similar manner. So you could possibly try this instead: pdf2ps With-Fonts.pdf | ps2pdf - > No-Fonts.pdf I'm somewhat of a novice at this stuff, but I think the "stripping" happens only because postscript *cannot* embed fonts. Usually I want to embed fonts for submission of papers in PDF.
bwoodacre · 633 weeks and 3 days ago
I'm pretty sure postscript embeds fonts. If you look in a ps or eps file you can actually read bits, so like pdf the specification must include standard fonts. I'm not entirely sure how mine works, although I do get the individual flags. I really just added the pipe. It's based on a one liner I saw a long time ago that spat out postscript from postscript.
qubyte · 633 weeks and 3 days ago
I've looked through the manpage for gs 8.61 and can't see how the specified options are asking the postscript interpreter to discard font information. This just seems more like a side effect to me rather than deliberate program action.
bwoodacre · 633 weeks and 3 days ago
Yup. That's pretty much the conclusion that I came to. It could be that you need to add a flag to preserve fonts and that's what's going on. Either way, it's worked for me for years and I've found it very useful. I should note (and sorry this is confusing!) that when I say `remove embeded fonts' what I really mean is turn all the letters into normal vector graphics. This way the file is composed without any reference to text. The obvious side effects are that text in the pdf becomes unselectable and the file size goes up. I do this because Inkscape seems to fall over when it has to handle pdf fonts, and this fixes it.
qubyte · 633 weeks and 3 days ago
I updated it to get rid of a couple of needless bits.
qubyte · 633 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: