2009年7月15日星期三

[fw-mvc] howto: capture action output, stream it as pdf

I've searched the web, the docs and everything and still couldn't find an
answer to a difficult question:
How can you capture the output of an action [to stream it as pdf with
dompdf]?

In a controller I have an action like
<?php
function getPdfAction() {
// use a different layout
$this->getHelper('layout')->setLayout('pdf-layout.phtml');

// I need to call render halfways, so no auto render
$this->getHelper('viewRenderer')->setNoRender();

//1 start capture content. although the docs says it returns a string,
there is no
// return in render()
// I also don't understand why I need to supply thisController explicitly,
but anyways..
$this->view->render('thisController/template.tpl');

$outputBuffer = ob_get_contents();

$dompdf = new DOMPDF();
$dompdf->load_html(mb_convert_encoding($outputBuffer, 'html', 'UTF-8'));
$dompdf->render();
$dompdf->stream('hereisyourfile.pdf');
}
?>

How should I adapt this approach? Would it even be possible to capture the
output of an controller action in that very same action? Or do I need a
postDispatch?

Maybe it would be the nicest to have this html to pdf conversion as an
action helper, but is more important that I can deal with this simpler
problem.

I did not succeed with
$this->getFrontController()->setParam('disableOutputBuffering', true); in
preDispatch (which is ugly imho).
--
View this message in context: http://www.nabble.com/howto%3A-capture-action-output%2C-stream-it-as-pdf-tp24496539p24496539.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: