On Friday, 18 May 2012 23:59:46 UTC+2, Josh M wrote:
>
>
>
> On May 18, 2:28 pm, AD7six <[email protected]> wrote:
> > 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
>
> The error is being generated by DOMPDF and reads exactly this: "Unable
> to stream pdf: headers already sent" It does not tell me where the
> headers were sent. I used this same template to create pdfs in
> another application that didn't use the CakePHP framework and I got no
> such error.
>
Sorry, I obviously thought you were truncating what you were reading.
>
> Let me ask this another way: I submit a request through the client
> for a controller method. That method performs some logic and passes
> data off to a view to be rendered. Are headers sent at any point
> before the contents of the view are rendered? I attempted to create a
> controller that performed no logic and created a view that contained
> only a single line of code: <? header('Location: http://google.com'); ?
> > When I request that action my browser simply renders a blank page.
> No redirect, no error. I don't understand how this could happen. I
> should either get a redirect to google or an error, but I get
> neither. My error reporting is set to E_ALL and E_DEPRECATED.
>
Most likely because you've got debug set to 0 in your core.php file. Set it
to not-0 and there'll be an error message dumped to the screen.
Even so, error messages are usually in:
your webserver error log,
your tmp/logs/errors.log
the screen
You need to read the real error message to see the mistake
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