【发布时间】:2013-11-08 01:55:15
【问题描述】:
对, 我已经为 wkhtmltopdf (https://github.com/ignited/laravel-pdf) 安装了服务提供者 当我添加
Route::get('/', function() {
$pdf = PDF::make();
$pdf->addPage('<html><head></head><body><b>Hello World</b></body></html>');
$pdf->send();
});
在我的 routes.php 中它会生成一个 pdf 文件。
我要做的是将整个 div 发布到我的控制器,然后从中生成一个 PDF。
我的表格:
<form id="convert" action="{{{ URL::to('') }}}/pdf" method="post">
<input type="hidden" name="body" id="body">
<input type="submit" class="btn btn-success pdf" value="Done? Convert to PDF!">
</form>
jQuery:
$('form#convert').submit(function(){
$("input#body").val($("#preview").html());
});
routes.php:
Route::post('pdf', 'PdfController@index');
最后是我的控制器 (PdfController):
<?php
class PdfController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$data = Input::get('body');
$pdf = PDF::make();
$pdf->addPage($data);
$pdf->send('test.pdf');
if(!$pdf->send())
return $pdf->getError();
}
}
不知何故,我认为这是一个基本的 POST 与 GET 的事情,或者我做的不对。
现在我收到错误Could not run command '/var/www/docassembly/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'
但是如果我用直接的 html 替换控制器中的变量,我会得到同样的错误。
如果我在表单和路由中使用 GET 并将直接 html 作为参数传递,则错误是不同的:
Could not run command '/var/www/docassembly/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64' test /tmp/tmp_WkHtmlToPdf_Hq98EZ: Loading pages (1/6) [> ] 0% [======> ] 10% [============================================================] 100% Error: Failed loading page http://test (sometimes it will work just to ignore this error with --load-error-handling ignore)
因此将它放在控制器中也是一个问题。 有线索吗?
【问题讨论】:
标签: post laravel laravel-routing