duanhan8757 2019-08-08 17:33
浏览 249

尝试使用用户输入填充pdf模板

I have a pdf template that I made. I am working on a real estate website that asks users for information regarding their properties and displays those answers neatly in a pdf flyer that they can download. My question is what is the best way to go about this? I downloaded FPDI so I can work off an existing template but I dont see how I can pass PHP variables to the Write() function. I also downloaded TCPDF but I cant seem to get it to work together with FPDI.

use setasign\Fpdi\Fpdi;

require_once('vendor/setasign/fpdf/fpdf.php');
require_once('vendor/setasign/fpdi/src/autoload.php');
require_once('vendor/tecnickcom/tcpdf/tcpdf.php');
//initiate FPDI
$pdf = new Fpdi();
$date = Date('d - m - Y');

$pageCount = $pdf->setSourceFile('C:/Users/19292/Desktop/flyer-template.pdf');

$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);

for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    if($pageNo === 1) {
        //If its the first page of your pdf
        $templateId = $pdf->importPage($pageNo);
        $pdf->AddPage();
        $pdf->useTemplate($templateId, ['adjustPageSize' => true]);

        $pdf->SetXY(10, 10);
        $pdf->Write(0, 'Title to the left on your first page');
        $pdf->write($date,true,0,false,false,'left');
    } else if($pageNo === 2) {
        $templateId = $pdf->importPage($pageNo);
        $pdf->AddPage();
        $pdf->useTemplate($templateId, ['adjustPageSize' => true]);

        $pdf->SetXY(220, 10);

    }
}
$pdf->Output();
?>

not sure what exactly should be required, what should be used to get the output that I want.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试