barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.66k stars 966 forks source link

Is it possible pass data to loadHTML method ? #941

Open Khaledsb opened 1 year ago

Khaledsb commented 1 year ago

Hello, I would like to ask everyone. I want to pass data from my code to html content with loadHTML method without use loadView .

example : show list of (Model result inside pdf).

Thank You

parallels999 commented 1 year ago

No

Khaledsb commented 1 year ago

@parallels999 can you give me un example please , i tried this but isn't working
$pdf->loadHTML($template->content, ['test' => 'test']);

parallels999 commented 1 year ago

https://github.com/barryvdh/laravel-dompdf/blob/7516caab940796d31267da9b30b548a56bef50cb/src/PDF.php#L81-L92

Khaledsb commented 1 year ago

the second paramter is for encoding not for data @parallels999 can you give me a real example ?

jameswagoner commented 1 year ago

While you cannot pass data directly to loadHTML(), you can build html from a blade view manually and then pass that in


// create a view, pass data, and get the html content
$html = response()->view($view, ['test' => 'test'])->getContent();

// pass html to pdf
PDF::loadHTML($html);
Khaledsb commented 1 year ago

@jameswagoner yes , that what i did as solution, thank you :)

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf. If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.