Force pdf download

I am using s3 for host my files on my discourse community, i made ios app and i need to download pdf files instead of open in the app

I found a solution for a link download:

<a href="download-url?wtn-download-file=true"> download File</a>

But for pdf uploaded on s3 i don`t know what to do.

Edit: removing my answer as I misunderstood the topic :person_facepalming:

Thanks thoka :+1:

Hm. It seems, he demands exactly the opposite of my feature request …

1 Like

According to this source, you should be able to achieve the desired behavior by adding download to these links via a theme component.

1 Like

I need to find a way to change all my pdf links… it`s almost 3000 links

Should be a matter of discourse remap

Word of caution: Test it first on a staging site. It might not work as expected.

1 Like

Hello :wave:

I think this topic is same: Force download pdf on IOS

For this you have to use api.decorateCookedElement.

Something like this should work :arrow_down_small:

Place it to the Header section to a component.

<script type="text/discourse-plugin" version="0.8.42">
    element => {
      const pdfFiles = element.querySelectorAll("a.attachment[href$='.pdf']");

      if (!pdfFiles.length) {

      pdfFiles.forEach((pdf) => {
        pdf.setAttribute("download", "");
    { id: "download-pdf", onlyStream: true }

I’ve tested it on my device and it works for me but if you want to use other attribute etc… you can easily change it… I hope it helps :slight_smile: