Android app webview is not downloading or loading pdf, php mpdf - php

I have developed a page which display invoice in html and has a download link for PDF. I am using mpdf library- php. Here is my code for download link:
public function downloadInvoice()
{
$id = $this->uri->segment(2);
$where = array('invoice_id'=>$id);
$data['invoice'] = $this->Common_model->getDataWhere("invoices","*",$where);
$mpdf = new \Mpdf\Mpdf();
$this->session->set_userdata($data);
$filename = $invoice['invoice_no'].'.pdf';
header("Content-Disposition", "attachment; filename='.$filename.'");
$html=$this->load->view('user/pdf/download_invoice',[],true);
$mpdf->WriteHTML($html);
$mpdf->Output($filename, 'D');
}
I am able to download the pdf in each and every browser, event in mobile browser. The android app developer using this link in app and showing it in webview. Now he is saying that download link does nothing. I also asked him to try the download link directly . this is also not working. What change should I apply to make it work in mobile. Mobile developer is saying that he has no control on webview and cannot do anything from his side.
Please help.

Related

PHP PDF download is not working properly in mobile

I am creating a web application in Codeigniter 4 in which users can purchase a PDF book. After payment, the user is redirected to a page where he/she can download PDF directly. The page doesn't have any UI. The PDF download is implemented using headers. The PDF download function is working perfectly on PC, but on mobile, the file is downloading as an HTML file.
eg : filename.pdf.html.
My function is as below
public function download()
{
$file_url = WRITEPATH . 'uploads/file.pdf';
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=filename.pdf");
readfile($file_url);
}
I have searched and tried almost all the solutions. But still, the issue is not resolved in mobile.
Solved the issue.
Looks like Codeigniter needed exit() function after readfile()
Thanks to #vee who gave the tip.

Tablet stream (snappy)

Laravel 6.0+
https://github.com/barryvdh/laravel-snappy
here is my problem. I would like that on tablet I can print the pdf directly or then be able to stream the pdf as on the pc.
because currently on tablet I have to download the pdf, open the pdf, and print the pdf.
I would like to simplify all that.
public function pdf()
{
$order = Order::first()
$pdf = PDF::loadView('admin/pdf.order', compact('order'));
return $pdf->stream('Pdf_'. $order->num_order .'_'. $order->customer->name);
}
Thank you for your help.
I have found a solution to my problem I am going through an html basic view with a button in javascript which asks to print and which directly starts printing!

How to implement download video in laravel 5

i've developed laravel MVC web app that has a downloaded video in a Download page so When ever i click on download button it should get me the video downloaded, but instead it opens in a new tab in my browser
here is my code:
Controller download function:
public function download($file_name) {
$file_path = public_path('download/'.$file_name);
return response()->download($file_path);
}
Download button :
Download

Moodle download a created PDF

I create a PDF in Moodle using the following code
$pdf = new pdf;
$pdf->AddPage();
$pdf->Write(1, "Test");
$pdf->Output();
How would I make this download in the browser instead of opening in browser?
// Force the browser to download the output
$pdf->Output('filename.pdf','D');
Moodle wraps the TCPDF library for PDF generation (the wrapper mostly just handles the locations for temporary files and accessing embedded images which are in the Moodle Files API).
You can find documentation about the TCPDF Output() function online at http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1
The important param is the second one, calling $pdf->Output('filename.pdf', 'D') will cause it to download.

Export a html page to pdf with everything that's written on it, after submit button

I need to export html page to pdf file with everything that's written in it, after I press submit button. It will open new page, with info, and I need for script to automatically make .pdf file (already uploaded to webserver), and get the link from file. Could you give me some easy example (if available, without any plugins, or other features that I must download, I would prefer clean PHP).
Just try this
HTML to PDF with PHP
Using open-source HTML2FPDF project
This solution uses HTML2PDF project (sourceforge.net/projects/html2fpdf/). It simply gets a HTML text and generates a PDF file. This project is based upon FPDF script (www.fpdf.org), which is pure PHP, not using the PDFlib or other third party library. Download [HTML2PDF][1], add it to your projects and you can start coding.
Code example
require("html2fpdf.php");
$htmlFile = "your link";
$buffer = file_get_contents($htmlFile);
$pdf = new HTML2FPDF('P', 'mm', 'Letter');
$pdf->AddPage();
$pdf->WriteHTML($buffer);
$pdf->Output('test.pdf', 'F');

Categories