<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Development Blog &#187; pdf</title>
	<atom:link href="http://www.web-development-blog.com/archives/tag/pdf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-development-blog.com</link>
	<description>Web development tutorials, SEO articles and PHP script resources</description>
	<lastBuildDate>Sun, 25 Jul 2010 14:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Create PDF documents Online with TCPDF</title>
		<link>http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/</link>
		<comments>http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/#comments</comments>
		<pubDate>Thu, 27 May 2010 17:50:26 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[documents]]></category>
		<category><![CDATA[invoice]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[php class]]></category>
		<category><![CDATA[tcpdf]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=1098</guid>
		<description><![CDATA[Many web applications using PDF documents for invoices, contracts and many other doc types. There are a few PHP classes which are able to create PDF documents online, one of them is TCPDF. This tutorial is about how-to use the TCPDF class while creating a simple invoice document. If you like to take a sneak [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>Many web applications using PDF documents for invoices, contracts and many other doc types. There are a few PHP classes which are able to create PDF documents online, one of them is TCPDF. This tutorial is about how-to use the TCPDF class while creating a simple invoice document. If you like to take a sneak peak on the result, check this website which generates the <a href="http://www.pdffacturatie.nl/">PDF Invoice</a> document on the fly.</p>
<h3>Why TCPDF and not some other PHP class?</h3>
<p><a href="http://www.tcpdf.org/" rel="nofollow">TCPDF</a> is based on the <a href="http://fpdf.org/" rel="nofollow">FPDF</a> class, a very stable project written for PHP4. Since several years has TCPDF much more features than FPDF and is written for PHP5 (there is also a PHP4 version). The TCPDF has also some great <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html" rel="nofollow">documentation</a> and of course examples for all important PDF jobs like:<br />
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 <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples" rel="nofollow">more</a>.</p>
<h3>The Zend Framework has some PDF class too&#8230;</h3>
<p>Yes right, the first plan was to write this tutorial about the Zend Framework, but after writing a few rows of code I&#8217;ve noticed that the <a href="http://framework.zend.com/manual/en/zend.pdf.html" rel="nofollow">PDF Class</a> is missing some important functions, like the <strong>MultiCell</strong>, which is used to wrap multiple rows of text. It&#8217;s a <strong>required</strong> function which was suggested as the <a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Pdf_Cell+-+Logan+Buesching" rel="nofollow">Zend_Pdf_Cell</a> 2 years ago and didn&#8217;t find the way to the core version until now. I like the Zend Framework a lot but<span id="more-1098"></span> not for creating PDF documents, the PDF class is much too limited. <img src='http://www.web-development-blog.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<h3>Okay let&#8217;s start the tutorial:</h3>
<p>In this tutorial we create a PDF invoice including header logo, the invoice rows, an information box and some footer row.<br />
In our code we include some PHP files, next we&#8217;ve created a small class extension to have a custom header/footer and some handy method which creates a text box.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tcpdf/config/lang/eng.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tcpdf/tcpdf.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MYPDF <span style="color: #000000; font-weight: bold;">extends</span> TCPDF <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">Header</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setJPEGQuality</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Image</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'logo.png'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'PNG'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://www.finalwebsites.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetY</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFont</span><span style="color: #009900;">&#40;</span>PDF_FONT_NAME_MAIN<span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'finalwebsites.com - PHP Script Resource, PHP classes and code for web developer'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CreateTextBox<span style="color: #009900;">&#40;</span><span style="color: #000088;">$textval</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fontsize</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fontstyle</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$align</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'L'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetXY</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 20 = margin left</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFont</span><span style="color: #009900;">&#40;</span>PDF_FONT_NAME_MAIN<span style="color: #339933;">,</span> <span style="color: #000088;">$fontstyle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fontsize</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cell</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$textval</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$align</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The <strong>header</strong> 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&#8217;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 <strong>PDF_FONT_NAME_MAIN</strong> is defined inside the TCPDF config file, which is located inside the <strong>config</strong> directory.</p>
<h3>The invoice header</h3>
<p>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.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// create a PDF object</span>
<span style="color: #000088;">$pdf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MYPDF<span style="color: #009900;">&#40;</span>PDF_PAGE_ORIENTATION<span style="color: #339933;">,</span> PDF_UNIT<span style="color: #339933;">,</span> PDF_PAGE_FORMAT<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set document (meta) information</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetCreator</span><span style="color: #009900;">&#40;</span>PDF_CREATOR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetAuthor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Olaf Lederer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TCPDF Example'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TCPDF Tutorial'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TCPDF, PDF, example, tutorial'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// add a page</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create address box</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Customer name Inc.'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">55</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mr. Tom Cat'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Street address'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">65</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zip, city name'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">70</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// invoice title / number</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invoice #201012345'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// date, order ref</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Date: '</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Order ref.: #6765765'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">105</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Invoice Rows</h3>
<p>Now we create the information about the products we like put into the PDF invoice. First we create some headers and than we use a <strong>foreach</strong> loop to output our <strong>$orders</strong> array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// list headers</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Quantity'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Product or service'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Price'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Amount'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Line</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">129</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">195</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">129</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// some example data</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'.com domain registration'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">9.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'.net domain name renewal'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">11.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'SSL certificate 256-Byte encryption'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">99.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'25GB VPS Hosting, 200GB Bandwidth'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">19.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$currY</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">128</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$orders</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quant'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'descr'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$amount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quant'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #339933;">.</span><span style="color: #000088;">$amount</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$currY</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$total</span><span style="color: #339933;">+</span><span style="color: #000088;">$amount</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Line</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currX</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">195</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currX</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After the headers and after the list of invoice items we create a line. Inside the loop, we use the variable <strong>$currY</strong> to raise the <strong>Y coordinate by 5</strong> for each new row. The row amount is calculated by PHP and also the total amount is raised inside the <strong>foreach</strong> loop.</p>
<h3>Invoice footer and information</h2>
<p>First we create a total row using the value from the variable <strong>$total</strong> we created before. After that row we have a <strong>MultiCell</strong> 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.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// output the total row</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Total'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currX</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">135</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #339933;">.</span><span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$total</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currX</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// some payment instructions or information</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setXY</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currX</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFont</span><span style="color: #009900;">&#40;</span>PDF_FONT_NAME_MAIN<span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">175</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;em&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit&lt;/em&gt;. &lt;br /&gt;
Vestibulum sagittis venenatis urna, in pellentesque ipsum pulvinar eu. In nec &lt;a href=&quot;http://www.google.com/&quot;&gt;nulla libero&lt;/a&gt;, eu sagittis diam. Aenean egestas pharetra urna, et tristique metus egestas nec. Aliquam erat volutpat. Fusce pretium dapibus tellus.'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Close and output PDF document</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test.pdf'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>At the end we call the output method which will safe the created PDF under the name test.pdf and sends the document to the browser.</p>
<p>This is just an example to show how easy it is to create PDF files online. Before you start your own PDF scripts, check all the <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples" rel="nofollow">TCPDF examples</a> to get an idea how-to use the different methods.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/search-for-photos-using-php-and-the-flickr-api/" rel="bookmark" title="December 19, 2009">Search for photos using PHP and the flickr API</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-form-plugin-and-php-file-uploads/" rel="bookmark" title="November 2, 2009">jQuery form plugin and PHP file uploads</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
</ul>
<p><!-- Similar Posts took 4.179 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>More advanced features in phpMyAdmin</title>
		<link>http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/</link>
		<comments>http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/#comments</comments>
		<pubDate>Mon, 12 May 2008 13:43:33 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[MIME]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/</guid>
		<description><![CDATA[This is part two of the article &#8220;Database management with phpMyAdmin&#8221; a review of the book &#8220;Mastering phpMyAdmin&#8221; and the open source software phpMyAdmin. The PMA relational system In MySQL there is no native function to create relations between several database tables. Using the InnoDB database type makes it possible to link with foreign keys [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>This is part two of the article &#8220;<a href="http://www.web-development-blog.com/archives/database-management-with-phpmyadmin/">Database management with phpMyAdmin</a>&#8221; a review of the book &#8220;<a href="http://www.packtpub.com/phpmyadmin-3rd-edition/book/mid/300908y6v6we" rel="nofollow">Mastering phpMyAdmin</a>&#8221; and the open source software phpMyAdmin.</p>
<h3>The PMA relational system</h3>
<p>In MySQL there is no native function to create relations between several database tables. Using the InnoDB database type makes it possible to link with foreign keys and in the latest versions there are stored procedures available to create or handle relations (and other intelligence) inside the database. PMA has great features to create relations while working on data within  the system, Yes the limit is for transactions within PMA, if you need relations within your own application you need to create them by yourself, all relational data created by PMA is stored as PMA meta data. The relational system is not enabled by default, setup scripts (table creation statements) are located in the  scripts sub-directory. Execute them within PMA and change your configuration file to fit your database structure:</p>
<p><code>$cfg['Servers'][$i]['pmadb']           = 'phpmyadmin';<br />
$cfg['Servers'][$i]['bookmarktable']   = 'pma_bookmark';<br />
$cfg['Servers'][$i]['relation']        = 'pma_relation';<br />
$cfg['Servers'][$i]['table_info']      = 'pma_table_info';<br />
$cfg['Servers'][$i]['table_coords']    = 'pma_table_coords';<br />
$cfg['Servers'][$i]['pdf_pages']       = 'pma_pdf_pages';<br />
$cfg['Servers'][$i]['column_info']     = 'pma_column_info';<br />
$cfg['Servers'][$i]['history']         = 'pma_history';</code></p>
<p>After the configurations are done, you get new features in your PMA installation. Note there is also a better support for relations using the foreign key feature while using the InnoDB database type.<span id="more-137"></span></p>
<h3>SQL validator</h3>
<p>I used PMA with the MySQL errors for debugging in the past, that was for me some easy way to test SQL statement and find SQL errors very fast. In PMA its also possible to use the &#8220;<a href="http://developer.mimer.com/validator/index.htm">Mimer SQL validator</a>&#8220;, using this validator your SQL statement is test again the Core SQL-99 rules and gives a report. Note that you need your server needs support for XML, PCRE and PEAR.</p>
<h3>Multi table query generator</h3>
<p>I tried this generator a few years ago and never used it really. Using the book it&#8217;s very easy to understand and maybe you like to play with that feature for a while. I don&#8217;t advice this kind of query generators because of risk of loosing your knowledge in SQL programming. A beginner could use that the generator to learn basic JOIN statements.</p>
<h3>Bookmark successful queries</h3>
<p>You know the situation that you have to execute a SQL statement once a in period and you save that code in your own file of often used SQL statements. PMA has some nice feature to store these queries in a kind of bookmark file. Note that you need to install the relational feature to store the bookmarks (meta information). The following extras are available with the bookmark feature:</p>
<ul>
<li> Storing bookmarks before sending a query</li>
<li> multi query bookmarks</li>
<li> bookmark manipulation using variables</li>
<li> default query for each table</li>
</ul>
<h3>Building relational schemas in PDF</h3>
<p>After building relations in MySQL it&#8217;s very useful to print these linked database table structure on paper. PMA has a compete editor interface to show the table structure using your own positions.</p>
<h3>MIME-Based transformations</h3>
<p>for those people using PMA to maintain the full database (like a CMS) is this feature: MIME-Based Transformations. With this feature its possible to create some &#8220;Intelligence&#8221; for table columns to transform BLOB data into images, text into clickable URLs, date formatting&#8230; Note that the GD library is required to show Images with this feature.</p>
<h3>Character Sets and Collations</h3>
<p>Since MySQL version 4.1.x and later it&#8217;s possible to store data with collations in a database table. This way data with special characters like &#8220;á&#8221; or &#8220;ö&#8221; are comparable with &#8220;normal&#8221; characters. PMA has full support for collations since version 2.6.</p>
<p>If you use data which includes special characters you should use the right &#8220;effective&#8221; character set otherwise the data is not displayed the right way.</p>
<p>There are many more feature in PMA like described here. If you read the book &#8220;<a href="http://www.packtpub.com/phpmyadmin-3rd-edition/book/mid/300908y6v6we" rel="nofollow">Mastering phpMyAdmin for Effective MySQL Management&#8221;</a> you get a better idea on all of them.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/database-management-with-phpmyadmin/" rel="bookmark" title="May 12, 2008">Database Management with phpMyAdmin</a></li>
<li><a href="http://www.web-development-blog.com/archives/upload-images-for-usage-in-tinymce/" rel="bookmark" title="September 25, 2008">Upload images for usage in TinyMCE</a></li>
<li><a href="http://www.web-development-blog.com/archives/save-bandwidth-with-phproxy-and-ip2nation/" rel="bookmark" title="May 30, 2007">Save bandwidth with PHProxy and ip2nation</a></li>
</ul>
<p><!-- Similar Posts took 3.639 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/more-advanced-features-in-phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->