]> git.sesse.net Git - webpdf/commitdiff
Added support for showing the last submitted PDFs in a thumbnail fashion.
authorSteinar H. Gunderson <sesse@samfundet.no>
Tue, 9 Aug 2005 00:39:59 +0000 (00:39 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Tue, 9 Aug 2005 00:39:59 +0000 (00:39 +0000)
README
createpdf.pl
index.html
last.pl [new file with mode: 0755]
pdfweb.css [new file with mode: 0644]

diff --git a/README b/README
index a01153642e76377c8589057687bf53148a5be928..f7c6881d6b8e76b7764f30b0b4e9f0277b239a79 100644 (file)
--- a/README
+++ b/README
@@ -5,7 +5,7 @@ You'll need:
   - A web server (I use Apache 2, with mpm-itk[1] to separate the ugliness
     from the rest of the server installation).
   - ImageMagick (http://www.imagemagick.org/).
-  - Perl (http://www.perl.org/), with the CGI module.
+  - Perl (http://www.perl.org/), with the CGI and HTML::Entities modules.
   - OpenOffice.org (http://www.openoffice.org/ -- doh), tested with v1.1
     only. See below for special configuration needed.
   - GhostScript, probably almost any halfway recent version; newer ones
index 6147e7e1938fd63b811658f41fced6ad985f6853..f33bbc5f6c95443fda34ef5168f6a22d7b5eb324 100755 (executable)
@@ -153,6 +153,22 @@ EOF
        exit;
 }
 
+# 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 $size = -s "output/$pdf_filename";
 
 (my $sanitized_outname = $outname) =~ tr/a-zA-Z0-9. -/_/c;
index c23881f61f6566b264350f309f64ba844fec8a4e..0aff6ad2a724f63613d9f754c49c15e3369644fd 100644 (file)
@@ -62,8 +62,9 @@
       multi-gigabyte jobs etc. on it regularily I might just not be able to
       do that. Please be nice :-)</p>
 
-    <p>Note that there is minimal security involved; if I feel like it, I
-      might even take a look at what people are processing. <strong>Do not submit
+    <p>Note that there is minimal security involved; you can even look at
+      <a href="last.pl">the last 20 submitted jobs</a> at any time (this
+      is also handy for resuming a big download). <strong>Do not submit
       any sensitive data!</strong></p>
 
     <p>The converter is currently based on <a href="http://www.ghostscript.com/">GPL
diff --git a/last.pl b/last.pl
new file mode 100755 (executable)
index 0000000..e668edf
--- /dev/null
+++ b/last.pl
@@ -0,0 +1,74 @@
+#! /usr/bin/perl
+use CGI;
+use HTML::Entities;
+use POSIX;
+use strict;
+use warnings;
+require './config.pm';
+
+my $num_last = 20;
+
+# Find the latest N PNG thumbnails. Somewhat ineffective, but I assume 
+# we'll get to that later :-)
+my @thumbnails = (sort { -M $a <=> -M $b } <$pdfweb::config::outputdir/*.png>);
+my $real_num_last = scalar @thumbnails;
+if ($real_num_last > $num_last) {
+       $real_num_last = $num_last;
+}
+
+# Sorry, no HTML templating. I didn't want to pull in yet another
+# dependency :-)
+
+print <<"EOF";
+Content-type: text/html; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE
+  html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+  <head>
+    <title>PDF converter : sesse.net</title>
+    <link rel="stylesheet" href="http://www.sesse.net/sesse.css" type="text/css" />
+    <link rel="stylesheet" href="pdfweb.css" type="text/css" />
+    <link rev="made" href="mailto:sgunderson\@bigfoot.com" />
+    <meta name="MSSmartTagsPreventParsing" content="TRUE" />
+  </head>
+  <body>
+    <h1>Last $real_num_last uploads</h1>
+    
+    <p><a href="http://pdf.sesse.net/">Back to the converter</a></p>
+EOF
+
+for my $t (@thumbnails[0..$num_last-1]) {
+       (my $descname = $t) =~ s/\.png$/.desc/;
+       open DESC, "<$descname"
+               or next;
+       chomp (my $desc = <DESC>);
+       close DESC;
+
+       if (length($desc) > 30) {
+               $desc = substr $desc, 0, 30;
+       }
+       $desc = HTML::Entities::encode_entities($desc);
+
+       my $time = (stat($t))[9];
+       my $date = POSIX::strftime("%Y-%m-%d %H:%M", localtime($time));
+       $t =~ s#^.*/##;
+       (my $pdfname = $t) =~ s/\.png$//;
+
+       print <<"EOF";
+<div class="pdfthumbnail">
+  <p class="thumb"><a href="output/$pdfname"><img src="output/$t" alt="PDF thumbnail" /></a></p>
+  <p class="desc">$desc</p>
+  <p class="date">$date</p>
+</div>
+EOF
+}
+
+print <<"EOF";
+
+    <p class="copyright">Web PDF converter, &copy; 2005 <a href="http://www.sesse.net/">Steinar H. Gunderson</a>.</p>
+  </body>
+</html>        
+EOF
diff --git a/pdfweb.css b/pdfweb.css
new file mode 100644 (file)
index 0000000..718fced
--- /dev/null
@@ -0,0 +1,32 @@
+.pdfthumbnail {
+       width: 250px;
+       height: 260px;
+       border: 1px solid black;
+       font-family: arial, helvetica, sans-serif;
+       font-size: smaller;
+       float: left;
+       margin: 1em;
+       background: rgb(192,192,255);
+}
+
+.pdfthumbnail p {
+       margin: 0em;
+       text-align: center;
+}
+.pdfthumbnail .thumb {
+       height: 192px;
+       line-height: 192px;
+       margin-top: 15px;
+       margin-bottom: 5px;
+}
+.pdfthumbnail img {
+       border: 1px solid black;
+       vertical-align: middle;
+}
+
+.copyright {
+       font-size: smaller;
+       border-top: 1px solid gray;
+       padding-top: 0.5em;
+       clear: both;
+}