pdfcrop 不起作用

pdfcrop 不起作用

我刚刚更新到 MiKTeX 2.9

我正在使用 Emacs 并运行 pdflatex --shell-escape -interaction=nonstopmode "\input" Instructions.tex

pdfcrop出现以下错误

PDFCROP 1.33, 2012/02/01 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Cannot call ghostscript ("C:\Program Files   (x86)\gs\gs8.71\bin\gswin32c.exe")!

所以我尝试pdfcrop手动调用:

C:\>pdfcrop  --margins 10 --debug Instructions-autopp.pdf s.pdf
PDFCROP 1.33, 2012/02/01 - Copyright (c) 2002-2012 by Heiko Oberdiek.
* Restricted mode: disabled
* Option `pdfversion': auto
* OS name: MSWin32
* Arch name: MSWin32-x86-multi-thread
* System: win
* Not found (gswin32c): gswin32c.exe
* Not found (gswin32c): C:\Perl\site\bin\gswin32c.exe
* Not found (gswin32c): C:\Perl\bin\gswin32c.exe
* Not found (gswin32c): C:\GTK\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\OpenVPN\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gs): gs.exe
* Not found (gs): C:\Perl\site\bin\gs.exe
* Not found (gs): C:\Perl\bin\gs.exe
* Not found (gs): C:\GTK\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\OpenVPN\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Search registry at `HKEY_LOCAL_MACHINE/SOFTWARE/'.
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/8.71/
  GS_DLL = C:\Program Files (x86)\gs\gs8.71\bin\gsdll32.dll
  EXE found: C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe
* Found (via registry): C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe
* Autodetected ghostscript command: C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe
* Input file: Instructions-autopp.pdf
* Output file: s.pdf
* Margins: 10 10 10 10
* PDF header: %PDF-1.4
* Using PDF minor version: 4
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: "C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe" -sDEVICE=bbox -    dBATCH -dNOPA
USE -c save pop -f Instructions-autopp.pdf
* Cleanup
* Temporary files: tmp-pdfcrop-1412.tex
!!! Error: Cannot call ghostscript ("C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe")!
* Cleanup
* Temporary files: tmp-pdfcrop-1412.tex

因此似乎找到了ghostscript,但仍然有错误。 Ghostscript 似乎已正确安装。例如,我可以执行以下操作:

C:\>"C:\Program Files (x86)\gs\gs8.71\bin\gswin32c.exe" -sDEVICE=bbox -dBATCH -d
NOPAUSE -c save pop -f Instructions-autopp.pdf
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 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: 640 577 978 706
%%HiResBoundingBox: 640.053965 577.439982 977.374658 705.834189

我可以尝试什么?

更新

调试输出:

C:\>perl pdfcrop.pl   --margins 10 --debug Instructions-autopp.pdf s.pdf
PDFCROP 1.37, 2012/10/16 - Copyright (c) 2002-2012 by Heiko Oberdiek.
* Restricted mode: disabled
* Option `pdfversion': auto
* Perl executable: C:\Perl64\bin\perl.exe
* Perl version: v5.10.1
* Perl product: ActivePerl, build 1007
* Pointer size: 8
* Pipe support: yes
* Fork support: no
* OS name: MSWin32
* Arch name: MSWin32-x64-multi-thread
* System: win
* Not found (gswin64c): gswin64c.exe
* Not found (gswin64c): C:\Perl64\site\bin\gswin64c.exe
* Not found (gswin64c): C:\Perl64\bin\gswin64c.exe
* Not found (gswin64c): C:\GTK\bin\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\OpenVPN\bin\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\ispell\gswin64c.exe
* Not found (gswin64c): C:\Program Files (x86)\ispell\gswin64c.exe
* Not found (gswin32c): gswin32c.exe
* Not found (gswin32c): C:\Perl64\site\bin\gswin32c.exe
* Not found (gswin32c): C:\Perl64\bin\gswin32c.exe
* Not found (gswin32c): C:\GTK\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\OpenVPN\bin\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gswin32c): C:\Program Files (x86)\ispell\gswin32c.exe
* Not found (gs): gs.exe
* Not found (gs): C:\Perl64\site\bin\gs.exe
* Not found (gs): C:\Perl64\bin\gs.exe
* Not found (gs): C:\GTK\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\OpenVPN\bin\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Not found (gs): C:\Program Files (x86)\ispell\gs.exe
* Search registry at `HKEY_LOCAL_MACHINE/SOFTWARE/'.
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/
* Registry entry found: HKEY_LOCAL_MACHINE/SOFTWARE/GPL Ghostscript/9.06/
  GS_DLL = C:\Program Files\gs\gs9.06\bin\gsdll64.dll
  EXE found: C:\Program Files\gs\gs9.06\bin\gswin64c.exe
