0

I am trying to convert the html page to a pdf file. I have no problem using $view->display();. The css format are displaying properly in here. However, when I try to use the $dompdf instead, the css seems to be a mess and different. I need some help here

  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();
    }
fypforstack
  • 47
  • 1
  • 9
  • How is the CSS referenced from your layout? Since you're using `loadHtml` if the CSS is referenced using a URI that does not include the domain then it may be pointing to the wrong location. Also ... what exactly do you mean by "a mess and different"? Is it not working at all, or just not doing what you expect? – BrianS Mar 16 '17 at 22:19

1 Answers1

0

try External css on your page

like;-

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

Dompdf have some limitation of applying css

try :- remove extra css and make simple other css file import like (link and try) advance css not worked pure css apply