将变量替换为TCPDF的WriteHtml()函数中的值


Substituting variables for their values in WriteHtml() function for TCPDF

我有两个表单字段,我想用用户在该表单中输入的值生成一个pdf。我使用tcpdf来完成这个任务。我不能让函数打印变量的值,而是打印在WriteHtml()函数中键入的任何内容。如何使代码工作?

HTML:

<html lang="en">
    <head>
        <title>Some Random PDF</title>
    <body>
           <h1>Enter relevant details</h1>
           <form action="form.php" method="post">

        <div class="form-group">
            <label for="inputName">Name of the partner</label>
            <input type="text" class="form-control" id="inputName" placeholder="" name="inputName">
             <span id="inputNameSpan"></span>
        </div> 

        <div class="form-group">   
          <label for="inputAddress">Address of the partner</label>
          <textarea type ="text" class = "form-control" id = "inputAddress" rows = "8" placeholder = "" name="inputAddress"></textarea>
          <span id="inputAddressSpan"></span>
        </div>


        <div class = "form-group">
        <center><button type="submit">SEND</button></center>
      </div>
    </form></center>
    </body>
</head>
PHP:

<?php
require_once('TCPDF/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$myName = $_POST['inputName'];
$myAddress = $_POST['inputAddress'];
$pdf->AddPage();
$html= '.htmlspecialchars($myName) lives in .htmlspecialchars($myAddress)';
$pdf->WriteHTML($html);
$pdf->Output();
?>

注:

假设($myName= John, $myAddress= New York City), PDF文件中需要/期望的输出。

约翰住在纽约市

任何帮助都是非常感激的。提前感谢!
$html= '.htmlspecialchars($myName) lives in .htmlspecialchars($myAddress)';

htmlspecialchars是PHP函数,确保它被识别为PHP脚本而不是字符串

一定要这样写

$html= htmlspecialchars($myName).' lives in '.htmlspecialchars($myAddress);

你需要设置输出类型I/F/FI。更多示例和解释请阅读文档http://www.tcpdf.org/

可以设置为$pdf->Output('yourfilename','I');