使用dompdf(CSS)将html修复为pdf

时间:2017-03-16 10:28:06

标签: html css pdf dompdf

我正在尝试将html页面转换为pdf文件。我使用$view->display();没问题。 css格式在这里正确显示。但是,当我尝试使用$dompdf时,css似乎是混乱而且不同。我需要一些帮助

  public function testPDF(){
        $view = View::loadView('agentpanel/invoice_header.php');   
        $invoice_view = View::loadView('agentpanel/invoice_view.php');
        $company = Company::fetch(1);
        $client  = Client::fetch(1);
        $invoice = Invoice::fetch(1);
        $invoice_view->addData(['company'           => $company,
                                'client'            => $client,
                                'template'          => $company->invoiceTemplate,
                                'availableProducts' => [],
                                'availableForms'    => [],
                                'sales'             => $invoice->sales->all(true),
                                'inv'               => $invoice,
                                'mode'              => 'view'
        ]);

        $invoice_view->set('date', date("M, d Y",time()));
        $view->set('invoice_view', $invoice_view->render());
        $view->display();
    } 

DOMPDF

   public function testPDF1(){
        $view = View::loadView('agentpanel/invoice_header.php');   
        $invoice_view = View::loadView('agentpanel/invoice_view.php');
        $company = Company::fetch(1);
        $client  = Client::fetch(1);
        $invoice = Invoice::fetch(1);
        $invoice_view->addData(['company'           => $company,
                                'client'            => $client,
                                'template'          => $company->invoiceTemplate,
                                'availableProducts' => [],
                                'availableForms'    => [],
                                'sales'             => $invoice->sales->all(true),
                                'inv'               => $invoice,
                                'mode'              => 'view'
        ]);

        $invoice_view->set('date', date("M, d Y",time()));
        $view->set('invoice_view', $invoice_view->render());
         $dompdf = new Dompdf();

        $dompdf->loadHtml($view->render());
        $dompdf->setPaper('A4', 'landscape');
        $dompdf->render();  
        $dompdf->stream();
    }

1 个答案:

答案 0 :(得分:0)

在您的网页上尝试外部css

喜欢; -

<link rel="stylesheet" href="http:****.css" type="text/css"/>

Dompdf有一些应用css的限制

尝试: - 删除额外的css并使其他简单的css文件导入(链接和尝试) 提前css没有工作纯css申请