* Found (via registry): C:\Program Files\gs\gs9.06\bin\gswin64c.exe
* Autodetected ghostscript command: C:\Program Files\gs\gs9.06\bin\gswin64c.exe
* Input file: Instructions-autopp.pdf
* Output file: s.pdf
* Margins: 10 10 10 10
* PDF header: %PDF-1.4
* Using PDF minor version: 4
* Running ghostscript for BoundingBox calculation ...
* Ghostscript call: "C:\Program Files\gs\gs9.06\bin\gswin64c.exe" -sDEVICE=bbox -dBATCH     -dNOPAUSE -c
 save pop -f Instructions-autopp.pdf
* Cleanup
* Temporary files: tmp-pdfcrop-3284.tex
!!! Error: Cannot call ghostscript `"C:\Program Files\gs\gs9.06\bin\gswin64c.exe"' (Bad
file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable)!
* Cleanup
* Temporary files: tmp-pdfcrop-3284.tex 

路线的具体说明很容易理解! = 找不到指定的路径。

更新脚本的结果:

*** system() ***
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 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: 640 577 978 706
%%HiResBoundingBox: 640.053402 577.439982 977.375220 705.851978
* No error.

*** backticks ***
%%BoundingBox: 640 577 978 706
%%HiResBoundingBox: 640.053402 577.439982 977.375220 705.851978
* No error.
==========
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 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
==========

*** pipe ***
[[GPL Ghostscript 9.06 (2012-08-08)]]
[[Copyright (C) 2012 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: 640 577 978 706
%%HiResBoundingBox: 640.053402 577.439982 977.375220 705.851978
* No error.

*** with stderror redirection ***

*** system() ***
Can't spawn "cmd.exe": No such file or directory at test.pl line 26.
! Exit code: 255

*** backticks ***
! Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable
==========
Use of uninitialized value $result in print at test.pl line 33.
==========

*** pipe ***
! Error: Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable

*** with stderror and stdout redirection ***

*** system() ***
Can't spawn "cmd.exe": No such file or directory at test.pl line 26.
! Exit code: 255

*** backticks ***
! Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable
==========
Use of uninitialized value $result in print at test.pl line 33.
==========

*** pipe ***
! Error: Execution error: Bad file descriptor/Le chemin dÆaccÞs spÚcifiÚ est introuvable

问题似乎是找不到 cmd.exe。我将 c:\windows\system32 放入系统变量 PATH 中,现在一切正常!

(我不知道为什么 c:\windows\system32 不再存在)

非常感谢您的帮助!

答案1

您的 Perl 版本可能存在标准/错误输出重定向问题。请尝试更新。当前版本为 5.16.1.1601。

另外,我还编写了一个测试脚本,尝试使用和不使用重定向的不同执行方法:

#!/usr/bin/env perl
use strict;
$^W=1;

use File::Spec::Functions qw(devnull);
my $null = devnull();

my $prg = '"C:\Program Files\gs\gs9.06\bin\gswin64c.exe"';
# $prg = '"C:\Program Files\gs\gs9.05\bin\gswin32c.exe"';

my $testfile = 'Instructions-autopp.pdf';
# $testfile = 'test.pdf';
my $cmdline =
  "$prg -sDEVICE=bbox -dBATCH -dNOPAUSE -c save pop -f $testfile";

sub analyze {
    if ($? == -1) { print "! Execution error: $!/$^E\n"; }
    elsif ($? & 127) { print sprintf "! Signal: %d\n", $? & 127; }
    elsif ($? != 0) { print sprintf "! Exit code: %d\n", $? >> 8; }
    else { print "* No error.\n"; }
}

sub test {
    print "\n*** system() ***\n";

    system($cmdline);
    analyze();

    print "\n*** backticks ***\n";
    my $result = `$cmdline`;
    analyze();
    print "==========\n";
    print $result;
    print "==========\n";

    print "\n*** pipe ***\n";
    my $ret = open(IN, "$cmdline |");
    if ($ret) {
        while (<IN>) {
            chomp;
            print "[[$_]]\n";
        }
        close(IN);
        analyze();
    }
    else {
        print "! Error: Execution error: $!/$^E\n";
    }
}

test();

print "\n*** with stderror redirection ***\n";
$cmdline .= " 2>&1";
test();

print "\n*** with stderror and stdout redirection ***\n";
$cmdline .= " 1>$null";
test();

1;
__END__

结果(以 win32/ActivePerl 16.0.1 为例):

*** system() ***
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
Page 2
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** backticks ***
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.
==========
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Page 2
==========

*** pipe ***
[[GPL Ghostscript 9.05 (2012-02-08)]]
[[Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.]]
[[This software comes with NO WARRANTY: see the file PUBLIC for details.]]
[[Processing pages 1 through 2.]]
[[Page 1]]
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
[[Page 2]]
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** with stderror redirection ***

*** system() ***
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
Page 2
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** backticks ***
* No error.
==========
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
Page 2
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
==========

*** pipe ***
[[GPL Ghostscript 9.05 (2012-02-08)]]
[[Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.]]
[[This software comes with NO WARRANTY: see the file PUBLIC for details.]]
[[Processing pages 1 through 2.]]
[[Page 1]]
[[%%BoundingBox: 72 696 341 767]]
[[%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977]]
[[Page 2]]
[[%%BoundingBox: 72 95 321 770]]
[[%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977]]
* No error.

*** with stderror and stdout redirection ***

*** system() ***
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
* No error.

*** backticks ***
* No error.
==========
%%BoundingBox: 72 696 341 767
%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977
%%BoundingBox: 72 95 321 770
%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977
==========

*** pipe ***
[[%%BoundingBox: 72 696 341 767]]
[[%%HiResBoundingBox: 72.287998 696.401979 340.685990 766.925977]]
[[%%BoundingBox: 72 95 321 770]]
[[%%HiResBoundingBox: 72.503998 95.147997 320.093990 769.985977]]
* No error.

答案2

我之所以看到这个问题是因为它的标题与我的问题相符,尽管我的错误消息有所不同。之前的答案很有帮助;我添加这个答案是因为它可能会对未来的提问者有所帮助。这也让我有机会感谢@HeikoOberdiek 提供的 pdfcrop。

miktex我在 Windows 7 上运行。我也使用,所以我的机器上cygwin有。直到我将它添加到我的路径中才找到它。仍然失败,所以我检查了:perlpdfcropperlpdfcrop

$ perl -version

This is perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-thread-multi-64int
(with 7 registered patches, see perl -V for more detail)

啊哈。我需要一个perl比附带的更新的cygwin所以我收到了一条消息(见下文)并再次尝试。新消息:没有ghostscript。所以我也收到了。现在pdfcrop运行正常。

C:\eb>pdftex -version
MiKTeX-pdfTeX 2.9.4535 (1.40.13) (MiKTeX 2.9)
Copyright (C) 1982 D. E. Knuth, (C) 1996-2012 Han The Thanh
TeX is a trademark of the American Mathematical Society.

C:\eb>perl --version

This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-mul
hread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Binary build 1603 [296746] provided by ActiveState http://www.ActiveState.co
Built Mar 13 2013 13:31:10

C:\eb>pdfcrop -help
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
...
--gscmd <name>      call of ghostscript   (C:\Program Files\gs\gs9.07\bin\gswin64c.exe)

相关内容