Specifications

pdf_moveto($pdf, 630, 150);
pdf_lineto($pdf, 610, 55);
pdf_lineto($pdf, 632, 69);
pdf_lineto($pdf, 646, 49);
pdf_lineto($pdf, 666, 150);
pdf_closepath($pdf);
pdf_fill($pdf);
As we would like the polygon outlined as well, we need to set up the same path a second time,
but call pdf_stroke() instead of pdf_fill().
As the multipointed star is a complex repetitive shape, we have written a function to calculate
the locations in the path for us. Our function is called draw_star() and requires x and y coor-
dinates for the center, the number of points required, the radius, the length of the points, a PDF
document identifier, and a Boolean value to indicate if the star shape should be filled in or just
an outline.
The draw_star() function uses some basic trigonometry to calculate locations for a series of
points to lay out a star. For each point we requested our star to have, we find a point on the
radius of the star and a point on a smaller circle $point_size within the outer circle and draw
a line between them. One thing worth noting is that PHPs trigonometric functions such as
cos() and sin() work in radians rather than degrees.
Using a function and some mathematics, we can accurately generate a complex repetitive
shape. Had we wanted a complicated pattern for our page border, we could have used a similar
approach.
When all our page elements are generated, we need to end the page and the document.
Problems with Headers
One minor thing to note in all these scripts is that we need to tell the browser what type of
data we are going to send it. We have done this by sending a content-type HTTP header, for
example
header( “Content-type: application/msword” );
or
header( “Content-type: application/pdf” );
One thing to be aware of is that browsers deal with these headers inconsistently. In particular,
Internet Explorer often chooses to ignore the MIME type and attempt to automatically detect
the type of file.
Generating Personalized Documents in Portable Document Format (PDF)
C
HAPTER 30
30
GENERATING
PERSONALIZED
DOCUMENTS IN
PDF
777
36 7842 CH30 3/6/01 3:40 PM Page 777