"My First PDF", Unforgetable……

Google+ Pinterest LinkedIn Tumblr +

Indeed, I do not like routines start with something. When you
learn any programming language, we are always forced to say, “Hello,
World!” In the new programming language. I also will invite you to do that again in this time, but to reduce the saturation a bit, let us change
this program into the program “My First PDF”

Try to make your script as below, and try to run through the browser in PHP…

Let’s cek it dot….. 🙂

?>
$halaman = pdf_new();
pdf_open_file($halaman);
pdf_set_info($halaman,”Creator”,”pdf-ku.php”);
pdf_set_info($halaman,”Author”,”Mr. Dodol”);
pdf_set_info($halaman,”Title”,”PDF Pertamaku”);
pdf_begin_page($halaman,595,842);
$huruf = pdf_findfont($halaman,”Helvetica-Bold”,”host”,0);
pdf_setfont($halaman,$huruf,38.0); pdf_show_xy($halaman,”Inilah PDF Pertamaku!”,50,700);
pdf_end_page($halaman);
pdf_close($halaman);
$buf = pdf_get_buffer($halaman);
$panjangbuffer = strlen($buf);
Header(“Content-type: application/pdf”);
Header(“Content-Length: $panjangbuffer”);
Header(“Content-Disposition: inline; filename=pdf-ku.pdf”);
echo $buf;
pdf_delete($halaman);
?>

“Specify the location in the sky Stars”
Create PDF documents, similar to the actual process of drawing on the canvas.
To be able to put your pictures or any posts in the appropriate place with
you desire, then you need to know how to determine the location of the PDF document. PHP document on the valid two-dimensional system of coordinates (x, y), where the point of origin or
coordinates (0,0) in the bottom left corner of the document. Direction coordinate x is horizontal direction
(from left to right) direction and the y coordinate direction is vertical (from bottom to top). System
basic size / scale that is used or abbreviated “pt” point, with the conversion:

1 pt = 1 / 72 inch = 0.35277777778 mm, or in other words
1 inch = 72 pt.

Making PHP document, per page is done. At the beginning of that page,
You must first determine the width and length of paper that will be used
in pt. The following table gives the size of the type of information in the paper
a pt.

Let’s try your script below to learn to play in the coordinates page A4 size.

<?php
$halaman = pdf_new();
pdf_open_file($halaman);
pdf_set_info($halaman,”Creator”,”koord.php”);
pdf_set_info($halaman,”Author”,”Mr. Dodol”);
pdf_set_info($halaman,”Title”,”Test Koordinat PDF”);
pdf_begin_page($halaman,595,842); //ukuran kertas A4

//membuat tulisan pada halaman
$huruf = pdf_findfont($halaman,”Helvetica-Bold”,”host”,0);
pdf_setfont($halaman,$huruf,38.0);
pdf_show_xy($halaman, “Kiri Bawah”, 10, 10);
pdf_show_xy($halaman, “Kanan Bawah”, 335, 10);
pdf_show_xy($halaman, “Kiri Atas”, 10, 802);
pdf_show_xy($halaman, “Kanan Atas”, 375, 802);
pdf_show_xy($halaman, “Tengah”,595/2-60,842/2-20);

// membuat garis di pinggir halaman
pdf_setrgbcolor_stroke($halaman,1,0,0);
pdf_moveto($halaman,10,10);
pdf_lineto($halaman,10,832);
pdf_lineto($halaman,585,832);
pdf_lineto($halaman,585,10);
pdf_lineto($halaman,10,10);
pdf_stroke($halaman);
pdf_setrgbcolor_stroke($halaman,0,0,0);
pdf_end_page($halaman);
pdf_set_parameter($halaman, “openaction”, “fitpage”);
pdf_close($halaman);
$buf = pdf_get_buffer($halaman);
$panjangbuffer = strlen($buf);
Header(“Content-type:application/pdf”);
Header(“Content-Length:$panjangbuffer”);
Header(“Content-Disposition:inline; filename=koord.pdf”);
echo $buf;
pdf_delete($halaman);
?>

Ok, That’s it. See You in the next tutorial.
telusuri

Share.

About Author

Leave A Reply