首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从TCPDF中的php函数和变量生成pdf

如何从TCPDF中的php函数和变量生成pdf
EN

Stack Overflow用户
提问于 2012-08-31 18:53:04
回答 1查看 2.5K关注 0票数 1

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

代码语言:javascript
复制
<?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和内容都是动态生成的。我有在$html变量中传递页面html和PHP代码的问题。

EN

回答 1

Stack Overflow用户

发布于 2012-08-31 19:06:05

您可以使用ob_start()ob_get_clean()来获取任何输出。

代码语言:javascript
复制
<?php
    ob_start();
?>
    <!-- HTML and PHP code here -->
<?php
    $html = ob_get_clean();
?>

$html将您的数据发送到TCPDF。

针对您的情况的示例:

代码语言:javascript
复制
<?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');
?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12213875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档