问题描述
我使用Symfony2 kpn snappy捆绑包生成pdf.我想从带有CSS的html页面生成PDF.我找到了一个解决方案,但它有一个问题:
I`m using Symfony2 kpn snappy bundle to generate pdfs. I want to generate PDF from an html page with css. I found a solution, but it has a problem with :
$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
会重定向到该页面.
The problem is that the pageUrl accounts_management_generate_pdf_markup
is behind a security area and cannot be accessed without authentication. The generated file is just the login page, to which this path accounts_management_generate_pdf_markup
redirects if not logged.
我的问题是:
有什么方法可以传递给快速的身份验证凭据?
是否有另一种方法使用snappy bundle使用styles(css)生成pdf
Is there any way to pass to snappy authentication credentials?
Is there another way using snappy bundle to generate the pdf using styles(css)
推荐答案
您可以将会话cookie作为参数添加到getOutput函数:
You can add the session cookie as an argument to the getOutput function:
$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"'
)
);
这篇关于Symfony 2 Kpn snappy生成带有输出的pdf符合安全区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!