使用R裁剪空白pdf(任何独立的跨平台解决方案?)

使用R裁剪空白pdf(任何独立的跨平台解决方案?),r,pdf,imagemagick,knitr,R,Pdf,Imagemagick,Knitr,我有一张A4大小的pdf,中间有一张图片,周围有空白。我希望裁剪空白,只保留中间的数字 我在Windows上使用R,并且想要一些跨平台的独立R包解决方案 魔法 我想使用magick软件包,但发现我似乎无法将pdf保存在矢量化文件中(打开了一个问题) 克尼特:绘图作物 我看到knitr有一个名为plot\u crop的函数,它在使用时“使用PDFCrop或ImageMagick裁剪绘图(删除边缘)”,我得到: > knitr::plot_crop("plot.pdf") pdfcrop: T

我有一张A4大小的pdf,中间有一张图片,周围有空白。我希望裁剪空白,只保留中间的数字

我在Windows上使用R,并且想要一些跨平台的独立R包解决方案

魔法 我想使用magick软件包,但发现我似乎无法将pdf保存在矢量化文件中(打开了一个问题)

克尼特:绘图作物 我看到knitr有一个名为
plot\u crop
的函数,它在使用时“使用PDFCrop或ImageMagick裁剪绘图(删除边缘)”,我得到:

> knitr::plot_crop("plot.pdf")
pdfcrop: The Perl interpreter could not be found.
[1] "\"plot.pdf\""
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c pdfcrop "plot.pdf" "plot.pdf"' had status 1 
2: In shell(paste(c(cmd, args), collapse = " ")) :
  'pdfcrop "plot.pdf" "plot.pdf"' execution failed with error code 1
安装perl后,第一次运行代码时出现以下错误:

> knitr::plot_crop("plot.pdf")
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Ghostscript exited with error code 1!

======================================================================
starting package maintenance...
installation directory: C:\Users\junior\AppData\Roaming\MiKTeX\2.9
package repository: http://ftp.heanet.ie/mirrors/ctan.org/tex/systems/win32/miktex/tm/packages/
lightweight database digest: 8462e7c8aae10c40abda758bef7897f9
going to download 13358 bytes
going to install 3 file(s) (1 package(s))
downloading http://ftp.heanet.ie/mirrors/ctan.org/tex/systems/win32/miktex/tm/packages/pdfcrop.tar.lzma...
13358 bytes, 12.24 KB/Sec
extracting files from pdfcrop.tar.lzma...
======================================================================
[1] "\"plot.pdf\""
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c pdfcrop "plot.pdf" "plot.pdf"' had status 13 
2: In shell(paste(c(cmd, args), collapse = " ")) :
  'pdfcrop "plot.pdf" "plot.pdf"' execution failed with error code 13
> knitr::plot_crop("plot.pdf")
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Ghostscript exited with error code 1!
[1] "\"plot.pdf\""
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c pdfcrop "plot.pdf" "plot.pdf"' had status 13 
2: In shell(paste(c(cmd, args), collapse = " ")) :
  'pdfcrop "plot.pdf" "plot.pdf"' execution failed with error code 13
第二次尝试运行代码时出现此错误:

> knitr::plot_crop("plot.pdf")
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Ghostscript exited with error code 1!

======================================================================
starting package maintenance...
installation directory: C:\Users\junior\AppData\Roaming\MiKTeX\2.9
package repository: http://ftp.heanet.ie/mirrors/ctan.org/tex/systems/win32/miktex/tm/packages/
lightweight database digest: 8462e7c8aae10c40abda758bef7897f9
going to download 13358 bytes
going to install 3 file(s) (1 package(s))
downloading http://ftp.heanet.ie/mirrors/ctan.org/tex/systems/win32/miktex/tm/packages/pdfcrop.tar.lzma...
13358 bytes, 12.24 KB/Sec
extracting files from pdfcrop.tar.lzma...
======================================================================
[1] "\"plot.pdf\""
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c pdfcrop "plot.pdf" "plot.pdf"' had status 13 
2: In shell(paste(c(cmd, args), collapse = " ")) :
  'pdfcrop "plot.pdf" "plot.pdf"' execution failed with error code 13
> knitr::plot_crop("plot.pdf")
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Ghostscript exited with error code 1!
[1] "\"plot.pdf\""
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c pdfcrop "plot.pdf" "plot.pdf"' had status 13 
2: In shell(paste(c(cmd, args), collapse = " ")) :
  'pdfcrop "plot.pdf" "plot.pdf"' execution failed with error code 13
还有别的选择吗?
我是否遗漏了其他已知的解决方案?(谢谢)

错误消息显示:

pdfcrop
:找不到Perl解释器


您必须安装Perl:

ImageMagick可以像您一样修剪图像周围的空白。但不幸的是,ImageMagick只是一个光栅处理器。因此,它将光栅化您的输入PDF(通过Ghostscript),修剪光栅数据,然后将光栅数据嵌入到矢量PDF外壳中。因此,您将丢失矢量数据。很抱歉,我不知道有哪个向量到向量处理器可以修剪空白。你也许可以使用potrace重新矢量化,但我没有这样做的经验。糟糕,谢谢。我想知道是否有什么工具可以做到这一点。我只能找到pdfcrop,但它似乎只适用于linux。(附言:在发布问题之前,我已经安装了ActiveState Perl-也许我应该重新启动计算机或其他东西,因为它可能没有在路径上看到Perl)是的,您需要确保
perl
位于
路径上。因此,重新启动Windows会将所需的部分添加到路径中,但现在出现了一个新错误,请参见上面的原始问题。这对我在Windows上的工作很好<代码>系统(“pdfcrop--version”)
返回v1.38。我不知道你的电脑出了什么问题。