Symfony2 / html2pdf包 - 在pdf文件中忽略CSS

时间:2016-04-24 16:39:10

标签: html css symfony html2pdf

我使用html2pdf捆绑生成pdf文件。我按照文档。捆绑工作正常我的pdf生成。但是css被忽略了。我在外部文件和bootstrap 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>

config.yml

ensepar_html2pdf:
    orientation: P
    format: A4
    lang: fr
    unicode: true
    encoding: UTF-8
    margin: [10,15,10,15]

我错过了什么?

提前致谢

1 个答案:

答案 0 :(得分:1)

html2pdf忽略extern文件 你必须在pdf中写下你的css,这要归功于:/ * css * /