1#!/usr/bin/perl 2# $Id: pdfclock.cgi.pl 14574 2005-10-29 16:27:43Z bonefish $ 3# 4# PDFlib client: pdfclock CGI example in Perl 5# 6 7use pdflib_pl 5.0; 8 9$RADIUS = 200.0; 10$MARGIN = 20.0; 11 12$p = PDF_new(); 13 14PDF_open_file($p, ""); 15 16# This line is required to avoid problems on Japanese systems 17PDF_set_parameter($p, "hypertextencoding", "winansi"); 18 19PDF_set_info($p, "Creator", "pdfclock.cgi.pl"); 20PDF_set_info($p, "Author", "Thomas Merz"); 21PDF_set_info($p, "Title", "PDF clock (Perl/CGI)"); 22 23PDF_begin_page($p, 2 * ($RADIUS + $MARGIN), 2 * ($RADIUS + $MARGIN)); 24 25PDF_translate($p, $RADIUS + $MARGIN, $RADIUS + $MARGIN); 26PDF_setcolor($p, "fillstroke", "rgb", 0.0, 0.0, 1.0, 0.0); 27PDF_save($p); 28 29# minute strokes 30PDF_setlinewidth($p, 2.0); 31for ($alpha = 0; $alpha < 360; $alpha += 6) 32{ 33 PDF_rotate($p, 6.0); 34 PDF_moveto($p, $RADIUS, 0.0); 35 PDF_lineto($p, $RADIUS-$MARGIN/3, 0.0); 36 PDF_stroke($p); 37} 38 39PDF_restore($p); 40PDF_save($p); 41 42# 5 minute strokes 43PDF_setlinewidth($p, 3.0); 44for ($alpha = 0; $alpha < 360; $alpha += 30) 45{ 46 PDF_rotate($p, 30.0); 47 PDF_moveto($p, $RADIUS, 0.0); 48 PDF_lineto($p, $RADIUS-$MARGIN, 0.0); 49 PDF_stroke($p); 50} 51 52($tm_sec,$tm_min,$tm_hour) = localtime(time); 53 54# draw hour hand 55PDF_save($p); 56PDF_rotate($p, (-(($tm_min/60.0) + $tm_hour - 3.0) * 30.0)); 57PDF_moveto($p, -$RADIUS/10, -$RADIUS/20); 58PDF_lineto($p, $RADIUS/2, 0.0); 59PDF_lineto($p, -$RADIUS/10, $RADIUS/20); 60PDF_closepath($p); 61PDF_fill($p); 62PDF_restore($p); 63 64# draw minute hand 65PDF_save($p); 66PDF_rotate($p, (-(($tm_sec/60.0) + $tm_min - 15.0) * 6.0)); 67PDF_moveto($p, -$RADIUS/10, -$RADIUS/20); 68PDF_lineto($p, $RADIUS * 0.8, 0.0); 69PDF_lineto($p, -$RADIUS/10, $RADIUS/20); 70PDF_closepath($p); 71PDF_fill($p); 72PDF_restore($p); 73 74# draw second hand 75PDF_setcolor($p, "fillstroke", "rgb", 1.0, 0.0, 0.0, 0.0); 76PDF_setlinewidth($p, 2); 77PDF_save($p); 78PDF_rotate($p, -(($tm_sec - 15.0) * 6.0)); 79PDF_moveto($p, -$RADIUS/5, 0.0); 80PDF_lineto($p, $RADIUS, 0.0); 81PDF_stroke($p); 82PDF_restore($p); 83 84# draw little circle at center 85PDF_circle($p, 0, 0, $RADIUS/30); 86PDF_fill($p); 87 88PDF_restore($p); 89PDF_end_page($p); 90 91PDF_close($p); 92 93$buf = PDF_get_buffer($p); 94 95# the following is required on Windows systems 96binmode(STDOUT); 97 98print "Content-Type: application/pdf\n"; 99print "Content-Length: " . length($buf) . "\n"; 100print "Content-Disposition: inline; filename=" . "pdfclock.cgi.pl.pdf" . "\n\n"; 101print $buf; 102 103PDF_delete($p); 104