CodeIgniter Forums
Open the view in browser as html page, not as pdf using DOMPDF - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Open the view in browser as html page, not as pdf using DOMPDF (/showthread.php?tid=87288)



Open the view in browser as html page, not as pdf using DOMPDF - nadeem14375 - 04-04-2023

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:


RE: Open the view in browser as html page, not as pdf using DOMPDF - JustJohnQ - 04-04-2023

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.


RE: Open the view in browser as html page, not as pdf using DOMPDF - nadeem14375 - 04-04-2023

(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.


RE: Open the view in browser as html page, not as pdf using DOMPDF - JustJohnQ - 04-04-2023

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?


RE: Open the view in browser as html page, not as pdf using DOMPDF - rmcdahal - 04-04-2023

(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