Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ghostcript from R

Tags:

r

ghostscript

I am trying to call ghostcript from R to crop pdf files, but cannot make it work. The ghostscript code is working fine when used in a command prompt. The reason for using R and not directly Ghostscrip is that I have to deal with many pdfs that are created from a loop within R.

The code is:

argument<-c("C:\\gs9.06\\bin\\gswin32.exe -sDEVICE=pdfwrite -o C:\\cropped.pdf -c [/CropBox [0.3 12.5 116.2 169] /PAGES pdfmark -f C:\\uncropped.pdf")
system2(command="C:\\WINDOWS\\system32\\cmd.exe", args=argument)

R returns:

'ropBox' is not recognized as an internal or external command,
operable program or batch file.
Warning message:
running command '"C:\WINDOWS\system32\cmd.exe" "C:\\gs9.06\\bin\\gswin32.exe -sDEVICE=pdfwrite -o J:\\Mapinfo\\cropped.pdf -c [/CropBox [0.3 12.5 116.2 169] /PAGES pdfmark -f J:\\Mapinfo\\testing.pdf"' had status 1

It seems that R does not like the "/" sign, but I do not know how to fix this. Any suggestion?

-Vincent

like image 471
Vincent Zintzen Avatar asked Aug 23 '26 06:08

Vincent Zintzen


1 Answers

I think you just need to rearrange your call a bit.

system2("C:\\program.exe",args="-program arguments")

I can't test this on my current machine (run at your own risk), but I think in your instance it would look like:

system2("C:\\gs9.06\\bin\\gswin32c.exe",args="-sDEVICE=pdfwrite -o C:\\cropped.pdf -c [/CropBox [0.3 12.5 116.2 169] /PAGES pdfmark -f C:\\uncropped.pdf")
like image 174
thelatemail Avatar answered Aug 25 '26 22:08

thelatemail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!