# WebDev return PDF with file name

**URL:** <https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [March 30, 2021, 2:27pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055 "2021-03-30T14:27:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 30, 2021, 2:27pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055/1 "2021-03-30T14:27:26Z")

</div>

I’m using the WebDev module in 8.1 to get a PDF from a database and send it to both a Perspective client, and possibly just a regular browser.

When sending the data back from the WebDev module I’m doing the following:

```auto
return {'contentType':'application/pdf','bytes':reportPDF}

```

Which works splendidly for returning the PDF. However when I access this doGet from a web browser it end up being returned as the name of the resource, in this case GetTicket, rather than something I can specify.

Is there something I can return in the dict that will provide the client web browser with a suggested name for this .pdf file?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 30, 2021, 4:36pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055/2 "2021-03-30T16:36:33Z")

</div>

The “modern” way is to specify a `download` attribute (which `system.perspective.download` does automatically when you specify a filename): [https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download)

However, at the server level you could try adding a well-formed `Content-Disposition` header:  
[https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 30, 2021, 4:45pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055/3 "2021-03-30T16:45:31Z")

</div>

So from the webdev side how do I add the Content-Disposition header? I tried this:

```auto
return {'contentType':'application/pdf','contentDisposition': 'attachment; filename="{}"'.format(ticketNum),'bytes':reportPDF}

```

And no dice. ticketNum is the identifier of each PDF in the database.

This would be just coming from the WebDev side as we may be distributing links in e-mails etc…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 30, 2021, 4:57pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055/4 "2021-03-30T16:57:20Z")

</div>

Try this:

```auto
request["servletResponse"].addHeader('contentDisposition', 'attachment; filename="{}"'.format(ticketNum))
return {'contentType':'application/pdf','bytes':reportPDF}

```

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 30, 2021, 5:12pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055/5 "2021-03-30T17:12:03Z")

</div>

> [@paul-griffith](#):
>
> request["servletResponse"].addHeader('contentDisposition', 'attachment; filename="{}"'.format(ticketNum))

You got me down the right path.

```auto
request["servletResponse"].addHeader('Content-Disposition', 'attachment; filename="{}.pdf"'.format(ticketNum))

```

Time to read up on the HttpServletResponse object in case this customer wants anything else. Sigh.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![c-w-t](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@c-w-t](https://forum.inductiveautomation.com/u/c-w-t)\
**Post date:** [September 21, 2021, 6:49pm UTC](https://forum.inductiveautomation.com/t/webdev-return-pdf-with-file-name/45055/6 "2021-09-21T18:49:04Z")

</div>

> [@bschroeder](#):
>
> `request["servletResponse"].addHeader('Content-Disposition', 'attachment; filename="{}.pdf"'.format(ticketNum))`

Awesome stuff, saved me some time friends!!
