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
I think you just need to rearrange your call a bit.
I can’t test this on my current machine (run at your own risk), but I think in your instance it would look like: