Welcome Guest, Not a member yet? Register   Sign In
Open the view in browser as html page, not as pdf using DOMPDF
#1

(This post was last modified: 04-04-2023, 12:12 AM by nadeem14375.)

Hi,

I am using Codeigniter 4, with DOMPDF.
My controller works, but open the view in browser as html page, not as pdf page, I want to download the pdf.

Code:
public function invoice_pdf()
    {

        $request = \Config\Services::request();

    $id = $request->getPost('id');

        $main_model = new MainModel;
        $this->data['invoice_list']= $main_model->list_invoice($id);

        $dompdf = new \Dompdf\Dompdf();
        $dompdf->loadHtml(view('list_invoice_pdf', $this->data));
        $dompdf->setPaper('A4', 'landscape');

        $dompdf->set_option('isHtml5ParserEnabled', true);
        $dompdf->render();
        $dompdf->stream();
    }

regards:
Reply
#2

The following code works for me:
PHP Code:
$dompdf = new \Dompdf\Dompdf();
$dompdf->loadHtml(view('Modules\Intranet\Views\pdf_view'));
$dompdf->setPaper('A4''landscape');
$dompdf->render();
$dompdf->stream('myFile.pdf'); 

With the following pdf_view.php:
PHP Code:
<?php
echo '<p>PDF File</p>'

I can't tell why it is not working for you.
Reply
#3

(04-04-2023, 01:19 AM)JustJohnQ Wrote: The following code works for me:
PHP Code:
$dompdf = new \Dompdf\Dompdf();
$dompdf->loadHtml(view('Modules\Intranet\Views\pdf_view'));
$dompdf->setPaper('A4''landscape');
$dompdf->render();
$dompdf->stream('myFile.pdf'); 

With the following pdf_view.php:
PHP Code:
<?php
echo '<p>PDF File</p>'

I can't tell why it is not working for you.

The problem, is that, it display / view as html page in browser, but i want to a pdf file/ output.
Reply
#4

I understand. The samples I sent you generate a PDF which is downloaded in my download folder.
Also, in Firefox setttings - Applications, PDF's are to be opened by Windows default application which is Adobe Acrobat on my system.
What's in your view?
Reply
#5

(04-04-2023, 12:11 AM)nadeem14375 Wrote: Hi,

I am using Codeigniter 4, with DOMPDF.
My controller works, but open the view in browser as html page, not as pdf page, I want to download the pdf.

Code:
public function invoice_pdf()
    {

        $request = \Config\Services::request();

    $id = $request->getPost('id');

        $main_model = new MainModel;
        $this->data['invoice_list']= $main_model->list_invoice($id);

        $dompdf = new \Dompdf\Dompdf();
        $dompdf->loadHtml(view('list_invoice_pdf', $this->data));
        $dompdf->setPaper('A4', 'landscape');

        $dompdf->set_option('isHtml5ParserEnabled', true);
        $dompdf->render();
        $dompdf->stream();
    }

regards:
Code:
$dompdf->loadHtml(view('Module\Admin\Views\Reports\pay_pdf', $data));
        $dompdf->setPaper('A4', 'landscape');
        $dompdf->render();
        $dompdf->stream('PAID-'.date("Y-m-d") . '.pdf', array("Attachment" => true));
        exit();

Add Attachment true in stream, Hope this will works
Reply




Theme © iAndrew 2016 - Forum software by © MyBB