summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2008-04-10 00:04:30 +0000
committerKarl Berry <karl@freefriends.org>2008-04-10 00:04:30 +0000
commit746495bc89836f195951c403990bc5a54e0cc187 (patch)
treef5752077bea32f1addfc8dde3e9c2ad0e8ce466c /Master/texmf-dist
parentd1adbe679a00856057b13139dbb9bc678ff74dd5 (diff)
pdfcrop 1.9 (7apr08), and switch to ctan2tl updating
git-svn-id: svn://tug.org/texlive/trunk@7371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/generic/pdfcrop/README147
-rw-r--r--Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl369
2 files changed, 516 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/generic/pdfcrop/README b/Master/texmf-dist/doc/generic/pdfcrop/README
new file mode 100644
index 00000000000..19d55cdcd5a
--- /dev/null
+++ b/Master/texmf-dist/doc/generic/pdfcrop/README
@@ -0,0 +1,147 @@
+README for pdfcrop 2008/04/05 v1.9
+
+TABLE OF CONTENTS
+=================
+A. Description
+B. Copyright, Disclaimer, License
+C. Files
+D. Requirements
+E. Installation
+F. User Interface
+G. Author
+H. Acknowledgement
+I. Questions, Suggested Improvements
+J. Known Problems
+K. History
+L. ToDo
+
+A. DESCRIPTION
+==============
+PDFCROP takes a PDF file as input, calculates the BoundingBox
+for each page by the help of ghostscript and generates a output
+PDF file with removed margins.
+
+B. COPYRIGHT, DISCLAIMER, LICENSE
+=================================
+Copyright (C) 2002, 2004, 2005, 2008 Heiko Oberdiek.
+
+This program may be distributed and/or modified under the
+conditions of the LaTeX Project Public License, either version 1.2
+of this license or (at your option) any later version.
+The latest version of this license is in
+ http://www.latex-project.org/lppl.txt
+and version 1.2 or later is part of all distributions of LaTeX
+version 1999/12/01 or later.
+
+C. FILES
+========
+The project `pdfcrop' consists of two files:
+pdfcrop.pl: This perl script is the main program. The extension
+ `.pl' may be omitted.
+README: Documentation, the file you are reading.
+
+Following temporary files are produced if `pdfcrop' is invoked:
+tmp-pdfcrop-*.tex: input file for pdfTeX
+tmp-pdfcrop-*.log: log file of pdfTeX run
+tmp-pdfcrop-*.pdf: result after pdfTeX run
+
+D. REQUIREMENTS
+===============
+* Perl5 (version 5 of the perl interpreter)
+* Ghostscript (>= 8.0 if PDF file contains rotated pages)
+* pdfTeX, version >= 1.0 (because of page selecting and \pdfximage syntax)
+
+E. INSTALLATION
+===============
+
+1. Perl script `pdfcrop.pl':
+
+ TDS 1.1 location:
+ * texmf/scripts/pdfcrop/pdfcrop.pl
+ * and a directory that is part of PATH contains a wrapper script
+ or link with name "pdfcrop".
+
+ Unix
+ * It is allowed to rename `pdfcrop.pl' to `pdfcrop':
+ mv pdfcrop.pl pdfcrop
+ * Ensure that the execute permission is set:
+ chmod +x pdfcrop
+ * Move the file to a directory where the shell can find it
+ (environment variable PATH, e.g. /usr/local/bin/).
+
+ Dos/Windows/(OS2)
+ * See requirements. I do not expect that the perl script
+ run under DOS or Windows. With cygwin it can work however.
+
+2. Documentation `README':
+
+ Copy it to an appropriate place, for example
+ `/usr/local/share/doc/pdfcrop/README'.
+ I is allowed to rename it to `pdfcrop.txt'.
+
+ TDS location:
+ somewhere below texmf/doc/... (?)
+
+F. USER INTERFACE
+=================
+* ToDo: User manual
+* Online help:
+ pdfcrop --help
+* Ghostscript's calculation of the bounding box is faster,
+ if --resolution 72 is used instead of ghostscript's implicite
+ default setting of 4000 DPI (hint from Ionut Georgescu).
+ Of course the calculation with higher resolution settings are
+ more accurate.
+
+G. AUTHOR
+=========
+Heiko Oberdiek
+Email: oberdiek@uni-freiburg.de
+
+H. ACKNOWLEDGEMENT
+==================
+Anthony Williams
+Scott Pakin <pakin@uiuc.edu>
+Ionut Georgescu
+Yves J\"ager
+
+I. QUESTIONS, SUGGESTED IMPROVEMENTS
+====================================
+If you have questions, problems with `pdfcrop', error reports,
+if you have improvements or want to have additional features,
+please send them to the author.
+
+My environment for developing and testing:
+* linux, SuSE 9.0
+* perl v5.8.1
+* pdfeTeX 3.141592-1.21a-2.1
+* Ghostscript 8.x
+
+J. KNOWN PROBLEMS
+=================
+* Perl must support open("-|"). Not every perl port supports this
+ for older windows (win95, win98).
+
+K. HISTORY
+==========
+2002/10/30 v1.0: First release
+2002/10/30 v1.1: Option --hires added.
+2002/11/04 v1.2: "nul" instead of "/dev/null" for windows.
+2002/11/23 v1.3: Use of File::Spec module's "devnull" call.
+2002/11/29 v1.4: Option --papersize added.
+2004/06/24 v1.5: Clear map file entries so that pdfTeX
+ does not touch the fonts.
+2004/06/26 v1.6: Use mgs.exe instead of gswin32c.exe for MIKTEX.
+2005/03/11 v1.7: Support of spaces in file names
+ (open("-|") is used for ghostscript call).
+2008/01/09 v1.8: Fix for moving the temporary file to the output
+ file across file system boundaries.
+2008/04/05 v1.9: Options --resolution and --bbox added.
+
+L. TODO
+=======
+* Description of user interface.
+* Documentation in other formats, eg. man or info pages.
+* Improved error checking.
+* Units support for option --margins.
+* Perhaps other drivers than pdfTeX, especially VTeX.
diff --git a/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl b/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl
new file mode 100644
index 00000000000..a13ac745439
--- /dev/null
+++ b/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl
@@ -0,0 +1,369 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q'
+ if 0;
+use strict;
+$^W=1; # turn warning on
+#
+# pdfcrop.pl
+#
+# Copyright (C) 2002, 2004, 2005, 2008 Heiko Oberdiek.
+#
+# This program may be distributed and/or modified under the
+# conditions of the LaTeX Project Public License, either version 1.2
+# of this license or (at your option) any later version.
+# The latest version of this license is in
+# http://www.latex-project.org/lppl.txt
+# and version 1.2 or later is part of all distributions of LaTeX
+# version 1999/12/01 or later.
+#
+# See file "README" for a list of files that belong to this project.
+#
+# This file "pdfcrop.pl" may be renamed to "pdfcrop"
+# for installation purposes.
+#
+my $file = "pdfcrop.pl";
+my $program = uc($&) if $file =~ /^\w+/;
+my $version = "1.9";
+my $date = "2008/04/05";
+my $author = "Heiko Oberdiek";
+my $copyright = "Copyright (c) 2002-2008 by $author.";
+#
+# Reqirements: Perl5, Ghostscript
+# History:
+# 2002/10/30 v1.0: First release.
+# 2002/10/30 v1.1: Option --hires added.
+# 2002/11/04 v1.2: "nul" instead of "/dev/null" for windows.
+# 2002/11/23 v1.3: Use of File::Spec module's "devnull" call.
+# 2002/11/29 v1.4: Option --papersize added.
+# 2004/06/24 v1.5: Clear map file entries so that pdfTeX
+# does not touch the fonts.
+# 2004/06/26 v1.6: Use mgs.exe instead of gswin32c.exe for MIKTEX.
+# 2005/03/11 v1.7: Support of spaces in file names
+# (open("-|") is used for ghostscript call).
+# 2008/01/09 v1.8: Fix for moving the temporary file to the output
+# file across file system boundaries.
+# 2008/04/05 v1.9: Options --resolution and --bbox added.
+#
+
+### program identification
+my $title = "$program $version, $date - $copyright\n";
+
+### error strings
+my $Error = "!!! Error:"; # error prefix
+
+### string constants for Ghostscript run
+# get Ghostscript command name
+my $GS = "gs";
+$GS = "gs386" if $^O =~ /dos/i;
+$GS = "gsos2" if $^O =~ /os2/i;
+$GS = "gswin32c" if $^O =~ /mswin32/i;
+$GS = "gswin32c" if $^O =~ /cygwin/i;
+$GS = "mgs" if defined($ENV{"TEXSYSTEM"}) and
+ $ENV{"TEXSYSTEM"} =~ /miktex/i;
+
+# Windows detection (no SIGHUP)
+my $Win = 0;
+$Win = 1 if $^O =~ /mswin32/i;
+$Win = 1 if $^O =~ /cygwin/i;
+
+# "null" device
+use File::Spec::Functions qw(devnull);
+my $null = devnull();
+
+### variables
+my $inputfile = "";
+my $outputfile = "";
+my $tmp = "tmp-\L$program\E-$$";
+
+### option variables
+my @bool = ("false", "true");
+$::opt_help = 0;
+$::opt_debug = 0;
+$::opt_verbose = 0;
+$::opt_gscmd = $GS;
+$::opt_pdftexcmd = "pdftex";
+$::opt_margins = "0 0 0 0";
+$::opt_clip = 0;
+$::opt_hires = 0;
+$::opt_papersize = "";
+$::opt_resolution = "";
+$::opt_bbox = "";
+
+my $usage = <<"END_OF_USAGE";
+${title}Syntax: \L$program\E [options] <input[.pdf]> [output file]
+Function: Margins are calculated and removed for each page in the file.
+Options: (defaults:)
+ --help print usage
+ --(no)verbose verbose printing ($bool[$::opt_verbose])
+ --(no)debug debug informations ($bool[$::opt_debug])
+ --gscmd <name> call of ghostscript ($::opt_gscmd)
+ --pdftexcmd <name> call of pdfTeX ($::opt_pdftexcmd)
+ --margins "<left> <top> <right> <bottom>" ($::opt_margins)
+ add extra margins, unit is bp. If only one number is
+ given, then it is used for all margins, in the case
+ of two numbers they are also used for right and bottom.
+ --(no)clip clipping support, if margins are set ($bool[$::opt_clip])
+ --(no)hires using `%%HiResBoundingBox' ($bool[$::opt_hires])
+ instead of `%%BoundingBox'
+Expert options:
+ --papersize <foo> parameter for gs's -sPAPERSIZE=<foo>,
+ use only with older gs versions <7.32 ($::opt_papersize)
+ --resolution <xres>x<yres> ()
+ --resolution <res> pass argument to ghostscript's option -r
+ Example: --resolution 72
+ --bbox "<left> <top> <right> <bottom>" ()
+ override bounding box found by ghostscript
+Examples:
+ \L$program\E --margins 10 input.pdf output.pdf
+ \L$program\E --margins '5 10 5 20' --clip input.pdf output.pdf
+END_OF_USAGE
+
+### process options
+my @OrgArgv = @ARGV;
+use Getopt::Long;
+GetOptions(
+ "help!",
+ "debug!",
+ "verbose!",
+ "gscmd=s",
+ "pdftexcmd=s",
+ "margins=s",
+ "clip!",
+ "hires!",
+ "papersize=s",
+ "resolution=s",
+ "bbox=s",
+) or die $usage;
+!$::opt_help or die $usage;
+
+$::opt_verbose = 1 if $::opt_debug;
+
+@ARGV >= 1 or die $usage;
+
+print $title;
+
+if ($::opt_bbox) {
+ $::opt_bbox =~ s/^\s+//;
+ $::opt_bbox =~ s/\s+$//;
+ $::opt_bbox =~ s/\s+/ /;
+ if ($::opt_bbox =~ /^-?\d*\.?\d+ -?\d*\.?\d+ -?\d*\.?\d+ -?\d*\.?\d+$/) {
+ print "* Explicite Bounding Box: $::opt_bbox\n" if $::opt_debug;
+ }
+ else {
+ die "$Error Parse error (option --bbox \"$::opt_bbox\")!\n";
+ }
+}
+
+@ARGV <= 2 or die "$Error Too many files!\n";
+
+### input file
+$inputfile = shift @ARGV;
+
+if (! -f $inputfile) {
+ if (-f "$inputfile.pdf") {
+ $inputfile .= ".pdf";
+ }
+ else {
+ die "$Error Input file `$inputfile' not found!\n";
+ }
+}
+
+print "* Input file: $inputfile\n" if $::opt_debug;
+
+### output file
+if (@ARGV) {
+ $outputfile = shift @ARGV;
+}
+else {
+ $outputfile = $inputfile;
+ $outputfile =~ s/\.pdf$//i;
+ $outputfile .= "-crop.pdf";
+}
+
+print "* Output file: $outputfile\n" if $::opt_debug;
+
+### margins
+my ($llx, $lly, $urx, $ury) = (0, 0, 0, 0);
+if ($::opt_margins =~
+ /^\s*([\-\.\d]+)\s+([\-\.\d]+)\s+([\-\.\d]+)\s+([\-\.\d]+)\s*$/) {
+ ($llx, $lly, $urx, $ury) = ($1, $2, $3, $4);
+}
+else {
+ if ($::opt_margins =~ /^\s*([\-\.\d]+)\s+([\-\.\d]+)\s*$/) {
+ ($llx, $lly, $urx, $ury) = ($1, $2, $1, $2);
+ }
+ else {
+ if ($::opt_margins =~ /^\s*([\-\.\d]+)\s*$/) {
+ ($llx, $lly, $urx, $ury) = ($1, $1, $1, $1);
+ }
+ else {
+ die "$Error Parse error (option --margins)!\n";
+ }
+ }
+}
+print "* Margins: $llx $lly $urx $ury\n" if $::opt_debug;
+
+### cleanup system
+my @unlink_files = ();
+my $exit_code = 1;
+sub clean {
+ print "* Cleanup\n" if $::opt_debug;
+ if ($::opt_debug) {
+ print "* Temporary files: @unlink_files\n";
+ }
+ else {
+ for (; @unlink_files>0; ) {
+ unlink shift @unlink_files;
+ }
+ }
+}
+sub cleanup {
+ clean();
+ exit($exit_code);
+}
+$SIG{'INT'} = \&cleanup;
+$SIG{'__DIE__'} = \&clean;
+
+### Calculation of BoundingBoxes
+
+my @gsargs = (
+ "-sDEVICE=bbox",
+ "-dBATCH",
+ "-dNOPAUSE",
+);
+push @gsargs, "-sPAPERSIZE=$::opt_papersize" if $::opt_papersize;
+push @gsargs, "-r$::opt_resolution" if $::opt_resolution;
+push @gsargs,
+ "-c",
+ "save",
+ "pop",
+ "-f",
+ $inputfile
+;
+
+my $tmpfile = "$tmp.tex";
+push @unlink_files, $tmpfile;
+open(TMP, ">$tmpfile") or
+ die "$Error Cannot write tmp file `$tmpfile'!\n";
+print TMP "\\def\\pdffile{$inputfile}\n";
+print TMP <<'END_TMP_HEAD';
+\csname pdfmapfile\endcsname{}
+\def\page #1 [#2 #3 #4 #5]{%
+ \count0=#1\relax
+ \setbox0=\hbox{%
+ \pdfximage page #1{\pdffile}%
+ \pdfrefximage\pdflastximage
+ }%
+ \pdfhorigin=-#2bp\relax
+ \pdfvorigin=#3bp\relax
+ \pdfpagewidth=#4bp\relax
+ \advance\pdfpagewidth by -#2bp\relax
+ \pdfpageheight=#5bp\relax
+ \advance\pdfpageheight by -#3bp\relax
+ \ht0=\pdfpageheight
+ \shipout\box0\relax
+}
+\def\pageclip #1 [#2 #3 #4 #5][#6 #7 #8 #9]{%
+ \count0=#1\relax
+ \dimen0=#4bp\relax \advance\dimen0 by -#2bp\relax
+ \edef\imagewidth{\the\dimen0}%
+ \dimen0=#5bp\relax \advance\dimen0 by -#3bp\relax
+ \edef\imageheight{\the\dimen0}%
+ \pdfximage page #1{\pdffile}%
+ \setbox0=\hbox{%
+ \kern -#2bp\relax
+ \lower #3bp\hbox{\pdfrefximage\pdflastximage}%
+ }%
+ \wd0=\imagewidth\relax
+ \ht0=\imageheight\relax
+ \dp0=0pt\relax
+ \pdfhorigin=#6pt\relax
+ \pdfvorigin=#7bp\relax
+ \pdfpagewidth=\imagewidth
+ \advance\pdfpagewidth by #6bp\relax
+ \advance\pdfpagewidth by #8bp\relax
+ \pdfpageheight=\imageheight\relax
+ \advance\pdfpageheight by #7bp\relax
+ \advance\pdfpageheight by #9bp\relax
+ \pdfxform0\relax
+ \shipout\hbox{\pdfrefxform\pdflastxform}%
+}%
+END_TMP_HEAD
+
+print "* Running ghostscript for BoundingBox calculation ...\n"
+ if $::opt_verbose;
+print "* Ghostscript call: $::opt_gscmd @gsargs\n" if $::opt_debug;
+
+my @bbox;
+if ($::opt_bbox) {
+ $::opt_bbox =~ /([-\d\.]+) ([-\d\.]+) ([-\d\.]+) ([-\d\.]+)/;
+ @bbox = ($1, $2, $3, $4);
+}
+my $page = 0;
+my $pid = open(KID_TO_READ, "-|");
+if ($pid) { # parent
+ while (<KID_TO_READ>) {
+ my $bb = ($::opt_hires) ? "%%HiResBoundingBox" : "%%BoundingBox";
+ next unless
+ /^$bb:\s*([\.\d]+) ([\.\d]+) ([\.\d]+) ([\.\d]+)/o;
+ @bbox = ($1, $2, $3, $4) unless $::opt_bbox;
+ $page++;
+ print "* Page $page: @bbox\n" if $::opt_verbose;
+ if ($::opt_clip) {
+ print TMP "\\pageclip $page [@bbox][$llx $lly $urx $ury]\n";
+ }
+ else {
+ my @bb = ($bbox[0] - $llx, $bbox[1] - $ury,
+ $bbox[2] + $urx, $bbox[3] + $lly);
+ print TMP "\\page $page [@bb]\n";
+ }
+ }
+ close(KID_TO_READ)
+ || die "!!! Error: Execution of ghostscript failed: $?\n";
+}
+else { # child
+ open STDERR, '>&STDOUT' or die "!!! Error: Cannot redirect stderr: $!\n";
+ open STDOUT, ">$null" or die "!!! Error: Cannot write to $null!\n";
+ exec($::opt_gscmd, @gsargs)
+ || die "!!! Error: Ghostscript run failed: $!\n";
+ # NOT REACHED
+}
+
+print TMP "\\csname \@\@end\\endcsname\n\\end\n";
+close(TMP);
+
+### Run pdfTeX
+
+push @unlink_files, "$tmp.log";
+my $cmd;
+if ($::opt_verbose) {
+ $cmd = "$::opt_pdftexcmd -interaction=nonstopmode $tmp";
+}
+else {
+ $cmd = "$::opt_pdftexcmd -interaction=batchmode $tmp";
+}
+print "* Running pdfTeX ...\n" if $::opt_verbose;
+print "* pdfTeX call: $cmd\n" if $::opt_debug;
+if ($::opt_verbose) {
+ system($cmd);
+}
+else {
+ `$cmd`;
+}
+if ($?) {
+ die "$Error pdfTeX run failed!\n";
+}
+
+### Move temp file to output
+if (!rename("$tmp.pdf", $outputfile)) {
+ use File::Copy;
+ move "$tmp.pdf", $outputfile or
+ die "$Error Cannot move `$tmp.pdf' to `$outputfile'!\n";
+}
+
+print "==> $page page", (($page == 1) ? "" : "s"),
+ " written on `$outputfile'.\n";
+
+$exit_code = 0;
+cleanup();
+
+__END__