以下命令在 pdf 文件上执行 ghostscript。(pdf_file
变量包含该pdf的路径)
bbox <- system(paste( "C:/gs/gs8.64/bin/gswin32c.exe -sDEVICE=bbox -dNOPAUSE -dBATCH -f", pdf_file, "2>&1" ), intern=TRUE)
执行后bbox
包括以下字符串。
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
然后对该字符串进行操作,以便隔离 BoundingBox 尺寸 (36 2544 248 2825) 并用于裁剪 pdf 文件。到目前为止一切正常。
但是,当我在任务管理器中安排这个脚本(使用 Rscript.exe 或 Rcmd.exe BATCH),或者当脚本在 R 块中并且我按knit HTML
时,bbox 会获取以下缺少 BoundingBox 信息的字符串,并使其不可用:
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
我怎样才能克服这个问题并让脚本自动运行?
(脚本来自该问题的公认答案)