27

I have PDF graphic in which I would like to have fonts removed. All other properties of the file should remain (such as size, etc). The output file should be in PDF as well. The text itself should be converted to outlines.

Can I do it at the moment of including the PDF figure in pdftex document? Or can I perhaps use a magic ghostscript command?

lockstep
  • 250,273
ronszon
  • 773
  • 4
    This looks like a duplicate of http://tex.stackexchange.com/questions/23407/how-can-i-convert-text-to-paths-with-pdflatex – Joseph Wright Sep 03 '11 at 08:03
  • Well, because this is a figure and not a page, the output after pdf2ps and then ps2pdf is a full-page document. The size has been lost... – ronszon Sep 03 '11 at 08:25
  • 3
    Do you mean that you have a lot of white space around the figure? So the final step can be to use pdfcrop (included in TeXLive, don't know in MikTeX). – Spike Sep 03 '11 at 08:53
  • Brilliant! That does what I wanted. I will update the question with an answer. – ronszon Sep 03 '11 at 10:02
  • 2
    Rather than answering your question within the question itself, you should add a separate answer. – lockstep Sep 03 '11 at 12:05

5 Answers5

23

Following this answer, you should use the following command for the new (9.15+) ghostscript

*nix

gs -dNoOutputFonts -sDEVICE=pdfwrite -o vectorized_file.pdf file.pdf

Win

gswin32 -dNoOutputFonts -sDEVICE=pdfwrite -o vectorized_file.pdf file.pdf

Himura
  • 903
  • 3
    As of Feburary 7 2017, this was the only correct solution on this page (with a version of gs at least 9.15). – gui11aume Feb 07 '17 at 17:35
15

In my case (pdftops 0.18.4, GPL Ghostscript 9.05) the resulting PDF following the above answer still contained the fonts and the text was not converted to curves. However, the answer I found at this Malaysian LaTeX User Group site worked for me. This is the script I used:

#!/bin/sh

if [ "x$1" = "x" -o "x$2" = "x" ]; then
    echo Usage: `basename "$0"` "<input.pdf>" "<output.pdf>" >&2
    exit 1
fi

gs -sDEVICE=pswrite -dNOCACHE -sOutputFile=- -q -dbatch \
   -dNOPAUSE -dQUIET "$1" -c quit | ps2pdf - "$2"

Of course, a pdfcrop step can still be added if you need it.

If this gives you an error use -sDEVICE ps2write

mindriot
  • 401
  • Excellent! None of the answers in the linked questions worked. Your script does work. – Emit Taste Jun 25 '14 at 15:23
  • Thank you! If the OP is available, I would certainly nominate this post for being the appropriate and most effective answer. – eacousineau Oct 08 '14 at 21:11
  • 1
    Hmm... On Ubuntu 14.04 with gs 9.10, using -sDEVICE=ps2write with the final ps2pdf conversion does not seem to keep the text as paths. I will look for some solutions. – eacousineau Jan 13 '15 at 18:34
  • 3
    Looks like using pdf2svg with a SVG to PDF conversion tool (perhaps with Inkscape) does the job! From a Launchpad Bug Report. – eacousineau Jan 13 '15 at 18:44
  • @eacousineau It does, but pdf2svg is obviously unable to use float numbers properly, because my graphics got destroyed by the utility. Anyways, this answer is out-dated, it doesn't work in gs9+. – yo' Apr 20 '15 at 08:56
  • @eacousineau This worked perfectly for me with the same setup (Ubuntu 14.04, gs 9.10, -sDEVICE=ps2write with the final ps2pdf conversion) – Grodriguez Sep 07 '17 at 10:13
  • 1
    @yo' It does work for me with gs 9.10. – Grodriguez Sep 07 '17 at 10:13
5

(Originally posted as part of question by OP ronszon)

The solution to the problem was conversion from PDF to PS, PS to PDF and cropping final PDF file.

pdftops myfile.pdf
ps2pdf myfile.ps
pdfcrop myfile.pdf
lockstep
  • 250,273
4

Another alternative is using pdf2svg, as indicated here: Launchpad Bug Report. In Ubuntu, you can install it as sudo apt-get install pdf2svg

My overarching goal in reading this post was to be able to edit the raw paths of the PDF in Inkscape, so this accomplishes my goal quite well.

EDIT:

As a succinct command, you can add the following command:

pdf-text-to-path() { name=${1%.[Pp][Dd][Ff]}; pdf2svg $1 $name.raw.svg; inkscape --export-pdf=$name.raw.pdf $name.raw.svg; }

The command pdf-text-to-path $name.pdf will generate $name.raw.svg and then use inkscape to convert the SVG to PDF in $name.raw.pdf. (Note: You will need Inkscape, which is admittedly bulky. convert seems to rasterize the image.)

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. I don't see how this produces a PDF file? As well, it would be nice to make the answer self-contained, i.e., to show how exactly can pdf2svg be used to accomplish the goal of the question. – yo' Jan 13 '15 at 19:09
  • Thank you for the suggestions! I've made the corresponding adjustments. – eacousineau Jan 14 '15 at 16:31
  • Nice, thanks. Just: (1) Yes, convert is from ImageMagick which is a raster image processor. (2) inkscape knows to modify the dimensions of the PDF file if this is done, just so slightly, yet it can change the output significantly. – yo' Jan 14 '15 at 16:45
1

The -sDEVICE=pswrite output driver in Ghostscript has been deprecated since 12/15/2010. In Ghostscript versions >= 9.09, use ps2write or eps2write.

Werner
  • 603,163
niels
  • 27
  • 1
    The question is 3 years old. You should tell that gs could have changed also options etc. Does it (I do not know)? BTW: Welcome to TeX.SE! – Mensch Dec 10 '14 at 17:48
  • 1
    This does not convert the fonts, it keeps them there! And FWIW, it has always been the case for gs9+. – yo' Apr 20 '15 at 08:56