#!/usr/local/bin/perl -w # # Time-stamp: <2002-06-26 10:26:50 georg> # $Id: dvi2pdf,v 1.2 2002/06/26 08:27:50 georg Exp $ # use strict; use Getopt::Std; # Who am I anyway (my $me = $0) =~ s/.*\///; # revision/date/author my $version = ('$Revision: 1.2 $' =~ m/Revision: (.*) /)[0]; my $date = ('$Date: 2002/06/26 08:27:50 $' =~ m/Date: (.*) /)[0]; my $author = ('$Author: georg $' =~ m/Author: (.*) /)[0]; my $distopts="-v -stats -params -compatlevel 3.0 -pagesize 595 842 pts -resolution 1200 -embedallfonts on -colordownsample off -graydownsample off -monodownsample off"; sub printhelp { print STDERR <<"EOF"; Usage: $me [-hl] [-f format] [-g "gsopt"] [-s x] [-d] [-o "distopts"] inputfile[.dvi] [outputfile] Version: $version, date: $date, author: $author $me converts a TeX dvi file into an Adobe PDF file. The input dvi file can be specified with or without the .dvi ending. If no output file name is given the name will be the input file name with the .dvi ending sustituted by .pdf. Like \`dvips\' the program must be run from a directory where all included graphics files can be found. Options: -h This help -f format Specify the paper format. Possible values are those allowed by the -sPAPERSIZE option of \`gs\'. Default is a4. This option does not override the paper size which is set by the \\special{} TeX macro. -g "string" additional options for \'gs\'. -i "filter" Filtercommand to put between the \`dvips\' and \'gs\' command. Example: -i "pstops \'2:0(0,-3mm),1(4.1cm,-3mm)\'" to adjust the position on the page. -l Rotate the file by 90 degree for landscape printing. This option does not override the paper size which is set by the \\special{} command. -s x Specify a papersize which is unknown to \`gs\'. xsize and ysize are measured in cm. -d Use the Adobe Acrobat distiller instead of ghostscript. The options -f, -g, -s are then ignored. -o "string" Alternative options for the Adobe distiller. Only valid in conjunction with the -d option. Default is \'$distopts\'. -v verbose EOF exit; } my %opts; my $opt_status = getopts('hf:g:i:ls:do:v',\%opts); if ( !$opt_status || defined($opts{h}) ) { printhelp; } # set papersize for output my $papopt = "-sPAPERSIZE=a4"; if ( defined($opts{f}) ) { $papopt = "-sPAPERSIZE=$opts{f}"; } # gs options my $gsopts = ""; if ( defined($opts{g}) ) { $gsopts = "$opts{g}"; } # filter option my $filopts = " | "; if ( defined($opts{i}) ) { $filopts = "| $opts{i} |"; } # size if ( defined($opts{s}) ) { my $xs; my $ys; ($xs,$ys) = ( $opts{p} =~ /(.*)x(.*)/ ); $papopt = sprintf("-r1200 -g%dx%d", 1200/2.53*$xs, 1200/2.53*$ys); } # landscape my $lsopt=""; if ( defined($opts{l}) ) { $lsopt = "-t landscape"; } ## default settings for pipe mode my $infilename=""; my $outfilename="-"; if ( defined($ARGV[0]) ) { $infilename = $ARGV[0]; my $base; # determine full input file name if ( ! -r $infilename ) { # only base of input file was specified $base = $infilename; $infilename = "$infilename.dvi"; if ( ! -r $infilename ) { die "datei nicht gefunden"; } } else { # full input file name including .dvi was specified if ($infilename =~ /.*\.[Dd][Vv][Ii]/) { $base = ($infilename =~ /(.*)\.[Dd][Vv][Ii]/)[0]; } else { die "no dvi file"; } } # determine output file name if ( ! defined($ARGV[1]) ) { $outfilename = "$base.pdf"; } else { $outfilename = $ARGV[1]; } } else { print "no input file given: aborting\n\n"; printhelp; } # dvips command # `dvips -z' mainly includes hyper-postscript code and is almost # eqivalent to `dvips -h hps.pro' but not quite ... # -z is not necessary if -Ppdf is used. # no documentation available! my $dvips="dvips -Pcmz -Pamz -Ppdf -f $lsopt $infilename"; # gs command line my $ps2pdf="gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 $papopt $gsopts -sOutputFile=$outfilename -c save pop -f -_"; # distill command line if ( defined($opts{d}) ) { if (defined($opts{o})) { $distopts = $opts{o}; } $ps2pdf = "distill $distopts > $outfilename"; } ## debug: # print "$ps2pdf\n"; # run conversion if ( defined($opts{v}) ) { print "running command\n"; print "$dvips $filopts $ps2pdf\n"; } system("$dvips $filopts $ps2pdf"); # delete temporary files generated by `dvips -z' # unlink "head.tmp", "body.tmp"; # END