【发布时间】:2011-11-16 11:17:39
【问题描述】:
我有一个 PHP 文件,其中包含来自 MySQL 数据库的数据。如何将 PHP 脚本的输出转换为 PDF
文件#1:
<?php
require(path . "/includes/header.php"); //header for html
require(path . "/includes/database.php"); //database settings
$c_id = $_GET['id']; //id for query;
$c_name="";
$c_image=array();
$sql1 = "SELECT cr_name FROM cr WHERE cr_id=$c_id";
$sql2 = "SELECT ci.cr_image FROM cr_image ci INNER JOIN cr_image_rel cir ON ci.cr_image_id = cir.cr_image_id WHERE cir.cr_id=$c_id";
if ($result = $dbLink->query($sql1)) {
while ($row = $result->fetch_row()) {
$c_name = $row[0];
}
}
if ($result = $dbLink->query($sql2)) {
while ($row = $result->fetch_row()) {
array_push($c_image,$row[0]);
}
}
?>
<div id="c_detail">
<div class="info_section">
<h2 class="section_title">Crop</h2>
<?php
echo '<h3>' . $c_name . '</h3>';
?>
<div>
<?php
foreach ($c_image as $i=>$v){
echo '<a class="c_thumb_image" title="Image Preview" href="user_image/' . $v . '"><img src="user_image/thumb_' . $v . '"/></a>';
}
?>
<div class="clear"></div>
</div>
</div>
</div>
<?php
$dbLink->close();
?>
我想使用 PHP、jQuery 或任何合适的工具创建/转换文件 #1 的输出为 PDF?我已经尝试过使用tcpdf,但它不起作用...
<?php
....
....
$html = stripslashes(read("crop_detail.php", $vars));
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('example_006.pdf', 'I');
?>
PDF 已渲染,但没有内容;页面是空白的!
有什么建议吗?
【问题讨论】:
-
什么???您能详细说明文件包含的内容吗?有很多方法可以在 PHP 中创建 PDF - 谷歌是你的朋友
-
如果您在服务器上具有 root 访问权限,则可以使用 apache 的 XSL-FO。欲了解更多信息de.wikipedia.org/wiki/…
-
@ManseUK Google 在这里领先。