我有一些函数可以获取样式表,并使用PHP中的OOP从其他类获取输出。我需要生成的pdf使用TCPDFm,但我面临着如何在$html变量传递的问题,我已经阅读了使用pass使用手册,这并没有解释XHTML+变量输出。我在这里粘贴我的代码,请帮助我。
<?php
// define some HTML content with style
$html = <<<EOF
<?php $frame->HTML_DOCTYPE(); ?>
<html>
<head><?php $frame->HTML_Title($page); $frame->HTML_CSS($page); $frame->HTML_JS($page); ?></head>
<body>
<div class='container_pngfix'>
<?php echo $frame->Print_Top($page); ?>
<div class='container_magazine'>
<div class='magazine_left'>
<?php
/*if(FALSE == empty($_SESSION['wi_id']) && FALSE == empty($_SESSION['wi_type']) && 0 == strcasecmp('bride',$_SESSION['wi_type'])){*/
if ($_REQUEST['magazineId']!="") {
echo $article->Print_Magazine_Issue($_REQUEST['magazineId']);
} else if ($_REQUEST['latestissue']) {
echo $article->Print_Magazine_Issue($article->getLatestMagazineId());
} else {
if (isset($_REQUEST['magazinedate'])) { $magazinedate=$_REQUEST['magazinedate']; } else { $magazinedate=""; }
if ($magazinedate=="") { $magazinedate=date("Y-m")."-01"; }
echo $article->Print_Magazine($magazinedate);
}
/*}else{
echo "<h2>Please Login/Register first to see Magazine details</h2>";
}*/
?>
</div>
<div class='magazine_right'><?php echo $frame->Print_RightSide_Articles($page); ?></div>
<div class='clearfloat'> </div>
<?php echo $frame->get_ContextualWeb($page,"low"); ?>
</div>
</div>
<?php echo $frame->Print_Bottom_Links($page); ?>
<?php $frame->Print_Bottom($page); ?>
</div>
</body>
</html>EOF;
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_061.pdf', 'I');
?>在这段代码中,我使用这些类的对象调用多个函数。页面的所有html和内容都是动态生成的。我有在$html变量中传递页面html和PHP代码的问题。
发布于 2012-08-31 19:06:05
您可以使用ob_start()和ob_get_clean()来获取任何输出。
<?php
ob_start();
?>
<!-- HTML and PHP code here -->
<?php
$html = ob_get_clean();
?>$html将您的数据发送到TCPDF。
针对您的情况的示例:
<?php
// your other script
ob_start();
?>
<?php $frame->HTML_DOCTYPE(); ?>
<html>
<head><?php $frame->HTML_Title($page); $frame->HTML_CSS($page); $frame->HTML_JS($page); ?></head>
<body>
<!-- rest of the page -->
</body>
</html>
<?php
$html = ob_get_clean();
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_061.pdf', 'I');
?>https://stackoverflow.com/questions/12213875
复制相似问题