Generating PDF File
In order to generate PDF document, we need to do these steps:
- Open a PDF stream and associate a handle with it:
$pdf = PDF_open();
- (Optional) Set document information like Author, Title, Subject, etc
- Start a new page (a PDF file can be made of different page with different layout, e.g. portrait, landscape…):
PDF_begin_page($pdf, 595, 842);
- (Optional) Set an hyperlink :
PDF_add_outline($pdf, "Item ".$data[1]);
- Choose font type, dimension
(pdf_set_font($pdf, "Helvetica-Bold" , 20, winansi);
) and rendering mode - Insert text at X,Y position :
PDF_show_xy($pdf, "Item : " .$data[1], 100, 700);
or
insert image at X,Y position on PDF document:pdf_place_image($pdf, $im, 100, 300, 3);
- Flush text buffer and close PDF stream.
PDF Coordinate Systems
What we need to do to locate a string or picture in some part of the PDF page,
is to convert from metric/inch distance to
DTP point correspondent value. At page 45 of PDFLib Manual we read:
is to convert from metric/inch distance to
DTP point correspondent value. At page 45 of PDFLib Manual we read:
".. . The default coordinate system (or default user space in PDF lingo) has the origin in the lower left corner of the page, and uses the DTP point as unit: 1 pt = 1 inch / 72 = 25,4 mm / 72 = 0,3528 mm"
Here is a snapshot code for generating PDF file:
<?php
$pdf
= PDF_open();
pdf_set_info_author($pdf, "Luca Perugini");
PDF_set_info_title($pdf, "Brochure for FlyStore");
pdf_set_info_creator($pdf, "See Author");
pdf_set_info_subject($pdf, "FlyStore");
PDF_begin_page($pdf, 595, 842);
PDF_add_outline($pdf, "Item ".$data[1]);
pdf_set_font($pdf, "Helvetica-Bold" , 20, winansi);
pdf_set_text_rendering($pdf, 0);
pdf_show_xy($pdf, "FlyStore Catalogue 2000",50,780);
PDF_show_xy($pdf, "Item : " .$data[1], 100, 700);
PDF_show_xy($pdf, "Description : " .$data[2], 100, 620);
$im = PDF_open_jpeg($pdf, "pass4_sml.jpg");
pdf_place_image($pdf, $im, 100, 300, 3);
pdf_close_image ($im);
pdf_stroke($pdf);
PDF_end_page($pdf);
PDF_close($pdf);
?>
In the end, I’d like to remind you that this article is not a PDF Tutorial,
so if you need more information about the PDF language and its use, you
must have a look at http://www.pdfzone.com/
and http://www.planetpdf.com/.
so if you need more information about the PDF language and its use, you
must have a look at http://www.pdfzone.com/
and http://www.planetpdf.com/.
Files Used in This Tutorial:
I hope this has been of use to you.
Ciao
— Luca
— Luca