The following command executes ghostscript on a pdf file. (the pdf_file
variable contains the path to that pdf)
bbox <- system(paste( "C:/gs/gs8.64/bin/gswin32c.exe -sDEVICE=bbox -dNOPAUSE -dBATCH -f", pdf_file, "2>&1" ), intern=TRUE)
After execution bbox
includes the following character string.
GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 36 2544 248 2825
%%HiResBoundingBox: 36.395015 2544.659922 247.070032 2824.685914
Error: /undefinedfilename in (2>&1)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1147/1684(ro)(G)-- --dict:1/20(G)-- --dict:69/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.64: Unrecoverable error, exit code 1
This string is then manipulated in order for the BoundingBox dimensions (36 2544 248 2825) to be isolated and used for cropping the pdf file. So far everything works ok.
However, when I schedule this script in Task Manager (using Rscript.exe or Rcmd.exe BATCH), or when the script is inside an R chunk and I press knit HTML
, bbox gets the following character string which lacks the BoundingBox information, and makes it unusable:
GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Error: /undefinedfilename in (2>&1)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1147/1684(ro)(G)-- --dict:1/20(G)-- --dict:69/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
How can I get over this problem and have the script run automated?
(The script comes from the accepted answer to that question)