简体   繁体   中英

Mixed PHP and HTML to pdf

I'm trying to use PhpToPdf libraries to export my page to pdf. However my page has mixed html and php outputs on it. This library requires to put all the markups in a php variable as a string to export it. But in my case the output is okay on html parts while it outputs plain php codes in the php part.

Example code:

<?php
require("phpToPDF.php"); 

$my_html="<HTML>
<h2>Test HTML 01</h2><br><br>
<h2><?php echo "Test HTML 01";?></h2>
</HTML>";

$pdf_options = array(
"source_type" => 'html',
"source" => $my_html,
"action" => 'save',
"save_directory" => '',
"file_name" => 'html_01.pdf');

phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='html_01.pdf'>Download Your PDF</a>");
?>

Output on the pdf file:

Test HTML 01

?php echo "Test HTML 01";?>

Is there any workaround to this problem?

You have already open PHP ...

 <?php
    $my_html="<HTML>
    <h2>Test HTML 01</h2><br><br>
    <h2><?php echo "Test HTML 01";?></h2>
    </HTML>";

Use:

$my_html="<HTML>
<h2>Test HTML 01</h2><br><br>
<h2>Test HTML 01</h2>
</HTML>";

or

$my_html="<HTML>
<h2>Test HTML 01</h2><br><br>
<h2>".$YourStrVariable."</h2>
</HTML>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM