home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / pdflib / pdflib-4.0.1.sit / pdflib-4.0.1 / bind / perl / pdfclock.cgi.pl < prev    next >
Encoding:
Perl Script  |  2001-07-04  |  2.2 KB  |  101 lines  |  [TEXT/McPL]

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