2012-08-31 40 views
1

我有一些函数,它使用样式表&从PHP中使用OOP获取其他类的输出。 我需要使用TCPDFm生成PDF,但我面临着如何传递$ html变量的问题,我已经阅读了XHTML + CSS使用手册,它没有解释PHP变量输出。 我在这里打开我的代码,请帮助。如何在TCPDF中使用php函数和变量生成pdf

<?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'>&nbsp;</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 &页面内容都是动态生成的。我有PHP HTML代码在$ html变量中传递的问题。

回答

2

您可以使用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'); 
?> 
+0

你可以写我的使用情况下,一个小例子。那是使用函数,会更有帮助 – Ankit

+0

增加了一个例子..祝你好运 –

+0

你有什么错误吗? –