【问题标题】:Ignited/Laravel-pdf - White screen of death - Unable to generate PDFs点燃/Laravel-pdf - 白屏死机 - 无法生成 PDF
【发布时间】:2014-03-19 19:33:50
【问题描述】:

这可能是一个非常简单的,但我无法让它工作......

我想从 Blade View 生成 PDF。

为了做到这一点,我通过 composer 安装了:

    "ignited/laravel-pdf": "1.*",
    "h4cc/wkhtmltopdf-i386": "*",
    "h4cc/wkhtmltopdf-amd64": "*"

我的服务提供者和门面设置如下:

    'Ignited\Pdf\PdfServiceProvider',
    'PDF'             => 'Ignited\Pdf\Facades\Pdf'  

我已经发布了配置设置并尝试了两种配置。

return array(
    # Uncomment for 32-bit systems
    'bin' => base_path() . '/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386'

    # Uncomment for 64-bit systems
    #'bin' => base_path() . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'

    # Add any global Wkhtmltopdf options here
    #'no-outline',
    #'margin-top'    => 0,
    #'margin-right'  => 0,
    #'margin-bottom' => 0,
    #'margin-left'   => 0,
);

我的控制器如下:

public function getPDF($id)
{
    $pdf = PDF::make();
    $pdf->addPage('<html><head></head><body><b>Hello World</b></body></html>');
    $pdf->send();
}

但是当我访问该页面时,我只是得到一个白屏。

一旦我最终显示 Hello World,我希望能够将视图传递给它以呈现为 PDF。

我的想法是,laravel-pdf 根本没有做任何事情,就像我在 $pdf-&gt;send() 之后 dd('helloooo') 一样,当我在浏览器中访问该页面时,我只是得到 string(8) "helloooo"

有什么想法还是我太笨了?

【问题讨论】:

  • 您是否运行过 composer installcomposer dump-autoload? WSOD 也通常是因为文件系统写入权限问题

标签: php pdf laravel wkhtmltopdf


【解决方案1】:

你为什么不在 app/routes.php 文件中试试这个?

Route::get('pdfhello', function() {
    $pdf = PDF::make();
    $html = View::make('hello');
    $pdf->addPage($html);
    $pdf->send('hola.pdf');
});

重要提示:app/view/hello.php 中的以下行似乎引发了白屏死机。

@import url(//fonts.googleapis.com/css?family=Lato:700);

可能是一些 CSS 指令,也可能是一些刀片指令,导致无法创建 pdf 文件。

【讨论】:

    猜你喜欢
    • 2015-06-19
    • 1970-01-01
    • 2012-09-13
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2011-02-24
    • 1970-01-01
    相关资源
    最近更新 更多