How to unpublish/publish files with Hook?

i wrote myself a page:create:after hook which creates a PDF with DomPDF. Everything works fine. But the file does not update in the frontend. How can I get the file from the media folder to update?

Here is the code snippet how to create the file:

F::write($newPage->root() . '/expose.pdf', $dompdf->output());

Here’s what I tried:

Media::unpublish($oldPage->root(), $oldPage->file('expose.pdf'), false);
// or
$kirby->file($oldPage->root() . '/expose.pdf')->unpublish();

// Code for DOMPDF creating PDF and save into Page Folder

Media::publish($kirby->file($newPage->root() . '/expose.pdf'), $newPage->mediaRoot());
// or
$kirby->file($newPage->root() . '/expose.pdf')->publish();

I am grateful for any help.

$oldPage->file('expose.pdf')->unpublish();
// Code for DOMPDF
F::write($newPage->root() . '/expose.pdf', $dompdf->output());
$newPage->file('expose.pdf')->publish();