I need create a PDF from an HTML view rendering with Javascript Apis
This is my code in PHP Laravel 4
$con = Contrato::find($id);
$html = (string) View::make('contratos.contratopdf')->with('con',$con)->render();
return PDF::load(utf8_decode($html), 'A5', 'landscape')->show();
In the view I have this script
<script src="http://test.rentacar.cl/js/lib/jquery.signaturepad.min.js"></script>
This js change the Dom in a normal HTML but when I show in PDF don't work.
Thanks!!
From my experience of dompdf(very famous pdf library),those library don't support JS interpreting(because the php don't have the power to interpret the javascript),here are two workaound I think you can try.
1.Server side rendering html,move your dom manipulation to php in order to create the dom element.(Recommended)
2.Use php and phantomJS.The php call phantomJS to capture the screen of html and saved the screenshot to pdf.
PhantomJS works nicely, take a look at this package: https://github.com/jonnnnyw/php-phantomjs
Full documentation here: http://jonnnnyw.github.io/php-phantomjs/
Example:
<?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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.