On Friday, 18 May 2012 18:09:35 UTC+2, Josh M wrote:
>
> Hello all,
>
> I am having issues using the DOMPDF pdf generation library in my
> Cake 2.1 application. I am building an inventory management
> application for use at my company and I am trying to dynamically
> generate pdfs my users can print as stock labels. However, when I
> attempt to stream to pdf in my view I get a "Headers already sent"
> error. I have already removed all leading and trailing spaces from
> the view and the DOMPDF include file. I am also using the ajax layout
> which does not preface the content with any html markup. I guess that
> cake is sending headers somewhere in the view rendering process that I
> can't see. Below is the code for my controller function and my view:
>
> Controller method:
> public function printSingleLabel($id = null){
> if($id === null){
> $this->Session->setFlash('No ID provided to print label');
> $this->redirect(array('action'=>'index'));
> }else{
> $this->set('stockItem', $this->StockItem->find('first',
> array(
> 'recursive'=>3, 'conditions'=>array(
> 'StockItem.id'=>$id
> )
> )));
> $this->set('quantity', 15);
> $this->render('printSingleLabel', 'ajax');
> }
> }
>
> View file:
> <?
> require_once("dompdf/dompdf_config.inc.php");
> $html = <<<EOD
> <html>
> <head>
> <title></title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8">
> <style>
> @page {
> margin: 0in 0in 0in 0in;
> }
> body {
> margin: 0in;
> padding: 0in;
> font-size:8pt;
> font-family: Arial, Sans-Serif;
> }
> div {
> float:left;
> /*width:2.75in;*/
> padding:0in;
> /*height:2.125in;*/
> margin:0in;
> }
>
> div.center {
> margin-left: 0.135in;
> margin-right: 0.135in;
> }
> </style>
> </head>
> <body>
> <div>
> <strong>{$stockItem['Part']['number']} Rev {$stockItem['StockItem']
> ['revision']}</strong>
> <br/>
> {$stockItem['Part']['name']}
> <br/>
> <strong>Lot/Batch:</strong>{$stockItem['StockItem']['lot']}/
> {$stockItem['StockItem']['batch']}<br/>
> <strong>Expires:</strong>{$stockItem['StockItem']['exp_date']}<br/
> >
> <strong>Status:</strong>{$stockItem['Status']['code']}<br/>
> <strong>Quantity:</strong>$quantity{$stockItem['Part']['Uom']
> ['code']}<br/>
> </div>
> </body></html>
> EOD;
> $pdf = new DOMPDF();
> $pdf->set_paper(array(0,0,153,198), 'landscape');
> $pdf->load_html($html);
> $pdf->render();
> $pdf->stream("sample.pdf", array('Attachment'=>0));
>
> I've spent a whole afternoon trying to track down where the headers
> are being sent with no luck. If anyone has a suggestion I'd greatly
> appreciate it.
Read the error message?
Warning: Cannot modify header information - headers already sent by (output
started at ***/this/file*:*on this line***) in /irrelevant.php
AD
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php