Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  96] [ 1]  / answers: 1 / hits: 18012  / 12 Years ago, mon, march 12, 2012, 12:00:00

Consider a static HTML page as test.html, and a printable version of the page has been stored in test.pdf. How can I guide browser to load and print test.pdf instead of test.html when visitors tell their browser to print?



If it's not possible how can I introduce a print button (using JavaScript) within the HTML page to do so?


More From » html

 Answers
18

You cannot force the browser to print a different file than the user is requesting/viewing. That would be a security nightmare!



Option 1 (JS (as requested) & HTML)



I suggest creating a printable version link on your site that will direct the user to the .pdf (opening the PDF in a new window would be preferable).



<!-- JS -->
<script type=text/javascript>
function LoadPrintableVersion() {
window.open(Test.pdf);
}
</script>

<!-- HTML -->
<span id=spanPrintableVersion onclick=LoadPrintableVersion()>
Printable Version
</span>


Option 2 (pure html)



<a href=test.pdf target=_blank>Printable Version</a>

[#86902] Saturday, March 10, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adrienb

Total Points: 500
Total Questions: 104
Total Answers: 104

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
;