PHP TCPDF使用一个命令创建多个PDF [英] PHP TCPDF Create Multiple PDFS With One Command

查看:59
本文介绍了PHP TCPDF使用一个命令创建多个PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用pdf导出数据.当我选择一条记录时,它可以正常工作...如何一键创建多个pdf? 这是我尝试过的

I want to export data with pdf.When i select one record it works fine...How to create multiple pdfs with one click? here is what i tried

require_once('eng.php');
require_once('tcpdf.php');
$pageLayout = array(750, 800); 
$pdf =new TCPDF('P', 'pt', $pageLayout, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->AddPage();
$html = 'my html';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
$pdf->Output('filename.pdf', 'D');

我该如何创建一个循环以创建更多pdf单独文件?

How i can put one loop to create more pdf seperate files?

推荐答案

以下代码对我有用:

使用variable的变量并循环创建新的pdf对象,使用'F'而不是'D'保存到服务器.

Use variable of variable and create new pdf object in loop, use 'F' instead of 'D' to save to server.

require_once('eng.php');
require_once('tcpdf.php');
$pageLayout = array(750, 800); 

$content=Array(
 '<html><body>Document A</body></html>',
 '<html><body>Document B</body></html>',
 '<html><body>Document C</body></html>'
);

foreach($content as $i=>$html){
$pdfname = $pdf . $i;
$$pdfname =new TCPDF('P', 'pt', $pageLayout, true, 'UTF-8', false);
$$pdfname->SetCreator(PDF_CREATOR);
$$pdfname->AddPage();
$$pdfname->writeHTML($html, true, false, true, false, '');
$$pdfname->lastPage();
$$pdfname->Output('filename_' . $i . '.pdf', 'D');
}

这篇关于PHP TCPDF使用一个命令创建多个PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