【问题标题】:Passing custom-header arguments to Knp SnappyBundle将自定义标头参数传递给 Knp SnappyBundle
【发布时间】:2019-04-15 12:08:23
【问题描述】:

我在 Symfony 4 中使用 Knp SnappyBundle。

我无法通过 yaml 或请求中的选项将自定义标头参数 (--custom-header <name> <value>) 传递给 wkhtmltopdf

这是我正在尝试的,似乎失败了:

knp_snappy:
  temporary_folder: "%kernel.cache_dir%/snappy"
  pdf:
    enabled: true
    binary: xvfb-run wkhtmltopdf
    options:
      - { name: 'custom-header', value: '%app_auth_header_name%' '%app_auth_header_token%'  }

我也尝试将值作为数组传递,但这也失败了。

【问题讨论】:

    标签: php symfony yaml wkhtmltopdf knp-snappy


    【解决方案1】:

    我已经部分解决了,不幸的是不是通过yaml,而是直接在代码示例中:

       public function getPdfBinary($url, Pdf $pdfService): PdfResponse
        {
            $url = urldecode($url);
            $res = new PdfResponse($pdfService->getOutput($url, ['custom-header' =>
                [ 'X-Authorization' => 'mytoken' ] ]),'output.pdf');
            return $res;
    

    yaml 期望自定义标头的标量值...

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多