带有Javascript的Laravel 4 render()PDF
我需要使用Javascript API从HTML视图渲染创建PDF 这是我在PHPLaravel4中的代码带有Javascript的Laravel 4 render()PDF,javascript,html,pdf,dom,laravel-4,Javascript,Html,Pdf,Dom,Laravel 4,我需要使用Javascript API从HTML视图渲染创建PDF 这是我在PHPLaravel4中的代码 $con = Contrato::find($id); $html = (string) View::make('contratos.contratopdf')->with('con',$con)->render(); return PDF::load(utf8_decode($html), 'A5', 'landscape')->show
$con = Contrato::find($id);
$html = (string) View::make('contratos.contratopdf')->with('con',$con)->render();
return PDF::load(utf8_decode($html), 'A5', 'landscape')->show();
在视图中,我有这个脚本
<script src="http://test.rentacar.cl/js/lib/jquery.signaturepad.min.js"></script>
这个js改变了普通HTML中的Dom,但是当我在PDF中显示时就不起作用了
谢谢 根据我对dompdf(非常著名的pdf库)的经验,这些库不支持JS解释(因为php没有解释javascript的能力),我认为您可以尝试以下两种方法 1.服务器端呈现html,将dom操作移动到php以创建dom元素。(推荐)
2.使用php和phantomJS。php调用phantomJS来捕获html屏幕并将屏幕截图保存为pdf。phantomJS工作得很好,请查看此软件包: 此处有完整的文档: 例如:
<?php
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
$request = $client->getMessageFactory()->createCaptureRequest('http://google.com');
$response = $client->getMessageFactory()->createResponse();
$file = '/path/to/save/your/screen/capture/file.jpg';
$request->setCaptureFile($file);
$client->send($request, $response);
您能否提供更多关于如何使用Phantom的上下文,而不仅仅是转储到该工具的链接?我已经更新了我的答案,添加了到完整文档和有效代码示例的链接。