【发布时间】:2018-01-14 19:58:30
【问题描述】:
我正在使用 PHP Laravel 框架开发网站。我的网站需要实现生成 PDF 报告的功能。在那个 PDF 报告中,我在 HTML 画布上绘制了一张图片。我正在使用this library 生成 PDF 报告。我可以生成报告,问题是报告中没有包含画布。
这是我的控制器生成 PDF 报告并在浏览器中显示。
class ReportController extends Controller
{
//
function invoice(){
$pdf = PDF::loadView('report.invoice');
return $pdf->stream();
}
}
这是我的pdf报告视图文件。
<h1>Report</h1>
<table border="1" style="width: 100%;">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Title 1</td>
<td>1000</td>
</tr>
<tr>
<td>2</td>
<td>Title 2</td>
<td>200</td>
</tr>
</tbody>
</table>
<canvas id="myCanvas" width="400" height="200">
</canvas>
<script type="text/javascript">
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var center_x = 200;
var center_y = 100;
var width = 100;
var height = 200;
drawOvalShape(context, 200, 100, 100, 200);
drawOvalShape(context, 200, 100, 80, 180);
drawOvalShape(context, 200, 100, 60, 160);
drawOvalShape(context, 200, 100, 40, 140);
drawOvalShape(context, 200, 100, 20, 120);
function drawOvalShape(context, center_x, center_y, width, height){
context.beginPath();
context.ellipse(center_x, center_y, width, height, 90 * Math.PI/180, 0, 2 * Math.PI);
context.stroke();
}
</script>
但是当它显示在浏览器中时,HTML 画布会从报告中移除。但其他 html 元素按预期工作。为什么会被移除?如何在我的 PDF 报告中包含画布?我的代码有什么问题?
我也在这样的 dompdf.php 配置文件中将 html5parser 设置为 true
"DOMPDF_ENABLE_HTML5PARSER" => true,
这不仅仅是工作。
【问题讨论】: