How can I convert .eps file to .pdf in Mathematica

2019-04-14 12:25发布

问题:

How can I convert .eps to .pdf inside Mathematica (perhaps using GhostScript?)?

回答1:

After installing GhostScript and setting appropriate environment variables (for Windows you should add gs\bin and gs\lib to the PATH, where gs is the top-level Ghostscript directory) you can use Jens Nöckel's method for converting .eps to .pdf (all the glyphs will be outlined):

gsEPS2PDF[epsPath_String, pdfPath_String] := 
 Run["gswin64c.exe -sDEVICE=pdfwrite -dNOCACHE -sOutputFile=\"" <> 
   pdfPath <> "\" -q -dbatch -dNOPAUSE \"" <> epsPath <> "\" -c quit"]

Here gswin64c.exe is the name of GhostScript executable for 64bit Windows systems, for Linux replace it with gs.

Another method based on Kurt Pfeifle' code (without font outlining):

gsEPS2PDFEmbedFonts[epsPath_String, pdfOutputPath_String] := 
 Run["gswin64c.exe -sFONTPATH=c:/windows/fonts -o \"" <> 
   pdfOutputPath <> 
   "\" -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress \"" <> epsPath <> 
   "\""]

Here c:/windows/fonts is the directory where fonts are located. See also here for information about GhostScript command line parameters.



回答2:

gr = Import["file.eps", "eps"]
Export["file.pdf", gr, "pdf"]