I have recently upgraded to El Capitan, and pdfcrop produces an output file, but does not crop the file. Any thoughts?
[Tex/LaTex] After El Capitan upgrade, pdfcrop does not crop pdf files
pdfcrop
Related Solutions
I would do it another way around: (This might actually solve some other issues of you)
Place the whole thing in a savebox in the preamble. (You have to manually enable the normal font use \normalfont
for this AFAIK.) Then you can measure the dimensions of the box and set the page dimensions accordantly. This will give you a PDF or PS which already has to correct size. For larger content I recommend to use a minipage
wrapper as usual.
The \pagecolor
command still works here. I would have thought you manually need to place a colored rectangle (\rule
) with the same size behind the content.
The following works for me using pdflatex
(PDF), latex
->dvips
1 (PS), latex
->dvips
1->ps2pdf
(PDF), xelatex
and lualatex
and produces a correctly sized file.
1 without any options, no -E
required
\documentclass{article}
\usepackage[cmyk]{xcolor}
\pagecolor{cyan}
\pagestyle{empty}
\parindent=0bp
\begin{lrbox}{0}%
\normalfont
\fbox{$\displaystyle E=mc^2 $}%
\end{lrbox}
\sbox0{\raise\dp0\box0}% raise box so it is all height, no depth
%\sbox0{\rlap{\textcolor{cyan}{\rule{\wd0}{\ht0}}}\box0}% \pagecolor surprisingly works so this is not needed
\usepackage[noheadfoot,nomarginpar,margin=0pt,paperwidth=\wd0,paperheight=\ht0]{geometry}
\begin{document}
\box0
\end{document}
Perhaps there is a problem with redirection of standard/error output with your Perl version. Try updating. The current version is 5.16.1.1601.
Also I have written a test script that tries different execution methods with and without redirecting:
#!/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__
The result (example with 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.
Best Answer
Although I couldn't get the pdfcrop perl script to crop the pdfs (http://pdfcrop.sourceforge.net/), a work around is the bash script linked below seems to work: https://askubuntu.com/questions/270493/how-to-crop-a-multi-page-image-scanned-pdf-file-which-wont-crop-with-pdfcrop