]> git.sesse.net Git - webpdf/blobdiff - createpdf.pl
Add -f (-force) to the gnome-web-print command line.
[webpdf] / createpdf.pl
index 3d9afce4281ebbb08d83435602f4b2e06651d694..1af0b87771aa36957a63f00c2b4563696fcc7b7f 100755 (executable)
@@ -29,6 +29,7 @@ $ENV{"HOME"} = $pdfweb::config::homedir;
 my $cgi = CGI->new;
 my $filename = $cgi->param('input');
 my $file = $cgi->upload('input');
+my $url = $cgi->param('url');
 
 # It kind of sucks that we just can't get the temporary file name from
 # CGI.pm, but OK, here goes :-)
@@ -54,7 +55,14 @@ if ($cgi->param('preset') eq 'screen') {
        $psopts = "";
 }
 
-if ($filename =~ /(.*)\.(?:e?ps|pdf)$/i) {
+if ($url =~ /^http/i) {
+       $outname = "web.pdf";
+
+       # Render through Gecko
+       $ENV{'DISPLAY'} = $pdfweb::config::xserver;
+       system("gnome-web-print", "-f", $url, "$pdfweb::config::outputdir/$pdf_filename.ps");
+       system("gs $pdfopts -dCompatbilityLevel=1.4 -dNOPAUSE -dPATCH -sDEVICE=pdfwrite -dSAFER -sOutputFile=output/$pdf_filename -c '.setpdfwrite $psopts' -f - < $pdfweb::config::outputdir/$pdf_filename.ps >&2");
+} elsif ($filename =~ /(.*)\.(?:e?ps|pdf)$/i) {
        $outname = "$1.pdf";
 
        # Yay, just a round through GhostScript
@@ -147,6 +155,24 @@ EOF
 
 my $size = -s "output/$pdf_filename";
 
+if (defined($size) && $size > 0) {
+       # Make a thumbnail from the finished PDF, for later reference. (Output to
+       # stdout is so we make sure we get only the first page; it's the simplest
+       # hack I can find offhand. :-) )
+       system("convert -resize 192x192 output/$pdf_filename png:- > output/$pdf_filename.png");
+       open DESC, ">output/$pdf_filename.desc";
+
+       if ($url =~ /^http/i) {
+               $url =~ tr/\n//d;
+               print DESC "$url\n";
+       } else {
+               $filename =~ tr/\n//d;
+               print DESC "$filename\n";
+       }
+
+       close DESC;
+}
+       
 (my $sanitized_outname = $outname) =~ tr/a-zA-Z0-9. -/_/c;
 
 print "Content-type: application/pdf\n";