Write to Hunte:
For a long time not to see you online, really a bit can not say the feeling, no Hunte phpuser.com nothing. Turn the two articles you stand on, special turned over an apology.
----------------------------------------------------
Original Author: Perugini Luca (www.phpbuilder.com)
Translator: Znsoft (http://www.phpease.com)
---------------------------------------------------
Reprint please keep the above information, otherwise please do not reprint!
The PHP bundled Pdflib library may be the best Web publishing platform. A pair of typical usage:
Demand Brochure
E-commerce Shipping list
With this guide, you can learn how to use the PDF extensions in PHP4 to create PDF documents.
We also focus on using MySQL data to create PDF documents.
Content Summary
Install Pdflib 3.0.1 and PHP4.01PL2 with PDF support: You can install the latest PHP4.03PL1
Extract PDF document
(I suppose you have a little experience in configuring PHP)
Install Pdflib and PHP with PDF support.
Demand:
PHP 4.02+ Download from http://php.net
Pdflib 3.0.1 Download from http://www.pdflib.com
This is how to let PDFLib3.0.1 and PHP4 work together a small secret recipe: (Foreigner very humorous ^_^)
Download the EXT/PDF/PDF.C patch directly from http://www.php.net to support Pdflib v 3.0.1
Download PDFLib3.0.1 from here http://www.pdflib.com
Applicable patches You can find http://www.pdflib.com/pdflib/patches.html here
Configure, make, and install Pdflib
#./configure--enabled-shared-pdflib
#make
#make Install
You will make Pdflib installed in/usr/local/lib.
Update System Library
Insert/usr/local/lib into/etc/ld.so.conf (file)
#/sbin/ldconfig
Testing and validation
Now you need to restart Apache.
#apachectl restart
Copy pdfclock.php to the httpd directory (that is, the Web directory) ... Test.... Everything's fine.
Important Information
To make phplib work with fonts you must pay attention to the UPR part of the Pdflib manual.
The simplest way to use Pdflib fonts is to copy the standard UPR description file (FONTS/PDFLIB.UPR) in the Pdflib tar package to your working directory.
Extract PDF document
Now we have the conditions to generate the PDF document as quickly as we could!
In this small example we want to generate the Flystore company's demand brochure, of course, to extract data from the catalog database.
Preparing the Database
I assume you have a bit of database experience, minimal, and I really just want you to know how to create a database and insert a table into it.
CREATE TABLE Catalogue:
Send MIME header information
In order for us to display correctly, we need to send the correct header information to the user's browser.
In PHP we can use the header function to implement. The following code sends the correct MIME type to the browser.
Important Information
What you have to know is that you can't output anything until you send a message. A common error is that there are spaces at the beginning of the file.
Take count from MySQL
Here we use a simple snippet of code to extract data from the catalog data.
<?php
$link = mysql_connect ("127.0.0.1", "Flyadm", "Flystore")
Or Die ("could not Connect");
mysql_select_db ("Flystore", $link);
$result = mysql_query ("SELECT * from Catalogue", $link)
Or Die ("Invalid query");
In order to generate the PDF document, we need to do the following steps:
Open a PDF stream and associate it with a handle:
$pdf = Pdf_open ();
(Optional) Set Document information like Author, Title, Subject, etc
(optional) Set up document information, such as author, title, subject, etc.
Start a new page (PDF file can produce different pages in different layouts, such as portrait, foreground ...):
Pdf_begin_page ($pdf, 595, 842);
(optional) Set up a hyperlink:
Pdf_add_outline ($pdf, "Item". $data [1]);
Select font type, size (Pdf_set_font ($pdf, "Helvetica-bold", Winansi);) Performance mode
Insert text at X.Y location:
Pdf_show_xy ($pdf, "Item:". $data [1], 100, 700);
or insert picture in x.y position:
Pdf_place_image ($pdf, $im, 100, 300, 3);
Refreshes the text buffer and closes the PDF stream.
PDF coordinate Systems
What We need to be locate a string or picture in some part of the PDF page,
In many places on the PDF page we need to locate strings and pictures, convert English units to DTP point values.
In the Pdflib manual, page 45 reads:
".. . The origin of the default coordinate system is in the lower left corner of the page, with the DTP point as the unit:
1 pt = 1 INCH/72 = 25.4MM/72 = 0.3528 mm
"
Here is the code snippet that generated the PDF file:
<?php
In the end, I want to prompt you this article is not a PDF tutorial, if you need more information and usage of PDF documents, you can access
http://www.pdfzone.com/and http://www.planetpdf.com/.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.