# PDF/File Download Page(Template)

**URL:** <https://forum.getkirby.com/t/pdf-file-download-page-template/25011>\
**Category:** Questions\
**Created:** [March 17, 2022, 10:57am UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011 "2022-03-17T10:57:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoBoBo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/robobo/32/8033_2.png) [@RoBoBo](https://forum.getkirby.com/u/RoBoBo)\
**Post date:** [March 17, 2022, 10:57am UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/1 "2022-03-17T10:57:31Z")

</div>

Hi,  
I would like to create a page that automatically downloads a pdf-file as soon as I select this page via a link.

More precisely:  
I would like to have a link to a page with a template in the footer-menu, which only offers a PDF for download instead of page content (preferably without actually calling up the this page).

Is this the correct or even best way to do this?

e.g.:

```auto
go($page->file('myfile.pdf')->url())

```

I would be very happy about your help/answers.

Best regards,  
Robert

---

<div class="post-metadata">

**Author:** ![isaactopo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/isaactopo/32/60_2.png) [@isaactopo](https://forum.getkirby.com/u/isaactopo)\
**Post date:** [March 17, 2022, 12:10pm UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/2 "2022-03-17T12:10:07Z")

</div>

I don’t know if I understand what you want to achieve. Do you want to download a PDF when you click on a link? If so, this will work:

```php
 <a href="<?= $page->file('myfile.pdf')->url() ?>" download>Download PDF</a>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 17, 2022, 12:32pm UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/3 "2022-03-17T12:32:36Z")

</div>

The alternative would be a route that returns `$file->download()`

> **[$file-\>download()](https://getkirby.com/docs/reference/objects/filesystem/file/download)**

---

<div class="post-metadata">

**Author:** ![RoBoBo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/robobo/32/8033_2.png) [@RoBoBo](https://forum.getkirby.com/u/RoBoBo)\
**Post date:** [March 17, 2022, 9:33pm UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/4 "2022-03-17T21:33:40Z")

</div>

Hallo and thank you for your answers.

@isaactopo:  
I know about the download attribute, but unfortunately that’s not what I would like to do.  
I would like to create a page (+ template + blueprint) where the editor in the backend sees only a field for the file-upload. If this page is called up by a visitor (click on the link in the [Footer] menu), the dialog box of the browser which offering the download should open instead of the page content.  
I also know the way with pure PHP

```auto
header('Content-Type: application/pdf');
....
...
readfile('xyz.pdf')

```

**I just thought that Kirby might already have a built-in-function/method that provides this, but as always, I’m missing what I’m looking for ☹**

@texnixe  
I would like to have it based on a temple and not with a route. A route refers more to a page, right?  
As already described above, the editor should simply select the template (e.g. with the name “Download File”) when he creates a page, insert the file and save it. If the page is listed, it is displayed in the menu and when a website visitor click it, no page appears, but the download is offered…

**Has anyone already done this and if so, how?**

Thanks,  
Robert

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 17, 2022, 11:04pm UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/5 "2022-03-17T23:04:28Z")

</div>

The you can just put the `$file->download()` code in the template.

---

<div class="post-metadata">

**Author:** ![RoBoBo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/robobo/32/8033_2.png) [@RoBoBo](https://forum.getkirby.com/u/RoBoBo)\
**Post date:** [March 18, 2022, 10:03am UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/6 "2022-03-18T10:03:37Z")

</div>

Thanks for your answer!

Then I’ll probably do it exactly as you instructed. I’m not quite sure yet whether forwarding with go() isn’t the more user-friendly way, since the PDF may then be displayed directl if the browser supports it.

Best regards,  
Robert

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [March 18, 2022, 1:22pm UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/7 "2022-03-18T13:22:09Z")

</div>

You could also create a [model](https://getkirby.com/docs/guide/templates/page-models) for the download template, and overwrite the `url` function to point to the file instead. This way you don’t even need a template.

**site/models/download.php**

```php
<?php

use Kirby\Cms\Page;

class DownloadPage extends Page {
    public function url($options = null): string {
        if($file = $this->file('myfile')) {
            return $file->url();
        }

        return parent::url($options);
    }
}

```

haven’t tried it, but should work 🙂

---

<div class="post-metadata">

**Author:** ![RoBoBo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/robobo/32/8033_2.png) [@RoBoBo](https://forum.getkirby.com/u/RoBoBo)\
**Post date:** [March 18, 2022, 3:19pm UTC](https://forum.getkirby.com/t/pdf-file-download-page-template/25011/8 "2022-03-18T15:19:51Z")

</div>

That sounds really great at all. I will try it out. Thanks for the hint. 😀
