Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 基于foreach和while的TCPDF时HTML转换为PDF_Php_Html_Pdf - Fatal编程技术网

Php 基于foreach和while的TCPDF时HTML转换为PDF

Php 基于foreach和while的TCPDF时HTML转换为PDF,php,html,pdf,Php,Html,Pdf,这可能已经得到了回答,是的,我使用了谷歌,这里的搜索stackoverflow,但问题仍然存在 我正在使用TCPDF库生成PDF文件,它工作得很好,但我有以下情况,为了生成PDF而不是HTML,我需要在HTML中放入一些foreach和while's和IF's,这样我就可以得到用户请求的布局 所以… if(isset($_POST['submit'])) { $ids = htmlentities($_POST['id'], ENT_NOQUOTE; $con = conectionDB();

这可能已经得到了回答,是的,我使用了谷歌,这里的搜索stackoverflow,但问题仍然存在

我正在使用TCPDF库生成PDF文件,它工作得很好,但我有以下情况,为了生成PDF而不是HTML,我需要在HTML中放入一些foreach和while's和IF's,这样我就可以得到用户请求的布局

所以…

if(isset($_POST['submit'])) {
$ids = htmlentities($_POST['id'], ENT_NOQUOTE;
$con = conectionDB();
$query 'SELECT * FROM books WHERE id = "$ids"';
$doit = $con->query($query);
// at this point everything is file
// a few if's and we are done with the fetching "books" data
// a few other tuff that is required from the library nothing fancy...
// now here is the hard part
// next line will build my layout to display my PDF
$build_HTML = <<<EOD
<style>
.clasess {...}
.nother {...}
</style>
<table width="100%" border="1" cellpadding="0" bordercolor="#333333" >
<tr>
<td>Author</td>
<td>Books</td>
</tr>
<tr>
<td> Jong </td>
<td>
<table>
<tr>
<td>Title</td><td>Year</td>
</tr>
// Here is the problem I need to put a query to fetch the related data from
// another table
$books = conectionDB();
$bookQ = "SELECT * FROM titles WHERE name = '$author_name'";
$doitTitles = $books->query($bookQ);
if ($doitTitles->num_row > 1) {
while($dos = $doitTitles->fetch_assoc()){
// my td's, but this doest work...
}
}
</table>
</td>
</tr>
</table>
EOD;
$pdf->writeHTML($build_HTML, true, false, false, false, '');
} else {
// Go back...
}
if(isset($\u POST['submit'])){
$ids=htmlentities($_POST['id'],ENT\u NOQUOTE;
$con=conectionDB();
$query'从id=“$ids”的书籍中选择*;
$doit=$con->query($query);
//在这一点上,一切都是文件
//几个if,我们就完成了获取“books”数据的工作
//图书馆需要的其他一些凝灰岩没什么特别的。。。
//现在是最难的部分
//下一行将构建我的布局以显示我的PDF
$build_HTML=1){
而($dos=$doititles->fetch_assoc()){
//我的td是,但这不起作用。。。
}
}
排爆药;
$pdf->writeHTML($build_HTML,true,false,false,”);
}否则{
//回去。。。
}
正如您看到的,我需要这个查询,您可能已经注意到我有$doititles->num_row>1为什么?因为如果有超过1个标题,如果只有1个记录,布局就会不同

我们知道,这是行不通的,所以问题是,还有其他方法可以做到这一点吗?
现在,在用户进入PDF之前,我用纯html显示信息,这意味着我在用户进入PDF之前使用的html将是相同的。。。所以我想知道,有没有另一个库,我可以使用它将HTML呈现为PDF,而不是从文件内部构建PDF。。。用户可以看到结果,所以这些结果只是把他们放在一个PDF


谢谢大家!

我有一个解决方案,所以问题是我正在尝试输出一个用动态内容构建的html,如果要显示为任何其他页面,my_page.html没有问题,但是在PDF中使用
$raw_html = 'Tables';
// a few while and foreach's and queries
$raw_html .='Closed tables';
// Ready the HTML
$html = <<<EOD
$raw_html
EOD;
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->Output('pdf_file_with_dynamic_html.pdf', 'I');
// the end.