X-Git-Url: https://git.sesse.net/?p=webpdf;a=blobdiff_plain;f=createpdf.pl;h=3d9afce4281ebbb08d83435602f4b2e06651d694;hp=86187fba167590e27420cb3930d6e115c28451ea;hb=130810b91098f85be3763e727bd420d2107b1f81;hpb=0f135d31b052aa50c51cc4a15455d02e076dfae8 diff --git a/createpdf.pl b/createpdf.pl index 86187fb..3d9afce 100755 --- a/createpdf.pl +++ b/createpdf.pl @@ -70,7 +70,7 @@ if ($filename =~ /(.*)\.(?:e?ps|pdf)$/i) { $outname = "$1.pdf"; # Run through ImageMagick first of all, then gs - open PIPE, "| convert $2:- ps:- | gs $pdfopts -dCompatbilityLevel=1.4 -dNOPAUSE -dPATCH -sDEVICE=pdfwrite -dSAFER -sOutputFile=output/$pdf_filename -c '.setpdfwrite $psopts' -f - >&2" + open PIPE, "| convert $2:- pdf:- | gs $pdfopts -dCompatbilityLevel=1.4 -dNOPAUSE -dPATCH -sDEVICE=pdfwrite -dSAFER -sOutputFile=output/$pdf_filename -c '.setpdfwrite $psopts' -f - >&2" or die "convert: $!"; my ($buf, $ret); @@ -106,7 +106,15 @@ if ($filename =~ /(.*)\.(?:e?ps|pdf)$/i) { # Create PostScript from OOo :-) system("/usr/lib/openoffice/program/soffice -display $pdfweb::config::xserver -headless -pt pdf $pdfweb::config::outputdir/$pdf_filename.$ext"); - system("gs $pdfopts -dCompatbilityLevel=1.4 -dNOPAUSE -dPATCH -sDEVICE=pdfwrite -dSAFER -sOutputFile=output/$pdf_filename -c '.setpdfwrite $psopts' -f - < output/$pdf_filename.pdf >&2"); + # This is quite hideous -- it looks like OO.o calls the file something slightly + # different depending on the time format, phase of the moon or something... So + # we try both. + my $inp_ps = "output/$pdf_filename.$ext.pdf"; + if (! -r $inp_ps) { + $inp_ps = "output/$pdf_filename.pdf"; + } + + system("gs $pdfopts -dCompatbilityLevel=1.4 -dNOPAUSE -dPATCH -sDEVICE=pdfwrite -dSAFER -sOutputFile=output/$pdf_filename -c '.setpdfwrite $psopts' -f - < $inp_ps >&2"); } elsif ($filename =~ /(.*)\.(c|cc|cpp|cs|h|py|rb|pl|diff|patch|js|php[1-5]?|hs|f|f90|java|css|sql|l|y|s?ml|sh|awk|m|v)$/i) { $outname = "$1.pdf"; my $ext = $2; @@ -139,8 +147,10 @@ EOF my $size = -s "output/$pdf_filename"; +(my $sanitized_outname = $outname) =~ tr/a-zA-Z0-9. -/_/c; + print "Content-type: application/pdf\n"; -print "Content-disposition: attachment; filename=\"$outname\"\n"; # FIXME: XSS problems? +print "Content-disposition: attachment; filename=\"$sanitized_outname\"\n"; print "Content-length: $size\n\n"; system("cat output/$pdf_filename"); # yuck?