You can trigger a download with the HTML5 download attribute.
<a href="path_to_file" download="proposed_file_name">Download</a>
Where:
path_to_fileis a path that resolves to an URL on the same origin. That means the page and the file must share the same domain, subdomain, protocol (HTTP vs. HTTPS), and port (if specified). Exceptions areblob:anddata:(which always work), andfile:(which never works).proposed_file_nameis the filename to save to. If it is blank, the browser defaults to the file's name.
Documentation: MDN, HTML Standard on downloading, HTML Standard on download, CanIUse
You can trigger a download with the HTML5 download attribute.
<a href="path_to_file" download="proposed_file_name">Download</a>
Where:
path_to_fileis a path that resolves to an URL on the same origin. That means the page and the file must share the same domain, subdomain, protocol (HTTP vs. HTTPS), and port (if specified). Exceptions areblob:anddata:(which always work), andfile:(which never works).proposed_file_nameis the filename to save to. If it is blank, the browser defaults to the file's name.
Documentation: MDN, HTML Standard on downloading, HTML Standard on download, CanIUse
For the button you can do
<form method="get" action="file.doc">
<button type="submit">Download!</button>
</form>
Videos
Copy<div onClick="window.location=location/to/file/pdf.php">something</div>
pdf.php:
Copy<?php
header('Content-disposition: attachment; filename=your_file.pdf');
header('Content-type: application/pdf');
readfile('path/to/your_file.pdf');
Try:
Copy<div onClick="window.location='path'; return false;">something</div>
You should set correct headers on server side which will determine view or download a file
I'm looking to provide a download as PDF button on my htmx based web page.
Just to provide the X to my Y question.
I think I want to grab the entire HTML document, send it to the server, process it into a PDF, put the PDF into download location, then return new html for the button that gives a link to the stored document.
I'm hoping I can do all that in ~3 seconds.
Is this idea wrong? Is there a better way?
How can I get the entire HTML page to send to the server?
Just looking to have a PDF open from a local location on a click.
<input type="button" value="Show Current PDF!" onclick="window.open('file:///C:/NewPDF.pdf');" size="20" class="newButton"/>