2017-03-16 77 views
0

我想將html頁面轉換爲pdf文件。我沒有問題,使用$view->display();。這裏的CSS格式正確顯示。但是,當我嘗試使用$dompdf來代替時,css看起來很混亂而且不同。我在這裏需要一些幫助使用dompdf修復html爲pdf(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(); 
    } 
+0

從您的佈局引用的CSS是如何?因爲如果使用不包含域的URI引用CSS,則使用'loadHtml',那麼它可能指向錯誤的位置。另外......「亂七八糟」是什麼意思?它根本沒有工作,或只是沒有做你期望的事情? – BrianS

回答

0

嘗試外部CSS在網頁上

等; -

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

DOMPDF有應用CSS

的一些限制

嘗試: - 刪除額外的CSS,並做出簡單的其他CSS文件導入像(鏈接和嘗試) 高級CSS不工作純CSS應用