# How to unpublish/publish files with Hook?

**URL:** <https://forum.getkirby.com/t/how-to-unpublish-publish-files-with-hook/25949>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 8, 2022, 7:44am UTC](https://forum.getkirby.com/t/how-to-unpublish-publish-files-with-hook/25949 "2022-07-08T07:44:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wamb](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@Wamb](https://forum.getkirby.com/u/Wamb)\
**Post date:** [July 8, 2022, 7:44am UTC](https://forum.getkirby.com/t/how-to-unpublish-publish-files-with-hook/25949/1 "2022-07-08T07:44:30Z")

</div>

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:

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

```

Here’s what I tried:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Wamb](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@Wamb](https://forum.getkirby.com/u/Wamb)\
**Post date:** [July 8, 2022, 10:26am UTC](https://forum.getkirby.com/t/how-to-unpublish-publish-files-with-hook/25949/2 "2022-07-08T10:26:13Z")

</div>

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

```
