?php $radius = 200; $margin = 20; $pagecount = 10; $pdf = pdf_new(); if (!pdf_open_file($pdf, "")) {print error; exit;}; pdf_set_parameter($pdf, "warning", "true"); pdf_set_info($pdf, "Creator", "pdf_clock.php"); pdf_set_info($pdf, "Author", "Uwe Steinmann"); pdf_set_info($pdf, "Title", "Analog Clock"); while($pagecount- - 0) {pdf_begin_page($pdf, 2 * ($radius + $margin), 2 * ($radius + $margin)); pdf_set_parameter($pdf, "transition", "wipe"); pdf_set_value($pdf, "duration", 0.5); pdf_translate($pdf, $radius + $margin, $radius + $margin); pdf_save($pdf); pdf_setrgbcolor($pdf, 0.0, 0.0, 1.0); / * minute strokes * / pdf_setlinewidth($pdf, 2.0); for ($alpha = 0; $alpha 360; $alpha += 6) {pdf_rotate($pdf, 6.0); pdf_moveto($pdf, $radius, 0.0); pdf_lineto($pdf, $radius-$margin / 3, 0.0); pdf_stroke($pdf);} pdf_restore($pdf); pdf_save($pdf); / * 5 minute strokes * / pdf_setlinewidth($pdf, 3.0); for ($alpha = 0; $alpha 360; $alpha += 30) {pdf_rotate($pdf, 30.0); pdf_moveto($pdf, $radius, 0.0); pdf_lineto($pdf, $radius-$margin, 0.0); pdf_stroke($pdf);} $ltime = getdate(); / * draw hour hand * / pdf_save($pdf); pdf_rotate($pdf, -(($ltime['minutes'] / 60.0)+$ltime['hours']-3.0)*30.0); pdf_moveto($pdf, -$radius / 10, -$radius / 20); pdf_lineto($pdf, $radius / 2, 0.0); pdf_lineto($pdf, -$radius / 10, $radius / 20); pdf_closepath($pdf); pdf_fill($pdf); pdf_restore($pdf); / * draw minute hand * / pdf_save($pdf); pdf_rotate($pdf, -(($ltime['seconds'] / 60.0)+$ltime['minutes']-15.0)*6.0); pdf_moveto($pdf, -$radius / 10, -$radius / 20); pdf_lineto($pdf, $radius * 0.8, 0.0); pdf_lineto($pdf, -$radius / 10, $radius / 20); pdf_closepath($pdf); pdf_fill($pdf); pdf_restore($pdf); / * draw second hand * / pdf_setrgbcolor($pdf, 1.0, 0.0, 0.0); pdf_setlinewidth($pdf, 2); pdf_save($pdf); pdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0)); pdf_moveto($pdf, -$radius / 5, 0.0); pdf_lineto($pdf, $radius, 0.0); pdf_stroke($pdf); pdf_restore($pdf); / * draw little circle at center * / pdf_circle($pdf, 0, 0, $radius / 30); pdf_fill($pdf); pdf_restore($pdf); pdf_end_page($pdf); # to see some difference sleep(1);} pdf_close($pdf); $buf = pdf_get_buffer($pdf); $len = strlen($buf); header("Content-type: application / pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=foo.pdf"); print $buf; pdf_delete($pdf);?
La distribution PDFLib contient un exemple plus complexe, qui crée des pages plus élaborées, avec une horloge.