{oapdf_gg}
Office software is closely linked to the PDF,the PDF is also must have to control!      Set home Page  Add to Favorites  
You are here:Home > PDF Application > PDF Development
PDF Development
PHP in the preparation of PDF document generator method tutorial
Finishing by: Date:2009-04-17 21:09:08 Popularity: Tags:

pie.php document

The following is the code:

//Accept the book
$ data = $ _POST [ 'data'];
$ slices = explode (",", $ data);

//initialize variables
$ sum = 0;
$ degrees = Array ();
$ diameter = 200;
$ radius = $ diameter/2;

//set the color of each piece of pie, with an array of storage
$ colours = array (array (0,0,0), array (0,0,1), array (0,1,0),
array (1,0,0), array (0,1,1), array (1,1,0),
array (1,0,1 ));

//calculate the total value
$ sum = array_sum ($ slices);

//1, respectively, each converted into the corresponding percentage (360-degree circle)
for ($ y = 0; $ y $ degrees [$ y] = ($ slices [$ y]/$ sum) * 360;
)

//the beginning of the creation of PDF documents
$ pdf = PDF_new ();
PDF_open_file ($ pdf, "chart.pdf");
PDF_begin_page ($ pdf, 500, 500);
PDF_setcolor ($ pdf, "stroke", "rgb", 1, 1, 0);
PDF_moveto ($ pdf, 250, 250);
PDF_lineto ($ pdf, 350, 250);
PDF_stroke ($ pdf);

for ($ z = 0; $ z (
//Set the fill color
PDF_setcolor ($ pdf, "fill", "rgb", $ colours [$ z] [0],
$ colours [$ z] [1], $ colours [$ z] [2 ]);

//calculate coordinates of the end of each arc
$ end_x = round (250 + ($ radius * cos ($ last_angle * pi ()/180 )));< br/> $ end_y = round (250 + ($ radius * sin ($ last_angle * pi ()/180 )));

//split each piece with a straight-line arc
PDF_moveto ($ pdf, 250, 250);
PDF_lineto ($ pdf, $ end_x, $ end_y);

//calculate and draw arc
PDF_arc ($ pdf, 250, 250, $ radius, $ last_angle, ($ last_angle + $ degrees [$ z ]));

//save the final point of
$ last_angle = $ last_angle + $ degrees [$ z];

//Fill color
PDF_fill_stroke ($ pdf);
)

//re-drawing the outline of outer
PDF_circle ($ pdf, 250, 250, 100);
PDF_stroke ($ pdf);

PDF_end_page ($ pdf);
PDF_close ($ pdf);

//If you want to direct output to the client, then add the following code to
$ buf = PDF_get_buffer ($ p);
$ len = strlen ($ buf);
header ( "Content-type: application/pdf");
header ( "Content-Length: $ len");
header ( "Content-Disposition: inline; filename = Pie_php.pdf");
print $ buf;
PDF_delete ($ p);
?>

run the above procedure and enter a different value, you will be a different pie.
PDFLib compatibility is a very good module, you can use PHP to prepare, you can use Java, C #, VB.NET, VB5/6 (ActiveX/COM), ASP (VBScript/Jscript), Borland Delphi, Windows Script Host , ColdFusion4.5 +, C/C + +, Python, Perl, RPG; platform support not only Windows, there are Unix/Linux, Mac OS, IBM eServer iSeries 400 and zSeries S/390 such, the specific operating environment please do not hesitate to visit their Web site to-date information.

there isArticle InformationsComment Information
Category column

Site Help | Site Map | Feedback |
OAPDF.COM Copyright 2009 V1.1