Active1 month ago
I am giving link of a pdf file on my web page for download, like below
The problem is when user clicks on this link then
- If the user have installed Adobe Acrobat, then it opens the file in the same browser window in Adobe Reader.
- If the Adobe Acrobat is not installed then it pop-up to the user for Downloading the file.
But I want it always pop-up to the user for download, irrespective of 'Adobe acrobat' is installed or not.
Convert HTML into PDF files with Adobe Acrobat DC. Learn how to easily convert a web page to PDF and keep the same formatting as the web page. Start with free trial. Download a HTML content as pdf using javascript – jsPDF November 4, 2015 September 12, 2017 Jacob Frazier Using jsPDF library, you can download the div containing graphs, tables, contents as a PDF. How To Save HTML File In Edge Browser In Windows 10. Follow the below-given step by step guides to save HTML or PDF file in Microsoft Edge Browser via Windows Application. First of you’ll have to download the “Save HTML in Edge” application from Microsoft Store from your Windows 10. For downloading the application. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. HTML5 as being developed as the next major revision of HTML is opening new doors to web professionals. With its unparalleled functionality, it actually boasts exciting new features and capabilities. Now to facilitate more advanced web development, we introduce HTML5 books PDF download. LEARN TO CODE HTML & CSS: DEVELOP & STYLE WEBSITES Shay Howe NEW RIDERS www.newriders.com To report errors, please send a note to [email protected].
Please tell me how i can do this?
Rob W284k5555 gold badges670670 silver badges596596 bronze badges
PrashantPrashant12.4k6060 gold badges151151 silver badges215215 bronze badges
14 Answers
Instead of linking to the .PDF file, instead do something like
which outputs a custom header, opens the PDF (binary safe) and prints the data to the user's browser, then they can choose to save the PDF despite their browser settings. The pdf_server.php should look like this:
PS: and obviously run some sanity checks on the 'file' variable to prevent people from stealing your files such as don't accept file extensions, deny slashes, add .pdf to the value
TravisOTravisO8,65733 gold badges3131 silver badges4242 bronze badges
This is a common issue but few people know there's a simple HTML 5 solution:
Where
newfilename
is the suggested filename for the user to save the file. Or it will default to the filename on the serverside if you leave it empty, like this:Compatibility: I tested this on Firefox 21 and Iron, both worked fine. It might not work on HTML5-incompatible or outdated browsers. The only browser I tested that didn't force download is IE...
Free Html To Pdf Converter
Check compatibility here: http://caniuse.com/#feat=download
T_DT_D2,39622 gold badges1313 silver badges2121 bronze badges
Don't loop through every file line.Use readfile instead, its faster. This is off the php site:http://php.net/manual/en/function.readfile.php
Make sure to sanitize your get variable as someone could download some php files...
Alex VAlex V16.4k44 gold badges2929 silver badges3232 bronze badges
Instead of using a PHP script, to read and flush the file, it's more neat to rewrite the header using
Rob WRob W.htaccess
. This will keep a 'nice' URL (myfile.pdf
instead of download.php?myfile
).284k5555 gold badges670670 silver badges596596 bronze badges
I found a way to do it with plain old HTML and JavaScript/jQuery that degrades gracefully. Tested in IE7-10, Safari, Chrome, and FF:
HTML for download link:
jQuery (pure JavaScript code would be more verbose) that simulates clicking on link after a small delay:
To make this more robust you could add HTML5 feature detection and if it's not there then use
Alex WAlex Wwindow.open()
to open a new window with the file.29.1k77 gold badges7575 silver badges8787 bronze badges
This is the key:
Content-type application/x-pdf-document or application/pdf is sent while sending PDF file. Adobe Reader usually sets the handler for this MIME type so browser will pass the document to Adobe Reader when any of PDF MIME types is received.
Sudden DefSudden Def3,68833 gold badges1414 silver badges88 bronze badges
There is an easier way in HTML5: Add a
Download
attribute. It is supported by most of the modern browsers.
Nisse Engström4,24999 gold badges2222 silver badges3737 bronze badges
tawsif torabitawsif torabi
I know I am very late to answer this but I found a hack to do this in javascript.
Shivek ParmarDownload Html As Pdf Using Jquery
Shivek Parmar1,90011 gold badge2525 silver badges3838 bronze badges
Try this:
<a href='pdf_server_with_path.php?file=pdffilename&path=http://myurl.com/mypath/'>Download my eBook</a>
The code inside pdf_server_with_path.php is:
Peter O.22.4k99 gold badges6060 silver badges7272 bronze badges
SaillSaill
Here's a different approach. I prefer rather than to rely on browser support, or address this at the application layer, to use web server logic.
If you are using Apache, and can put an .htaccess file in the relevant directory you could use the code below. Of course, you could put this in httpd.conf as well, if you have access to that.
The FilesMatch directive is just a regex so it could be set as granularly as you want, or you could add in other extensions.
The Header line does the same thing as the first line in the PHP scripts above. If you need to set the Content-Type lines as well, you could do so in the same manner, but I haven't found that necessary.
Evan DonovanEvan Donovan
I solved mine using the whole url of the PDF file (Instead of just putting the file name or location to href): a href='domain . com/pdf/filename.pdf'
Mark AllenaMark Allena
if you need to limit download rate, use this code !!
For more information click here
Mehran HooshangiMehran Hooshangi
user11021789user11021789
In a Ruby on Rails application (especially with something like the Prawn gem and the Prawnto Rails plugin), you can accomplish this a little more simply than a full on script (like the previous PHP example).
In your controller:
The render :layout => false part tells the browser to open up the 'Would you like to download this file?' prompt instead of attempting to render the PDF. Then you would be able to link to the file normally: http://mysite.com/myawesomepdf.pdf
btwbtw3,61099 gold badges3636 silver badges3939 bronze badges
protected by Zoe the transgirlAug 16 at 12:49
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?