How to use the PDF document function in php, read how to use the PDF document function in php, and write it to Hunte: I haven't seen you on the Internet for a long time. I can't tell you that, phpuser.com without hunte is nothing. I turned to the two articles on your website and turned over one to apologize. --------------------------------------------- to Hunte:
I haven't seen you on the Internet for a long time. I can't say anything. I didn't know hunte's phpuser.com. I turned to the two articles on your website and turned over one to apologize.
----------------------------------------------------
Original Author: Perugini Luca (www.phpbuilder.com)
Http://www.phpease.com (znsoft)
---------------------------------------------------
Reprinted please keep the above information; otherwise, please do not reprinted!
PHP bundling the PDFLIB library may be the best web publishing platform. Typical usage:
Demand brochure
E-Commerce waybill
With this guide, you can learn how to use the PDF extension 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 supported by PDF)
Extract PDF documents
(I suppose you have a little experience configuring php)
Install PDFLib and PHP supported by PDF.
Requirements:
PHP 4.02 + Download from http://php.net
PDFLib 3.0.1 download from http://www.pdflib.com
This is a secret recipe for working with PDFLib3.0.1 and php4: (humorous foreigner ^_^)
Download the ext/pdf. c patch from the http://www.php.net directly to support PDFLib v 3.0.1
Download PDFLib3.0.1 http://www.pdflib.com from here
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 install PDFLib in/usr/local/lib.
Update system Library
Insert/usr/local/lib into/etc/ld. so. conf (file)
#/Sbin/ldconfig
Test and verification
Now you need to restart apache
# Apachectl restart
Copy javasclock. php to the httpd Directory (web directory)... test... everything works.
Important Information
To make PHPLIb and font work together, you must pay attention to the UPR section in the PDFLib manual.
The simplest way to use PDFLib to use fonts is to copy the standard UPR description file (fonts/PDFlib. upr) in the pdflib tar package to your working directory.
Extract PDF documents
Now we have made the conditions for generating PDF documents like flying!
In this small example, we will generate a FLYStore requirement booklet, which of course extracts data from the directory database.
Prepare database
I assume that you have a little experience with databases. to the minimum extent, I really only want you to know how to create a database and insert tables into it.
Create a table catalogue:
Send MIME header information
In order for us to display the information correctly, we need to send the correct header information to the user's browser.
In PHP, we can use the header function. The following code sends the correct MIME type to the browser.
Important Information
You must know that you cannot output anything before sending the header information. A common error is that there is a space at the beginning of the file.
Retrieve data from mysql
Here we use a simple code snippet to extract data from the directory data.
$ Link = mysql_connect ("127.0.0.1", "flyadm", "flystore ")
Or die ("cocould not connect ");
Mysql_select_db ("flystore", $ link );
$ Result = mysql_query ("SELECT * FROM catalogue", $ link)
Or die ("Invalid query ");
$ Data = mysql_fetch_row ($ result );
....
....
Mysql_close ($ link );
?>
Generate PDF file
To generate a PDF document, follow these steps:
Open a PDF stream and associate it with a handle:
$ Pdf = pai_open ();
(Optional) Set document information like Author, Title, Subject, etc
(Optional) set document information, such as author, title, topic, etc.
Start a new page (PDF files can be used to generate different pages, such as portraits, foreground ...):
__Begin_page ($ pdf, 595,842 );
(Optional) set a hyperlink:
Pai_add_outline ($ pdf, "Item". $ data [1]);
Select the font type and size (pdf_set_font ($ pdf, "Helvetica-Bold", 20, winansi );).
Insert text at X. y:
Pai_show_xy ($ pdf, "Item:". $ data [1], 100,700 );
Or insert an image at the X.Y position:
Pai_place_image ($ pdf, $ im, 100,300, 3 );
Refresh the text buffer and close the PDF stream.
PDF Coordinate Systems
What we need to do to locate a string or picture in some part of the PDF page,
In many places on the PDF page, we need to locate the string and image and convert the imperial unit to the DTP point value.
On page 45 of the PDFLIB manual, write:
"... The default coordinate system origin is located in the lower left corner of the page, and the unit is DTP:
1 pt = 1 inch/72 = 25.4/72 = 0.3528
"
Here is the code snippet for generating a PDF file:
Pai_show_xy ($ pdf, "Item:". $ data [1], 100,700 );
Pai_show_xy ($ pdf, "Description:". $ data [2], 100,620 );
$ Im = pai_open_jpeg ($ pdf, "pass4_sml.jpg ");
Pai_place_image ($ pdf, $ im, 100,300, 3 );
Pai_close_image ($ im );
Performance_stroke ($ pdf );
Pai_end_page ($ pdf );
Pai_close ($ pdf );
?>
At the end, I want to remind you that this article is not a PDF tutorial. if you need more information and usage of the PDF document, you can visit
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.