2015-04-02 83 views
2

PDF我需要創建從HTML視圖與的JavaScript APILaravel 4渲染()的JavaScript

渲染PDF這是我在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(); 

在我此腳本的觀點

<script src="http://test.rentacar.cl/js/lib/jquery.signaturepad.min.js"></script> 

這個js改變DOM在一個普通的HTML,但是當我顯示PDF不起作用。

謝謝!

回答

0

PhantomJS工作得很好,看看這個包:https://github.com/jonnnnyw/php-phantomjs

完整的文檔在這裏:http://jonnnnyw.github.io/php-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); 
+0

你能提供多一點的背景下,以鬼怪會怎樣使用,而不是隻是傾銷鏈接到工具? – 2015-09-29 19:47:01

+0

我已經更新了我的答案,並提供了完整文檔和有效代碼示例的鏈接。 – 2015-09-30 12:05:10

0

從我的dompdf(非常有名的pdf庫)的經驗來看,這些庫不支持JS解釋(因爲php沒有解釋javascript的能力),下面是兩種方法,我認爲你可以嘗試。

1.Server端渲染HTML中,將您的DOM操作,以創建DOM元素到PHP。(推薦)

2.使用PHP和phantomJS.The PHP調用phantomJS捕捉到HTML的屏幕和將截圖保存爲pdf。