# Downloading a PDF via static link

**URL:** <https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251>\
**Category:** Dash Python\
**Created:** [June 18, 2020, 4:28pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251 "2020-06-18T16:28:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![howardmf](https://avatars.discourse-cdn.com/v4/letter/h/8baadc/32.png) [@howardmf](https://community.plotly.com/u/howardmf)\
**Post date:** [June 18, 2020, 4:28pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251/1 "2020-06-18T16:28:22Z")

</div>

Hello!

I am looking to have a download file link. Is there a specific component for this? How have others accomplished this? I’ve done it before with and EXCEL file but I’m having a hard time with PDF format.

Thanks,

Morgan

---

<div class="post-metadata">

**Author:** ![Emil](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emil/32/31734_2.png) [@Emil](https://community.plotly.com/u/Emil)\
**Post date:** [June 18, 2020, 5:27pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251/2 "2020-06-18T17:27:51Z")

</div>

Maybe you could use my `Download` component? I haven’t tried with PDF, but I guess it should work.

> <https://stackoverflow.com/questions/62082946/dash-download-in-memory-generated-file-on-button-click-how-to-give-filename/62088521#62088521>

EDIT: If you **only** need static files, you could also just serve them directly via the flask server.

---

<div class="post-metadata">

**Author:** ![howardmf](https://avatars.discourse-cdn.com/v4/letter/h/8baadc/32.png) [@howardmf](https://community.plotly.com/u/howardmf)\
**Post date:** [June 18, 2020, 5:28pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251/3 "2020-06-18T17:28:18Z")

</div>

Thanks! I’ll have a look

---

<div class="post-metadata">

**Author:** ![howardmf](https://avatars.discourse-cdn.com/v4/letter/h/8baadc/32.png) [@howardmf](https://community.plotly.com/u/howardmf)\
**Post date:** [June 18, 2020, 5:37pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251/4 "2020-06-18T17:37:45Z")

</div>

It doesn’t appear that pandas has a pdf writer.

---

<div class="post-metadata">

**Author:** ![Emil](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emil/32/31734_2.png) [@Emil](https://community.plotly.com/u/Emil)\
**Post date:** [June 18, 2020, 5:48pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251/5 "2020-06-18T17:48:59Z")

</div>

Ah, you don’t need that. The pandas step was only necessary in the other example to transform the python data structure into the desired output format. You should be able to write the bytes directly. Here is an example,

```auto
import os
import dash
import dash_html_components as html

from dash.dependencies import Output, Input
from dash_extensions import Download

# Create app.
app = dash.Dash(prevent_initial_callbacks=True)
app.layout = html.Div([html.Button("Download pdf", id="btn"), Download(id="download")])

@app.callback(Output("download", "data"), [Input("btn", "n_clicks")])
def generate_csv(n_nlicks):
    # Path to a pdf file on the server.
    pdf_dir = "C:/Users/emilh/Dropbox"
    pdf_file = "Get Started with Dropbox.pdf"
    # Convert data to a string.
    with open(os.path.join(pdf_dir, pdf_file), 'rb') as f:
        content = list(f.read())
    # The output must follow this form for the download to work.
    return dict(filename=pdf_file, content=content, type="text/pdf")

if __name__ == ' __main__':
    app.run_server()

```

---

<div class="post-metadata">

**Author:** ![howardmf](https://avatars.discourse-cdn.com/v4/letter/h/8baadc/32.png) [@howardmf](https://community.plotly.com/u/howardmf)\
**Post date:** [June 18, 2020, 5:56pm UTC](https://community.plotly.com/t/downloading-a-pdf-via-static-link/41251/6 "2020-06-18T17:56:07Z")

</div>

Ahh I was over complicating it. Thanks for the explanation!
