1<?php 2/* $Id: pdfclock.php 14574 2005-10-29 16:27:43Z bonefish $ 3 * A little PDFlib application to draw an analog clock. 4 * 5 */ 6$RADIUS = 200.0; 7$MARGIN = 20.0; 8 9$p = PDF_new(); /* create a new PDFlib object */ 10 11/* open new PDF file; insert a file name to create the PDF on disk */ 12if (PDF_open_file($p, "") == 0) { 13 die("Error: " . PDF_get_errmsg($p)); 14} 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.php"); 20PDF_set_info($p, "Author", "Rainer Schaaf"); 21PDF_set_info($p, "Title", "PDF clock (PHP)"); 22 /* start a new page */ 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$ltime = getdate(); 53 54/* draw hour hand */ 55PDF_save($p); 56PDF_rotate($p, -(($ltime['minutes"]/60.0)+$ltime['hours"]-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, -(($ltime['seconds"]/60.0)+$ltime['minutes"]-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, -(($ltime['seconds"] - 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); /* close page */ 90 91PDF_close($p); /* close PDF document */ 92 93$buf = PDF_get_buffer($p); 94$len = strlen($buf); 95 96header("Content-type: application/pdf"); 97header("Content-Length: $len"); 98header("Content-Disposition: inline; filename=pdfclock.pdf"); 99print $buf; 100 101PDF_delete($p); /* delete the PDFlib object */ 102?> 103