I am using Laravel 5.4 and using
"barryvdh/laravel-dompdf": "^0.8.0",
https://github.com/barryvdh/laravel-dompdf
i have follwoing code in controller
$pdf = PDF::loadView('print.print', $data);
return $pdf->download('invoice.pdf');
As it will download pdf properly but i am looking to preview the content in the view to print.
i have googled lot still not able to get it
You can use stream() function as stated in documentation here.
According to documentation of dompdf,
When you use stream like this:
$dompdf->stream('filename.pdf');
In default, you will see a download dialouge box.
But, you can add parameter Attachment value to false so that you can view pdf in browser.
Here is what you need to do:
$dompdf->stream("filename.pdf", array("Attachment" => false));
This might help you.
I've struggled with this and manage to make it work with the following snippet:
$html = view('desktop.bill', $data)->render();
return #\PDF::loadHTML($html, 'utf-8')->stream(); // to debug + add the follosing headers in controller ( TOP LEVEL )
Besides the upper command, you will need to add on a TOP LEVEL, like first lines in the controller, the following hearders:
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
header('Content-Transfer-Encoding: binary');
Related
please I need help I'm trying to create a SEPA XML file so I downloaded the sepa-xml with coenter image description heremposer in my project then I make the same code in the documentation to test if work or not so when I enter image description hereadded the code and generate the file I get an empty file. but when I dump the variable I get a result .
I get this page
I referred here. Looks like you need to download the generated xml code.
[Git link][1].
Code will be like this.
header('Content-disposition: attachment; filename="newfile.xml"');
header('Content-type: "text/xml"; charset="utf8"');
echo $directDebit->asXML();
exit;
In this case the generated code will be saved as newfile.xml and download the file automatically. Hope it solves your problem
[1]: https://github.com/php-sepa-xml/php-sepa-xml/blob/master/doc/direct_debit.md
I am using Quickbooks PHP SDK to generate a PDF from an Invoice but I would like to upload the PDF to the server. Currently I can request the Invoice and download the PDF but how do I tell Laravel to take the PDF and upload it without it being downloaded?
$invoice = $dataService->FindById("Invoice", "130147");
$pdfContent = $dataService->DownloadPDF($invoice, null, true);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="invoice.pdf"');
echo $pdfContent;
exit();
Instead of it downloading I would like to do something like:
$path = $pdfContent->storeAs('public/pdf', invoice.pdf);
Is this possible?
I did find a solution outside of my question above.
The Quickbooks API allows the ability to pass a file location in the second variable. Also the 3rd variable can be set to true to generate a raw PDF.
$invoice = $dataService->FindById("Estimate", "130147");
$data = $dataService->DownloadPDF($invoice, base_path('/pdf/'), false);
While this is a great simple solution I wonder if there is an solution with how I was originally going about?
IM trying to save a PDF file, generated from HTML, into the user's local using MPDF. Here is the part of the code responsable for this:
$mpdf = new \Mpdf\Mpdf();
$html = $this->load->view('gestao/relatorios/relatorio_cargo_cidades', $data, true);
$mpdf->WriteHTML($html);
$mpdf->SetFooter(relatorio_footer());
$mpdf->Output('relatorio_cargos_cidades_seletivo_' . $seletivo_id .'_'.date("Ymd_his").'.pdf', 'D');
At first I was trying to show the PDF using the "I" param from the output function, than the user could just see the PDF and choose to download it or not. But when I tried to submit a file into another website, it says that the file is not a PDF. Than I used my linux to see if the file was actually a PDF, here's what I got:
As you can see, the file is being saved as "data" for some reason. I've already tried to use the 'F' param, also from the output function, and than it worked, I saved as PDF. But the F param only save the file inside the code folder, so it was not very usefull for me.
Can anyone tell me how could I save the file as an actually PDF using MPDF?
EDIT
I think that the problem is being caused by CODEIGNITER, not by the MPDF. When I'm setting the last param from the load->view as TRUE, the returned HTML is in a data (string) form, and MPDF is not converting this properly.
Adding ob_clean() might solve your problem:
ob_clean();
$mpdf->Output('relatorio_cargos_cidades_seletivo_' . $seletivo_id .'_'.date("Ymd_his").'.pdf', 'D');
You can simply use the D parameter for downloading:
$mpdf -> Output ('FILENAME.pdf', 'D');
or generate your own header and then output the content as string:
header ("Content-type: application/pdf");
header ("Content-Disposition: inline; filename=FILENAME.pdf");
$mpdf -> Output ('', 'S');
Refer to Can an ASP.NET MVC controller return an Image?
, the answer suggest to return image file from controller in C#.
My question is:
Can I do the same thing or similar in PHP? What I want is to hide PDF path from URL.
Thanks
I think you are trying to hide the real local path of your pdf file using php. If this is the case, you can use something like this:
<?php
$localfilename = 'my_local_path/my_file.pdf';
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename='download.pdf'");
readfile($localfilename);
?>
I hope this helps you. Greetings!
I have a php script that generates a pdf report. When we go to save the pdf document, the filename that Acrobat suggests is report_pdf, since the php script is named report_pdf.php. I would like to dynamically name the pdf file, so I don't have to type the appropriate name for the report each time that I save it.
Asking on a news group, someone suggested this, where filename="July Report.pdf" is the intended name of the report
<?
header('Content-Type: application/pdf');
header('Content-disposition: filename="July Report.pdf"');
But it doesn't work. Am I doing it wrong, or will this work at all? Is this a job for mod_rewrite?
So I've tried both
header('Content-disposition: inline; filename="July Report.pdf"');
and
header('Content-disposition: attachment; filename="July Report.pdf"');
( not at the same time ) and neither work for me. Is this a problem with my web host? For this url, here's my code:
<?
header('Content-disposition: inline; filename="July Report.pdf"');
// requires the R&OS pdf class
require_once('class.ezpdf.php');
require_once('class.pdf.php');
// make a new pdf object
$pdf = new Cpdf();
// select the font
$pdf->selectFont('./fonts/Helvetica');
$pdf->addText(30,400,30,'Hello World');
$pdf->stream();
?>
Try:
header('Content-Disposition: attachment; filename="July Report.pdf"');
or
header('Content-Disposition: inline; filename="July Report.pdf"');
Another option would be to use the $_SERVER['PATH_INFO'] to pass your "July Report.pdf" - an example link might be:
<a href="report_pdf.php/July%20Report.pdf?month=07">
That file should default to saving as "July Report.pdf" - and should behave exactly like your old php script did, just change the code that produces the link to the pdf.
Should be:
header('Content-disposition: attachment;filename="July Report.pdf"');
Based on https://github.com/rospdf/pdf-php/raw/master/readme.pdf (Page 19)
The stream-method accepts an array as parameter:
stream([array options])
Used for output, this will set the required headers and output the pdf code.
The options array can be used to set a number of things about the output:
'Content-Disposition'=>'filename' sets the filename, ...
This code works well for me
$ezOutput = $pdf->ezStream(array("Content-Disposition"=>"YourFileName.pdf"));
In my case I use ezStream() but I think stream() should give the same result.
For the name shown on the title tab in the browser
I had the same problem, then i found that it's metadata missing inside my .pdf.
I used a tools ("debenu PDF tools") for edit pdf property like author, title, etc...
I just change title from empty field to what title I want, upload the new pdf and now, with same code, same script the browser show the right name!
For the name when u ask to save document
is what u specify in header filename=
Did you try to remove spaces from file name using hyphens? So, I think its name must be like this; filename=July-Report.pdf