barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.62k stars 965 forks source link

Network Error when downloading from browser #982

Closed Mcad30 closed 1 year ago

Mcad30 commented 1 year ago

This is just a Dompdf wrapper! I understand that this package is just a Laravel wrapper for https://github.com/dompdf/dompdf Any issues with PDF rendering, CSS that is not applied correctly, aligning/fonts/characters etc that are not directly related to this package, should be reported there. When having doubts, please try to reproduce the issue with just dompdf. If it's also present there, do not open an issue here please.

Describe the bug First of all, thank you for making this package for Laravel.

I've successfully converted an html view file into a PDF format. However, when I try clicking my view button which redirects me to a browser-view of the html , and click download, the file explorer shows up asking me where I want to save the file. I noticed that the file type was "All Files (*)" and not pdf. I tried saving it but it gives me a 'Failed - Network Error'. I'm guessing it's because of the file type not being detected as pdf? Like I should set the content type of the file? idk.

I'm not sure if it's meant to be like that or I'm doing something wrong.

To Reproduce Steps to reproduce the behavior:

Here's my code:

Expected behavior I was expecting to have the pdf file type in the choices.

Screenshots The first image is the browser's view of the converted HTML to PDF file where I click the download button. The second image is the file explorer where I select the path where I want to save the file. The third image is where I clicked save and received a 'Failed - Network error' 1 2 3

Additional context Add any other context about the problem here.

parallels999 commented 1 year ago
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Facades\Response;

///

$name = 'file_name.pdf'
return Response::make(
    Pdf::loadView('print.test_result', $data)->setPaper('Short', 'portrait')->output(),
    200,
    [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; filename="'.$name.'"'
    ]
);
Mcad30 commented 1 year ago
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Facades\Response;

///

$name = 'file_name.pdf'
return Response::make(
    Pdf::loadView('print.test_result', $data)->setPaper('Short', 'portrait')->output(),
    200,
    [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; filename="'.$name.'"'
    ]
);

Thank you for taking the time to help.

I seem to be getting the same problem after I pasted your suggestion.

I'm able to see the PDF converted but can't seem to download it still. It still says Failed - Network Error and the file type still says "All files (.)"

Mcad30 commented 1 year ago

Oh actually I found a workaround. Not code related though. I'll just show it how in case someone might find it useful.

So instead of saving it right away, I clicked the print icon and clicked save as PDF.

I was able to save it as a pdf file without having the Network Error.

Thank you @parallels999 for your help :)

1 2