This is another export feature php tutorials, I will create simple PHP script to fetch data from MySQL and create pdf file using php. We will use third party FPDF.The FPDF is very awesome PHP class to generate PDF using PHP from MySQL database.This is open source php library to generate pdf file using PHP. Use PHP to Create Dynamic pdf Files (Page 1 of 3 ). In the following article you will learn how to create a pdf file using PHP. This code will be useful if you were considering creating invoices, reports or any other hardcopy file for your client. Many web applications output documents like invoices, contracts or just web pages in the PDF format. There are a few PHP classes which can be used for online, one of them is TCPDF. This tutorial is about how-to use the TCPDF class while creating a simple invoice document. A function that creates, is very common for a website that sells goods or services.ツ xA0 Why TCPDF and not some other PHP class? Is based on the class, a very stable project written originally for PHP4. Since several years has TCPDF much more features than FPDF and is written for PHP5. The TCPDF has also some great and of course examples for all important PDF jobs like: WriteHTML and RTL support, Multiple columns, JavaScript and Forms, Bookmarks (Table of Content), Multicell complex alignment, Barcodes, Set PDF viewer display preferences, EPS/AI vectorial images and many more. The Zend Framework has some PDF class too Yes right, the first plan was to write this tutorial about the, but after writing a few rows of code I’ve noticed that the is missing some important functions, like the MultiCell, which is used to wrap multiple rows of text. It’s a required function which was suggested as the Zend_Pdf_Cell 2 years ago and didn’t find the way to the core version until now. I like the Zend Framework a lot butツ xA0not for creating PDF documents, the PDF class is much too limited.:( Okay let’s start the tutorial: In this tutorial we create a PDF invoice including header logo, the invoice rows, an information box and some footer row. In our code we include some PHP files, next we’ve created a small class extension to have a custom header/footer and some handy method which creates a text box. } The header method has only two functions, one sets the image quality and the second will place an image (including hyperlink) on a defined place (x=120, Y=10, width=75). All coordinates are measured in Millimeters and the height for the image is calculated by the script. Inside the footer method we’re using some basic TCPDF methods to define the position, the font/style and the cell with the footer text. The third method (CreateTextBox) is just a group of TCPDF functions which makes it easier to place some text box into the PDF document. Note, the constant variable PDF_FONT_NAME_MAIN is defined inside the TCPDF config file, which is located inside the config directory. The invoice header The following code will create a TCPDF object with default values, the PDF meta data gets defined (author, title, etc.), a page is added and the invoice header with information is created using our custom text box method. $pdf -> Line ( 20, $currY + 4, 195, $currY + 4 ); After the headers and after the list of invoice items we create a line. Inside the loop, we use the variable $currY to raise the Y coordinate by 5 for each new row. The row amount is calculated by PHP and also the total amount is raised inside the foreach loop. Invoice footer and information First we create a total row using the value from the variable $total we created before. After that row we have a MultiCell which can hold the payment conditions or just some other information. You can use HTML code in this cell as well, for example a link to your terms and conditions. The above posts about mPDF seems from the same user trying to promote it;) I’m an happy user of TCPDF and from my point of view TCPDF and mPDF are uncomparable because the latter contains a lot of code borrowed from TCPDF and different license (LGPL vs GPL). Additionally TCPDF includes tons of killer features that are missing in mPDF (i.e: bidirectional-algorithm for RTL languages, digital signature, document encryption, pre-press utilities, native SVG support, and much more). AFAIK, the latest TCPDF release is able to convert HTML much better than mPDF (at least for my purposes) and includes support for CSS files. I do not understand why the mPDF author started a new project borrowing a lot of code from TCPDF instead of collaborating with the original author. I just spent a long time trying to figure out why this script was timing out after 4 minutes. The constructor in the example uses the constant PDF_UNIT, as defined in the original tcpdf_config.php file, as ‘mm’. However, I had revised the tcpdf_config.php file, setting PDF_UNIT = ‘in’. As a result, the server stalled on trying to scale my Image in the MYPDF::Header() method to 30 inches wide instead of 30 mm wide. Upon changing the constructor call to use “mm” as the PDF_UNIT, the script generated a PDF very quickly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2018
Categories |