[英]Symfony2/html2pdf bundle - CSS ignored in pdf file
我正在使用html2pdf
包生成 pdf 文件。 我遵循了文档。 捆绑工作正常,我的 pdf 生成。 但是css被忽略了。 我在一个外部文件和引导 CDN 中有我的 css。 但没有变化。
但是,我创建了一条指向应该以 PDF 格式转换的视图的路由,并且 css 在 HTML 视图中运行良好。
我的控制器:
public function invoicPdfAction($id){
$em = $this->getDoctrine()->getManager() ;
$invoic = $em->getRepository('EcommerceBundle:Orders')->findOneBy(
array(
'user' => $this->getUser(),
'validate' => 1,
'id' => $id
));
if(!$invoic){
$this->addFlash('danger', 'La facture n\'existe pas ');
return $this->redirect($this->generateUrl('_invoic_user'));
}
$html = $this->renderView('UsersBundle:Public:User/invoicPDF.html.twig', array('invoic'=>$invoic));
$html2pdf = $this->get('html2pdf_factory')->create();
$html2pdf->pdf->SetDisplayMode('real');
$html2pdf->pdf->setSubject('Facture : My E-Commerce');
$html2pdf->pdf->setTitle('Facture : n°'. $invoic->getReference());
$html2pdf->writeHTML($html);
$html2pdf->Output('invoic.pdf') ;
return new Response($html2pdf->Output('invoic.pdf'), 200, array('Content-Type' => 'application/pdf'));
}
我的观点 invoicPDF.html.twig
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Facture</title>
<link rel="stylesheet" href="{{ asset('css/style_invoic.css') }}">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahauwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<h1> Facture de la commande n° : {{ invoic.reference }} </h1>
</div>
....
</div>
</body>
</html>
配置文件
ensepar_html2pdf:
orientation: P
format: A4
lang: fr
unicode: true
encoding: UTF-8
margin: [10,15,10,15]
我错过了什么?
提前致谢
html2pdf 忽略外部文件你必须在你的 pdf 中写你的 css 感谢:/* css */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.