1
$\begingroup$

I have created a pdf from two plots with GraphicsColumn and now I need to get rid of the extra whitespace on the sides. Don't use ImageCrop for that because the image loses a lot of quality.

Usually I would use pdfcrop on the terminal to cut out the white space so thought of adding it to the Mathematica Notebook itself. The problem... even though the command works completely fine in my terminal, in the Mathematica Notebook it returns the following error

<|"ExitCode" -> 1, "StandardOutput" -> "PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 
by Heiko \Oberdiek.", "StandardError" -> "!!! Error: Ghostscript exited with error code 1!"|>

I ran it in two different ways. Both return the same error

RunProcess[{"pdfcrop", "file.pdf", "file.pdf"}]
RunProcess[$SystemShell, All, "pdfcrop file.pdf file.pdf"]

Please help as to why Mathematica could be having a problem with Ghostscript.

Also if you could indicate what tags would be appropriate for this post I'd highly appreciate it.

Edit: I am on Ubuntu 17.10, have Ghostscript 9.21, GNU bash 4.4.12(1)-release (x86_64-pc-linux-gnu) and Mathematica 11.

$\endgroup$
  • $\begingroup$ You should add your operating system as well. $\endgroup$ – Szabolcs May 18 '18 at 21:03
  • $\begingroup$ Thanks! I have added that information $\endgroup$ – M.O. May 19 '18 at 13:55
2
$\begingroup$

I am the author of MaTeX, which does call Ghostscript using RunProcess. I (used to) get a lot of support requests about MaTeX (before I included workarounds for most issues).

As I remember, some Linux users had trouble with it for the following reasons:

  • The script that starts up Mathematica will change LD_LIBRARY_PATH on Linux, so that Mathematica can find its own libraries.

  • Ghostscript may use some of the same libraries that Mathematica ships with, but may not work correctly with them (so it just quits on startup).

If this is indeed the problem that you are running into, then the following should work:

$environment = Association@GetEnvironment[]; (* get all environment variables *)
KeyDropFrom[$environment, "LD_LIBRARY_PATH"] (* remove LD_LIBRARY_PATH *)
RunProcess[{"gs", "--version"}, ProcessEnvironment -> $environment]

Let me know if it worked.

If this does not work, try running gs --version from Mathematica (as above, but without ProcessEnviroment) and post the output.

$\endgroup$
  • $\begingroup$ It worked! I honestly thought I wouldnt be able to get an answer! Thank you so much! $\endgroup$ – M.O. May 20 '18 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.