# Forcer le téléchargement pdf

**URL:** https://meta.discourse.org/t/force-pdf-download/281819
**Category:** Support
**Created:** [Octobre 11, 2023, 12:49 UTC](https://meta.discourse.org/t/force-pdf-download/281819 "2023-10-11T00:49:12Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Rafael\_Melo\_Silva](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rafael_melo_silva/32/298585_2.png) [@Rafael\_Melo\_Silva](https://meta.discourse.org/u/Rafael_Melo_Silva)
#### Post date: [Octobre 11, 2023, 12:49 UTC](https://meta.discourse.org/t/force-pdf-download/281819/1 "2023-10-11T00:49:12Z")

</div>

J’utilise s3 pour héberger mes fichiers sur ma communauté discourse, j’ai créé une application iOS et j’ai besoin de télécharger des fichiers PDF au lieu de les ouvrir dans l’application

J’ai trouvé une solution pour un téléchargement de lien :

`<a href="download-url?wtn-download-file=true"> Télécharger le fichier </a>`

Mais pour les PDF téléchargés sur s3, je ne sais pas quoi faire.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [Octobre 12, 2023, 8:49 UTC](https://meta.discourse.org/t/force-pdf-download/281819/2 "2023-10-12T08:49:15Z")

</div>

Modification : suppression de ma réponse car j’avais mal compris le sujet 🤦

Merci thoka 👍

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [Octobre 12, 2023, 10:10 UTC](https://meta.discourse.org/t/force-pdf-download/281819/3 "2023-10-12T10:10:31Z")

</div>

Hm. Il semble qu’il exige exactement le contraire de ma demande de fonctionnalité…

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [Octobre 12, 2023, 10:14 UTC](https://meta.discourse.org/t/force-pdf-download/281819/4 "2023-10-12T10:14:27Z")

</div>

Selon [cette source](https://gomakethings.com/how-to-force-a-file-to-download-instead-of-open-in-the-browser-using-only-html/), vous devriez pouvoir obtenir le comportement souhaité en ajoutant `download` à ces liens via un composant de thème.

---

<div class="post-metadata">

### Author: ![Rafael\_Melo\_Silva](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rafael_melo_silva/32/298585_2.png) [@Rafael\_Melo\_Silva](https://meta.discourse.org/u/Rafael_Melo_Silva)
#### Post date: [Octobre 12, 2023, 5:51 UTC](https://meta.discourse.org/t/force-pdf-download/281819/5 "2023-10-12T17:51:28Z")

</div>

Je dois trouver un moyen de changer tous mes liens pdf… il y a près de 3000 liens.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [Octobre 12, 2023, 6:14 UTC](https://meta.discourse.org/t/force-pdf-download/281819/6 "2023-10-12T18:14:33Z")

</div>

Devrait être une question de remappage de discours

> [@Change the domain name or rename your Discourse](https://meta.discourse.org/t/change-the-domain-name-or-rename-your-discourse/16098#replace-all-instances-of-the-old-name-with-the-new-name-in-posts-6):
>
> bookmark This guide explains how-to change the domain name of your Discourse site, and includes information about setting up DNS changes, editing configuration files, updating site settings, and correcting social logins and post content to reflect your new domain name. warning This guide is for self-hosted Discourse instances that were installed using our [installation guide on GitHub](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md). If you are [hosted by Discourse](https://www.discourse.org/pricing), please see [Configure your domain name for hosted Discourse](https://meta.discourse.org/t/configure-your-domain-name-for-hosted-discourse/21827) for specific …

Mot de prudence : Testez-le d’abord sur un site de staging. Il se peut que cela ne fonctionne pas comme prévu.

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [Octobre 12, 2023, 6:57 UTC](https://meta.discourse.org/t/force-pdf-download/281819/7 "2023-10-12T18:57:39Z")

</div>

Bonjour 👋

Je pense que ce sujet est le même : [Force download pdf on IOS](https://meta.discourse.org/t/force-download-pdf-on-ios/282047?u=don)

Pour cela, vous devez utiliser [api.decorateCookedElement](https://github.com/discourse/discourse/blob/460e702887e266f1d24122c199c9d6eeaf1b8883/app/assets/javascripts/discourse/app/lib/plugin-api.js#L359-L388).

Quelque chose comme ceci devrait fonctionner 🔽

Placez-le dans la section Header d’un composant.

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

      if (!pdfFiles.length) {
        return;
      }

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

```

Je l’ai testé sur mon appareil et cela fonctionne pour moi, mais si vous souhaitez utiliser d’autres attributs, etc., vous pouvez facilement les modifier… J’espère que cela vous aidera 🙂
