<?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>PHP Log &#187; PDF</title>
	<atom:link href="http://www.php-log.de/tags/pdf/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Thu, 27 May 2010 04:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Umrechnen von Milimetern in Punkt z.b. beim Erzeugen Von PDF</title>
		<link>http://www.php-log.de/444/php/umrechnen-von-milimetern-in-punkt-z-b-beim-erzeugen-von-pdf</link>
		<comments>http://www.php-log.de/444/php/umrechnen-von-milimetern-in-punkt-z-b-beim-erzeugen-von-pdf#comments</comments>
		<pubDate>Wed, 26 Aug 2009 01:22:34 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[PDF]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=444</guid>
		<description><![CDATA[Sollte ich mal wieder in die Verlegenheit kommen&#8230; Hier die Funktion: function transformMMtoPoint&#40;$mm&#41;&#123; return round&#40;$mm * &#40;1 / 0.351&#41;, 2&#41;; &#125;]]></description>
			<content:encoded><![CDATA[<p>Sollte ich mal wieder in die Verlegenheit kommen&#8230;<span id="more-444"></span></p>
<p>Hier die Funktion:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> transformMMtoPoint<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mm</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mm</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">/</span> <span style="color:#800080;">0.351</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/444/php/umrechnen-von-milimetern-in-punkt-z-b-beim-erzeugen-von-pdf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDF bearbeiten mit Zend Framework in einer CakePHP Anwendung</title>
		<link>http://www.php-log.de/150/php/pdf-bearbeiten-mit-zend-framework-in-einer-cakephp-anwendung</link>
		<comments>http://www.php-log.de/150/php/pdf-bearbeiten-mit-zend-framework-in-einer-cakephp-anwendung#comments</comments>
		<pubDate>Tue, 10 Feb 2009 04:23:28 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Media Views]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=150</guid>
		<description><![CDATA[Es gibt zur Zeit noch keine PDF Unterstützung in CakePHP. Auch in der Bakery gibt es nur ein Tutorial für die Entwicklung mit TCPDF, aber  danach steht mir heute nicht der Sinn. Vielmehr reizt es mich CakePHP mit dem Zend Framework zu verheiraten. Die Komponente Zend_Pdf kann PDF&#8217;s einlesen, bzw. neu anlegen, beschreiben, speichern und [...]]]></description>
			<content:encoded><![CDATA[<p>Es gibt zur Zeit noch keine PDF Unterstützung in CakePHP. Auch in der <a href="http://bakery.cakephp.org/categories/view/3" target="_blank">Bakery</a> gibt es nur ein Tutorial für die Entwicklung mit <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf" target="_blank">TCPDF</a>, aber  danach steht mir heute nicht der Sinn. Vielmehr reizt es mich CakePHP mit dem Zend Framework zu verheiraten. Die Komponente Zend_Pdf kann PDF&#8217;s einlesen, bzw. neu anlegen, beschreiben, speichern und noch einges mehr. Ein schönes Stück Software.<span id="more-150"></span></p>
<p>CakePHP ist auf dass Einbinden fremder Libraries vorbereitet und bietet dem Zend Framework den Ordner /vendors als Quartier. Über die Konstante <strong>VENDORS</strong> kann dann auch fleissig inkludiert werden. Da ich gleich das ganze Zend Framework in den Vendor Ordner gepackt ist es nur konsequent diesen in den include_path einzubinden:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// /app/config/bootstrap.php</span>
<span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> VENDORS <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Danach kann es auch im Controller schon losgehen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> view<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Die Zend_Pdf Komponente einbinden</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Zend/Exception.php&quot;</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;">&quot;Zend/Pdf/Exception.php&quot;</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;">&quot;Zend/Pdf.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Ein bestehendes PDF öffnen</span>
	<span style="color: #000088;">$pdf</span> <span style="color: #339933;">=</span> Zend_Pdf<span style="color: #339933;">::</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span>VIEWS <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;shares/share_template.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Einen Font einrichten und registrieren</span>
	<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> Zend_Pdf_Font<span style="color: #339933;">::</span><span style="color: #004000;">fontWithName</span><span style="color: #009900;">&#40;</span>Zend_Pdf_Font<span style="color: #339933;">::</span><span style="color: #004000;">FONT_TIMES_ROMAN</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;">pages</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFont</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font</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;">// In das PDF schreiben</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pages</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">drawText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World, how are you doing?&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">710</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Und dann schön speichern (Ausserhalb des Webroot)</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span>APP<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;files/shares/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Einen Media View für die Ausgabe/Download einrichten</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Media'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	       <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.pdf&quot;</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'HelloWorld'</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'download'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'extension'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pdf'</span><span style="color: #339933;">,</span>
	       <span style="color: #0000ff;">'path'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'files'</span> <span style="color: #339933;">.</span> DS <span style="color: #339933;">.</span> <span style="color: #0000ff;">'shares'</span> <span style="color: #339933;">.</span> DS
	<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;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Der Umgang mit der Komponente Zend_Pdf wird <a target="_blank" href="http://framework.zend.com/manual/de/zend.pdf.drawing.html">hier</a> ausführlich erläutert. An dieser Stelle will ich nur den Prozess als ganzes beleuchten. Also&#8230;Ich habe die view Methode eines Controllers so eingerichtet dass nicht mehr HTML ausgeben wird, sondern ein dynamisch beschriebenes PDF.  Was neben der Einbindung des Zend Frameworks noch interessant ist sind die <a target="_blank" href="http://book.cakephp.org/de/view/489/Media-Views">Media Views</a>, die Ihre Entsprechung in der <a target="_blank" href="http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000401">send_file</a> Methode von Ruby On Rails finden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/150/php/pdf-bearbeiten-mit-zend-framework-in-einer-cakephp-anwendung/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
