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