Is it possible to download a pdf file through pure html?

I use the link tag to open a pdf file. clicking this link opens the pdf file directly. Can I upload a pdf file to my system via html?

+3
source share
7 answers

The short answer is no : PDF processing is completely dependent on client-side software, from a web browser to a PDF reader. Your server may provide hints that may or may not be used by the browser, but you will not be able to execute it using regular HTML.

Regardless, you can configure your web server to send the appropriate HTTP headers. If you are using Apache , you can use the .htaccess file :

<FilesMatch "\.(?i:pdf)$">
  ForceType application/pdf
  Header set Content-Disposition attachment
</FilesMatch>

If you replace application / pdf with an application / octet stream , you can even bypass the PDF plugin if it is installed (not guaranteed).

Other web servers will require a different configuration.

+4
source

You should change the headers sent to the client by the server and add something like.

Content-Disposition: attachment; filename="downloaded.pdf"

This can be done using a php script proxy or by configuring your web server.

+3
source

html.

Content-Disposition: attachment;filename=x.pdf.

+2

Chrome Firefox, !

<a href="./directory/yourfile.pdf" download="newfilename">Download the pdf</a>

newfilename - , . , , :

<a href="./directory/yourfile.pdf" download>Download the pdf</a>

+1

, HTML... , -, apache

0

, Alvaro tip .

<FilesMatch "\.(?i:pdf)$">
  ForceType application/pdf
  Header set Content-Disposition attachment
</FilesMatch>

- , .htaccess, 500. - , ?

UPDATE: - Apache:

# a2enmod headers
0

I know this is an old question, but it is worth mentioning that many modern browsers now support an attribute downloadfor links, which can be used as follows:

<a href="/path/to/mydownload.pdf" download> 
0
source

Source: https://habr.com/ru/post/1724086/


All Articles