【问题标题】:Fixing html to pdf using dompdf (CSS)使用 dompdf (CSS) 将 html 修复为 pdf
【发布时间】:2017-03-16 10:28:05
【问题描述】:

我正在尝试将 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();
    }

【问题讨论】:

  • 如何从您的布局中引用 CSS?由于您使用的是loadHtml,如果使用不包含域的 URI 引用 CSS,那么它可能指向错误的位置。另外......你所说的“一团糟和不同”到底是什么意思?它根本不起作用,还是没有达到您的预期?

标签: html css pdf dompdf


【解决方案1】:

在您的页面上尝试外部 css

喜欢;-

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

Dompdf 应用 css 有一些限制

try :- 删除多余的 css 并进行简单的其他 css 文件导入,例如(链接并尝试) 高级 css 不起作用纯 css 应用

【讨论】:

    猜你喜欢
    • 2012-12-07
    • 2011-06-17
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2013-04-22
    相关资源
    最近更新 更多