PHP : Function Reference : PDF Functions : PDF_begin_template
rz
Sorry. In the previous note I somehow managed to include the same program twice.
The program that uses templates to draw the fractal is
<?php
function initmengers(&$pdf,$level) {
static $mengers;
if($level>0) initmengers($pdf,$level-1);
$mengers[$level] = pdf_begin_template($pdf,1,1);
if($level===0) {
pdf_rect($pdf,$x,$y,1,1);
pdf_fill($pdf);
}
else {
for($i=0; $i<3; $i++)
for($j=0; $j<3; $j++)
if($i!=1 || $j!=1)
pdf_place_image($pdf,$mengers[$level-1],$j/3,$i/3,1/3);
}
pdf_end_template($pdf);
return $mengers[$level];
}
$pdf = pdf_new();
pdf_open_file($pdf);
$pic = initmengers($pdf,6);
pdf_begin_page($pdf, 595, 421);
pdf_place_image($pdf,$pic,50,50,300);
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header('Content-disposition: inline; filename=test.pdf');
header('Content-length: ' . strlen($data));
echo $data;
pdf_delete($pdf);
?>
|