<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How to let DomPDF and Zend Framework play along</title>
	<atom:link href="http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/</link>
	<description>An analog guy in a digital world</description>
	<lastBuildDate>Wed, 18 Aug 2010 19:35:56 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: nomad</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-2226</link>
		<dc:creator>nomad</dc:creator>
		<pubDate>Mon, 05 Apr 2010 07:52:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-2226</guid>
		<description>I&#039;ve been trying your approach that you have suggested to Peter but i can&#039;t seems to get it working. 

function viewAction() {

layout = new Zend_Layout();
$layout-&gt;setLayoutPath(APPLICATION_PATH . &quot;/views/scripts/invoice&quot;);				
$this-&gt;view-&gt;foo = &quot;test data&quot;;
$this-&gt;render(); /* i can render my view.phtml */

$layout-&gt;content = $output;
$layout-&gt;setLayout(&#039;pdf&#039;); 
echo &quot;&lt;pre&gt;&quot;;
print_r($layout);
$html = $layout-&gt;render();

}
When i render the layout it show following error:
Message: Requested HTML document contains no data. 

following is my pdf.phtml code

$dompdf = new DOMPDF();
$dompdf-&gt;set_paper(&quot;a4&quot;,&quot;portrait&quot;);
$dompdf-&gt;load_html($html);
$dompdf-&gt;set_base_path($_SERVER[&#039;DOCUMENT_ROOT&#039;]);
$dompdf-&gt;render();
$dompdf-&gt;stream(&quot;document.pdf&quot;);</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been trying your approach that you have suggested to Peter but i can&#8217;t seems to get it working. </p>
<p>function viewAction() {</p>
<p>layout = new Zend_Layout();<br />
$layout-&gt;setLayoutPath(APPLICATION_PATH . &#8220;/views/scripts/invoice&#8221;);<br />
$this-&gt;view-&gt;foo = &#8220;test data&#8221;;<br />
$this-&gt;render(); /* i can render my view.phtml */</p>
<p>$layout-&gt;content = $output;<br />
$layout-&gt;setLayout(&#8216;pdf&#8217;);<br />
echo &#8220;
<pre>";
print_r($layout);
$html = $layout-&gt;render();

}
When i render the layout it show following error:
Message: Requested HTML document contains no data. 

following is my pdf.phtml code

$dompdf = new DOMPDF();
$dompdf-&gt;set_paper("a4","portrait");
$dompdf-&gt;load_html($html);
$dompdf-&gt;set_base_path($_SERVER['DOCUMENT_ROOT']);
$dompdf-&gt;render();
$dompdf-&gt;stream("document.pdf");</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcel van Veelen</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-2075</link>
		<dc:creator>Marcel van Veelen</dc:creator>
		<pubDate>Tue, 09 Mar 2010 14:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-2075</guid>
		<description>Great!

Works fine.</description>
		<content:encoded><![CDATA[<p>Great!</p>
<p>Works fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael D</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1784</link>
		<dc:creator>Michael D</dc:creator>
		<pubDate>Sat, 23 Jan 2010 01:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1784</guid>
		<description>&lt;a href=&quot;#comment-1778&quot; rel=&quot;nofollow&quot;&gt;@Tom&lt;/a&gt; 
 Here is the html that is added to the file before the pdf header. 
----------
&lt;b&gt;Warning&lt;/b&gt;:  file_put_contents(/var/www/vmnc/library/dompdf/lib/fonts/php_Times-Roman.afm) [&lt;a href=&#039;function.file-put-contents&#039; rel=&quot;nofollow&quot;&gt;function.file-put-contents&lt;/a&gt;]: failed to open stream: Permission denied in &lt;b&gt;/var/www/vmnc/library/dompdf/lib/class.pdf.php&lt;/b&gt; on line &lt;b&gt;2354&lt;/b&gt;

-------------
Im not sure what that means but is enough to corrupt the file so it wont be rendered by some pdf viewers. 

Thanks I appreciate your help.</description>
		<content:encoded><![CDATA[<p><a href="#comment-1778" rel="nofollow">@Tom</a><br />
 Here is the html that is added to the file before the pdf header.<br />
&#8212;&#8212;&#8212;-<br />
<b>Warning</b>:  file_put_contents(/var/www/vmnc/library/dompdf/lib/fonts/php_Times-Roman.afm) [<a href='function.file-put-contents' rel="nofollow">function.file-put-contents</a>]: failed to open stream: Permission denied in <b>/var/www/vmnc/library/dompdf/lib/class.pdf.php</b> on line <b>2354</b></p>
<p>&#8212;&#8212;&#8212;&#8212;-<br />
Im not sure what that means but is enough to corrupt the file so it wont be rendered by some pdf viewers. </p>
<p>Thanks I appreciate your help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1778</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 20 Jan 2010 22:52:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1778</guid>
		<description>Have you tried my second method? That&#039;s a more compact approach. Of course, you lose the benefit of a layout, but I could live with that.

Could you post what you have, then maybe I can help you with fixing it.</description>
		<content:encoded><![CDATA[<p>Have you tried my second method? That&#8217;s a more compact approach. Of course, you lose the benefit of a layout, but I could live with that.</p>
<p>Could you post what you have, then maybe I can help you with fixing it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael D</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1768</link>
		<dc:creator>Michael D</dc:creator>
		<pubDate>Mon, 18 Jan 2010 05:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1768</guid>
		<description>Ive been trying your approach but I keep getting corrupted files with the html content coming before the pdf. I can disable the layout with $this-&gt;helper-&gt;layout-&gt;diableLayout(); to just get the view scipt html code but I cant figure out how to get the view in the pdfs layout content area.</description>
		<content:encoded><![CDATA[<p>Ive been trying your approach but I keep getting corrupted files with the html content coming before the pdf. I can disable the layout with $this-&gt;helper-&gt;layout-&gt;diableLayout(); to just get the view scipt html code but I cant figure out how to get the view in the pdfs layout content area.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1723</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 05 Jan 2010 22:56:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1723</guid>
		<description>Hello Peter,
That&#039;s exactly what I&#039;ve needed DomPDF for. Below is how I did it. The code should be in your invoices controller, view action. Via a URL parameter, you could switch to PDF code.
        // We need a layout to render the view in (possibly a separate PDF layout)
        $layout = new Zend_Layout();
        $layout-&gt;setLayoutPath(APPLICATION_PATH . &quot;/path/to/layouts&quot;);

        // Assign stuff to your view like this:
        $this-&gt;view-&gt;foo = &quot;bar&quot;;

        // Render the current view script:
        $this-&gt;render();

        // capture the response:
        $output = $this-&gt;getResponse()-&gt;getBody();

        // set that view script content as content of the layout:
        $layout-&gt;content = $output;
        $layout-&gt;setLayout(&#039;pdf&#039;); // my custom layout is called &#039;pdf.phtml&#039;
        $html = $layout-&gt;render();

That&#039;s it, you can now use $html as input for DomPDF.

As an extra, I&#039;ll also give you the code to just render any view script. You&#039;ll see that it&#039;s much shorter, and maybe you want to use that. It&#039;s something I use in cron scripts to render e-mail templates, but it can be used for DomPDF as well:

        // create a new view:
        $view = new Zend_View();
        $view-&gt;setScriptPath(APPLICATION_PATH . &quot;/path/to/view/scripts&quot;);

        // assign stuff to the view:
        $view-&gt;foo = &quot;bar&quot;;

        // render the view:
        $html = $view-&gt;render(&#039;pdf.phtml&#039;);</description>
		<content:encoded><![CDATA[<p>Hello Peter,<br />
That&#8217;s exactly what I&#8217;ve needed DomPDF for. Below is how I did it. The code should be in your invoices controller, view action. Via a URL parameter, you could switch to PDF code.<br />
        // We need a layout to render the view in (possibly a separate PDF layout)<br />
        $layout = new Zend_Layout();<br />
        $layout->setLayoutPath(APPLICATION_PATH . &#8220;/path/to/layouts&#8221;);</p>
<p>        // Assign stuff to your view like this:<br />
        $this->view->foo = &#8220;bar&#8221;;</p>
<p>        // Render the current view script:<br />
        $this->render();</p>
<p>        // capture the response:<br />
        $output = $this->getResponse()->getBody();</p>
<p>        // set that view script content as content of the layout:<br />
        $layout->content = $output;<br />
        $layout->setLayout(&#8216;pdf&#8217;); // my custom layout is called &#8216;pdf.phtml&#8217;<br />
        $html = $layout->render();</p>
<p>That&#8217;s it, you can now use $html as input for DomPDF.</p>
<p>As an extra, I&#8217;ll also give you the code to just render any view script. You&#8217;ll see that it&#8217;s much shorter, and maybe you want to use that. It&#8217;s something I use in cron scripts to render e-mail templates, but it can be used for DomPDF as well:</p>
<p>        // create a new view:<br />
        $view = new Zend_View();<br />
        $view->setScriptPath(APPLICATION_PATH . &#8220;/path/to/view/scripts&#8221;);</p>
<p>        // assign stuff to the view:<br />
        $view->foo = &#8220;bar&#8221;;</p>
<p>        // render the view:<br />
        $html = $view->render(&#8216;pdf.phtml&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1721</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Tue, 05 Jan 2010 19:25:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1721</guid>
		<description>This was a fantastic help, thank you!

I&#039;m wondering if you know how to pass the output of a rendered ZF view script to DOMPDF?

I have an invoice template that renders XHTML output. I can view the output in my application by going here:
/invoices/view/id/234

Is there an easy way to grab that output and pass it to $dompdf-&gt;load_html($html) to convert it to a PDF?</description>
		<content:encoded><![CDATA[<p>This was a fantastic help, thank you!</p>
<p>I&#8217;m wondering if you know how to pass the output of a rendered ZF view script to DOMPDF?</p>
<p>I have an invoice template that renders XHTML output. I can view the output in my application by going here:<br />
/invoices/view/id/234</p>
<p>Is there an easy way to grab that output and pass it to $dompdf-&gt;load_html($html) to convert it to a PDF?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Romanitch</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1414</link>
		<dc:creator>Romanitch</dc:creator>
		<pubDate>Fri, 13 Nov 2009 08:49:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1414</guid>
		<description>Thank you !!!</description>
		<content:encoded><![CDATA[<p>Thank you !!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1273</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 23 Oct 2009 13:32:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1273</guid>
		<description>Glad to be of service :)</description>
		<content:encoded><![CDATA[<p>Glad to be of service <img src='http://www.encapsulated.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://www.encapsulated.org/blog/2009/08/27/how-to-let-dompdf-and-zend-framework-play-along/comment-page-1/#comment-1253</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Tue, 20 Oct 2009 14:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=77#comment-1253</guid>
		<description>This was a great help. My colleague and I were looking into this problem for over an hour, until we stumbled upon your Blog. Thank you.</description>
		<content:encoded><![CDATA[<p>This was a great help. My colleague and I were looking into this problem for over an hour, until we stumbled upon your Blog. Thank you.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
