Page 309 - Open Soource Technologies 304.indd
P. 309

Unit 12: Portable Document Format



            The starting points of other functions, such as pdf_circle( ) and pdf_rect( ), are defined directly   Notes
            in the calls.

            The pdf_moveto( ) function starts the path at a particular point:
            pdf_moveto(pdf, x, y);
            With pdf_lineto( ), you can draw a line from the current point to another point:
            pdf_lineto(pdf, x, y);
            Use pdf_circle( ) to draw a circle of radius r at a particular point:
            pdf_circle(pdf, x, y, r);
            The pdf_arc( ) function draws an arc of a circle:
            pdf_arc(pdf, x, y, r, alpha, beta);
            The circle is centered at (x, y) and has radius r. The starting point of the arc is alpha degrees
            (measured counterclockwise from the horizontal axis), and the endpoint is beta degrees.
            Use pdf_curveto( ) to draw a Bézier curve from the current point:
            pdf_curveto(pdf, x1, y1, x2, y2, x3, y3);
            The points (x1,y1), (x2, y2), and (x3, y3) are control points through which the curve must pass.
            You can draw a rectangle with pdf_rect( ):
            pdf_rect(pdf, x, y, width, height);

            To draw a line from the current point back to the point that started the path, use pdf_closepath( ):
            pdf_closepath(pdf);
                          A simple graphic path

            <?php
            $p = pdf_new( );
            pdf_open_file($p);
            pdf_begin_page($p,612,792);

            pdf_moveto($p,150,150);
            pdf_lineto($p,450,650);
            pdf_lineto($p,100,700);
            pdf_curveto($p,80,400,70,450,250,550);
            pdf_stroke($p);
            pdf_end_page($p);
            pdf_close($p);
            $buf = pdf_get_buffer($p);
            $len = strlen($buf);
            header(“Content-Type:application/pdf”);
            header(“Content-Length:$len”);
            header(“Content-Disposition:inline; filename=gra.pdf”);
            echo $buf; pdf_delete($p);
            ?>





                                             LOVELY PROFESSIONAL UNIVERSITY                                   303
   304   305   306   307   308   309   310   311   312   313   314