Wamb
June 27, 2022, 10:52am
#1
Is it possible to save files in the content folder of the current page using the page.create:after and page.update:after hooks?
I have tried the following:
$dompdf->stream('expose.pdf');
Data::write('expose.pdf', $dompdf->output());
F::write($this->root().'expose.pdf', $dompdf->output());
file_put_contents($page->diruri().'/expose.pdf', $dompdf->output());
In a page.create:after hook, you have access to $page, so your syntax using $this
doesn’t make sense, as it refers to the hook, and there is also a slash missing, so try:
F::write($page->root() . '/expose.pdf', $dompdf->output());
Note that in the page.update:after
hook the page variable will be $newPage
.
Wamb
June 27, 2022, 11:43am
#3
Thank you that works now so far, but I get a message when I save the change in the panel.
The message shows me the rendered PDF with the caption: The JSON response could not be parsed.
Then the PDF can be found but is empty.
i am using this:
$dompdf->loadHTML(snippet('pdf/expose',['page' => $newPage]));
Well, I’m not familiar with DomPdf, but according to this SO response, there’s a step missing: php - how to save DOMPDF generated content to file? - Stack Overflow
Wamb
June 27, 2022, 11:55am
#5
i’m probably on the wrong track with the snippet. and will try another way to load the content of a template.
Or how to load a snippet without it being rendered?
You have to pass true
to return instead of echo:
$html = snippet('pdf/expose', ['page' => $newPage], true);
Wamb
June 27, 2022, 12:08pm
#7
texnixe:
, true
This is the solution, thank you