PHPBuilder - PHP for PDF Page 4

# PHP for PDF - Page 4

by: Luca Perugini
|
October 26, 2000

## Generating PDF File

In order to generate PDF document, we need to do these steps:
1. Open a PDF stream and associate a handle with it:
\$pdf = PDF_open();

2. (Optional) Set document information like Author, Title, Subject, etc

3. 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);
4. (Optional) Set an hyperlink :

5. Choose font type, dimension
(pdf_set_font(\$pdf, "Helvetica-Bold" , 20, winansi);) and rendering mode

6. 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);

7. 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:
".. . 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(\$pdf595842);
pdf_set_font(\$pdf"Helvetica-Bold" 20winansi);
pdf_set_text_rendering(\$pdf0);
pdf_show_xy(\$pdf"FlyStore Catalogue 2000",50,780);

PDF_show_xy(\$pdf"Item : " .\$data[1], 100700);

PDF_show_xy(\$pdf"Description : " .\$data[2], 100620);

\$im PDF_open_jpeg(\$pdf"pass4_sml.jpg");
pdf_place_image(\$pdf\$im1003003);
pdf_close_image (\$im);

pdf_stroke(\$pdf);
PDF_end_page(\$pdf);
PDF_close(\$pdf);

?>

## Files Used in This Tutorial:

I hope this has been of use to you.
Ciao
-- Luca

Comment and Contribute

## Your comment has been submitted and is pending approval.

Author:
Luca Perugini

Comment:

Comment:

(Maximum characters: 1200). You have characters left.