3 # Wrapper around a variety of programs that can do PS -> PDF conversion
12 require Win32
::TieRegistry
;
13 Win32
::TieRegistry
->import();
17 while ($ARGV[0] =~ /^-(.*)$/) {
21 if ($opt eq '-nocompress') {
26 my ($in, $out) = @ARGV;
29 die "Usage: $0 [-nocompress] infile ou{ tfile\n";
32 # If Win32, help GhostScript out with some defaults
34 return if (!$win32_ok);
39 my $Reg = $::Registry
->Open('', {Access
=> 'KEY_READ', Delimiter
=> '/'});
43 foreach my $k1 ('HKEY_CURRENT_USER/Software/',
44 'HKEY_LOCAL_MACHINE/SOFTWARE/') {
45 foreach my $k2 ('Artifex/', '') {
46 foreach my $k3 ('GPL Ghostscript/', 'AFPL Ghostscript/',
48 my $r = $Reg->{$k1.$k2.$k3};
49 if (ref($r) eq 'Win32::TieRegistry') {
50 foreach my $k (keys(%$r)) {
52 if (ref($rk) eq 'Win32::TieRegistry' &&
53 defined($rk->{'/GS_LIB'})) {
63 my($av) = $a->Path =~ m
:^.*/([^/]+)/$:;
64 my($bv) = $b->Path =~ m
:^.*/([^/]+)/$:;
68 return unless (scalar(@gs));
70 $ENV{'PATH'} .= ';' . $gs[0]->{'/GS_LIB'};
71 $ENV{'GS_FONTPATH'} .= (defined($ENV{'GS_FONTPATH'}) ?
';' : '')
72 . $ENV{'windir'}.'\\fonts';
78 # 1. Acrobat distiller
79 my $r = system('acrodist', '-n', '-q', '--nosecurity', '-o', $out, $in);
80 exit 0 if ( !$r && -f
$out );
82 # 2. ps2pdf (from Ghostscript)
83 # The -I clause helps Ghostscript pick up the Fontdir file written by findfont.ph
84 # GhostScript uses # rather than - to separate options and values on Windows, it seems...
86 my $o = $win32_ok ?
'#' : '-';
87 my $r = system('ps2pdf', "-dOptimize${o}true", "-dEmbedAllFonts${o}true",
88 "-dCompressPages${o}" . ($compress ?
'true' : 'false'),
89 "-dUseFlateCompression${o}true", $in, $out);
90 exit 0 if ( !$r && -f
$out );
92 # 3. pstopdf (BSD/MacOS X utility)
93 my $r = system('pstopdf', $in, '-o', $out);
94 exit 0 if ( !$r && -f
$out );