Laravel Snappy PDF如何显示图像

时间:2019-11-12 17:35:41

标签: laravel-5 snappy laravel-snappy

我对快速包装有问题。我正在尝试使用外部图像生成pdf,但是这样做时出现错误:

$pdf = PDF::loadView('admin-customer.tag.pdf-view', $product)
    ->setOption('page-width', '100')
    ->setOption('page-height', '70.5')
    ->setOption('margin-top', 2)
    ->setOption('margin-bottom', 2)
    ->setOption('margin-left', 2)
    ->setOption('margin-right', 2);
    return $pdf->download($product->name . '.pdf');

我的观点:

<div class="qrcode">
            <img src="//api.qrserver.com/v1/create-qr-code/?data=http://trackagro.com.br" alt="">
            <h6 class="msg">
                CONSULTE PELO SEU LEITOR DE QR-CODE OU EM NOSSO SITE TRACKAGRO.COM.BR
            </h6>
        </div>

错误:

Page 1 of 1 Done Exit with code 1 due to network error: ContentNotFoundError " stdout: "" command: D:\Projects\empresas\trackagro\trackagro-sistema\vendor\wemersonjanuario\wkhtmltopdf-windows\bin\64bit\wkhtmltopdf --lowquality --margin-bottom "2" --margin-left "2" --margin-right "2" --margin-top "2" --page-height "70.5" --page-width "100" "C:\Users\PopApps\AppData\Local\Temp\knp_snappy5dcaeaf096db73.71503659.html" "C:\Users\PopApps\AppData\Local\Temp\knp_snappy5dcaeaf09905f2.88209190.pdf".

1 个答案:

答案 0 :(得分:0)

我一直在研究并设法解决使用另一个库来生成qrcode的问题,该问题会在SVG中生成图像: https://www.simplesoftware.io/simple-qrcode/

我的代码:

$pdf = PDF::loadView('admin-customer.tag.pdf-view', $product)
    ->setOption('page-width', '100')
    ->setOption('page-height', '70.5')
    ->setOption('margin-top', 2)
    ->setOption('margin-bottom', 2)
    ->setOption('margin-left', 2)
    ->setOption('margin-right', 2)
    ->setOption('images', true);
    return $pdf->download($product->name . '.pdf');

我的观点:

<img src="data:image/png;base64, {{ base64_encode(QrCode::format('png')->size(100)->generate('http://trackagro.com.br')) }}" />

非常感谢