3

我想使用 barryvdh\laravel-snappy 创建 PDF 文件。我遵循了 github 页面上的所有步骤,但是每当我使用类似的功能时

$pdf->output();
$pdf->download("test.pdf");

我收到服务器错误。

我尝试使用安装程序以及作曲家依赖项在 Windows 上安装 wkthmltopdf。我清除了缓存,使用了 composer update,dump-autoload 等等。

这是我的控制器中的功能:

public function createInvoice($id)
    {
        $data = ["data" => "data"];
        $pdf = PDF::loadView("invoice.default", $data);

        dd($pdf);
        return response()->json([
            "pdf" => base64_encode($pdf->output())
        ]);
    }

我的 snappy.php 配置:

'pdf' => [
        'enabled' => true,
        'binary'  => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
        'timeout' => false,
        'options' => [],
        'env'     => [],
    ],

    'image' => [
        'enabled' => true,
        'binary'  => base_path('vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),
        'timeout' => false,
        'options' => [],
        'env'     => [],
    ],

我的 app.php 配置:

'providers' => [
.
.
    Barryvdh\Snappy\ServiceProvider::class,

.
.
.

'aliases'=> [
.
.
   'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
   'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,

当我在 $pdf 上使用 dd 时,在调用输出、下载、内联等函数之前,我得到以下响应:

PdfWrapper {#347
  #snappy: IlluminateSnappyPdf {#346
    #optionsWithContentCheck: array:4 [
      "header-html" => "html"
      "footer-html" => "html"
      "cover" => "html"
      "xsl-style-sheet" => "xsl"
    ]
    -binary: "C:\xampp\htdocs\invoicing\vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64"
    -options: array:125 [
      "ignore-load-errors" => null
      "lowquality" => true
      "collate" => null
      "no-collate" => null
      "cookie-jar" => null
      "copies" => null
      "dpi" => null
      "extended-help" => null
      "grayscale" => null
      "help" => null
      "htmldoc" => null
      "image-dpi" => null
      "image-quality" => null
      "manpage" => null
      "margin-bottom" => null
      "margin-left" => null
      "margin-right" => null
      "margin-top" => null
      "orientation" => null
      "output-format" => null
      "page-height" => null
      "page-size" => null
      "page-width" => null
      "no-pdf-compression" => null
      "quiet" => null
      "read-args-from-stdin" => null
      "title" => null
      "use-xserver" => null
      "version" => null
      "dump-default-toc-xsl" => null
      "dump-outline" => null
      "outline" => null
      "no-outline" => null
      "outline-depth" => null
      "allow" => null
      "background" => null
      "no-background" => null
      "checkbox-checked-svg" => null
      "checkbox-svg" => null
      "cookie" => null
      "custom-header" => null
      "custom-header-propagation" => null
      "no-custom-header-propagation" => null
      "debug-javascript" => null
      "no-debug-javascript" => null
      "default-header" => null
      "encoding" => null
      "disable-external-links" => null
      "enable-external-links" => null
      "disable-forms" => null
      "enable-forms" => null
      "images" => null
      "no-images" => null
      "disable-internal-links" => null
      "enable-internal-links" => null
      "disable-javascript" => null
      "enable-javascript" => null
      "javascript-delay" => null
      "load-error-handling" => null
      "load-media-error-handling" => null
      "disable-local-file-access" => null
      "enable-local-file-access" => null
      "minimum-font-size" => null
      "exclude-from-outline" => null
      "include-in-outline" => null
      "page-offset" => null
      "password" => null
      "disable-plugins" => null
      "enable-plugins" => null
      "post" => null
      "post-file" => null
      "print-media-type" => null
      "no-print-media-type" => null
      "bypass-proxy-for" => null
      "proxy" => null
      "radiobutton-checked-svg" => null
      "radiobutton-svg" => null
      "run-script" => null
      "disable-smart-shrinking" => null
      "enable-smart-shrinking" => null
      "stop-slow-scripts" => null
      "no-stop-slow-scripts" => null
      "disable-toc-back-links" => null
      "enable-toc-back-links" => null
      "user-style-sheet" => null
      "username" => null
      "window-status" => null
      "zoom" => null
      "footer-center" => null
      "footer-font-name" => null
      "footer-font-size" => null
      "footer-html" => null
      "footer-left" => null
      "footer-line" => null
      "no-footer-line" => null
      "footer-right" => null
      "footer-spacing" => null
      "header-center" => null
      "header-font-name" => null
      "header-font-size" => null
      "header-html" => null
      "header-left" => null
      "header-line" => null
      "no-header-line" => null
      "header-right" => null
      "header-spacing" => null
      "replace" => null
      "disable-dotted-lines" => null
      "cover" => null
      "toc" => null
      "toc-depth" => null
      "toc-font-name" => null
      "toc-l1-font-size" => null
      "toc-header-text" => null
      "toc-header-font-name" => null
      "toc-header-font-size" => null
      "toc-level-indentation" => null
      "disable-toc-links" => null
      "toc-text-size-shrink" => null
      "xsl-style-sheet" => null
      "viewport-size" => null
      "redirect-delay" => null
      "cache-dir" => null
      "keep-relative-links" => null
      "resolve-relative-links" => null
    ]
    -env: null
    -timeout: false
    -defaultExtension: "pdf"
    #temporaryFolder: null
    +temporaryFiles: []
    -logger: NullLogger {#345}
    +"fs": Filesystem {#109}
  }
  #options: []
  +"html": """
    <!DOCTYPE html>
    <html>
    <head>
    \t<title>Invoice<title>
    </head>
    <body>
    <div class="container">
    \t<table class="table table-bordered">
    \t\t<thead>
    \t\t\t<th>Name</th>
    \t\t\t<th>Email</th>
    \t\t</thead>
    \t\t<tbody>
    \t\t\t<tr>
    \t\t\t\t<td>TEST</td>
    \t\t\t\t<td>BEST</td>
    \t\t\t</tr>
    \t\t</tbody>
    \t</table>
    </div>
    </body>
    </html>
    """
  +"file": null
}

当我调用其中一个函数时,然后:

{
    "message": "Server Error"
}
4

1 回答 1

1

将二进制路径更改为

  'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf', //for ubuntu
        // 'binary'  => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"', //for windows
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltoimage', //for ubuntu
        // 'binary'  => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"', //for windows
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

你已经为 ubuntu 设置了。

于 2019-09-25T10:37:16.487 回答