【问题标题】:Symfony 2 kpn snappy generate pdf with output meets security areaSymfony 2 kpn snappy 生成 pdf 输出符合安全区域
【发布时间】:2013-11-29 12:37:01
【问题描述】:

我正在使用 Symfony2 kpn snappy bundle 来生成 pdf。我想从带有 css 的 html 页面生成 PDF。我找到了一个解决方案,但它有一个问题:

    $pageUrl = $this->generateUrl('accounts_management_generate_pdf_markup',
    array('invoice' => $invoiceData), true); // use absolute path!

    return new \Symfony\Component\HttpFoundation\Response(
        $this->get('knp_snappy.pdf')->getOutput($pageUrl), 200, array(
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'attachment; filename="file.pdf"'
        )
    );

问题是 pageUrl accounts_management_generate_pdf_markup 位于安全区域后面,未经身份验证无法访问。生成的文件只是登录页面,如果没有记录,此路径accounts_management_generate_pdf_markup 将重定向到该页面。

我的问题是:

有什么方法可以传递给 snappy 的身份验证凭据?
是否有另一种方法使用 snappy bundle 使用样式(css)生成 pdf

【问题讨论】:

    标签: php symfony pdf bundle


    【解决方案1】:

    您可以将会话 cookie 作为参数添加到 getOutput 函数:

            $pageUrl = $this->generateUrl('route', array('id' => $id), true);
            $session = $this->get('session');
            $session->save();
            session_write_close();
    
            return new Response(
                $this->get('knp_snappy.pdf')->getOutput($pageUrl, array('cookie' => array($session->getName() => $session->getId()))),
                200,
                array(
                    'Content-Type'          => 'application/pdf',
                    'Content-Disposition'   => 'attachment; filename="file.pdf"'
                )
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2015-07-29
      • 2019-06-30
      • 2014-03-28
      • 2015-05-15
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多