Print PDF form a link

Mylor
Mylor used Ask the Experts™
on
Ok, I m driving my self crazy. I need to print several PDF files from links in my page, can anyone help please.

ie:

Print File 1 (will print, www.mysite.com/adobedoc1.pdf )
Print File 2 (will print, www.mysite.com/adobedoc2.pdf )
Print File 3 (will print, www.mysite.com/adobedoc3.pdf )

Thanks in advance!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This will work in internet explorer:

<html>
<head>
<script>
function printPDF(url){
      document.getElementById('Pdf1').src=url;
      document.getElementById('Pdf1').printWithDialog();
}
</script>
</head>
<body>
<a href="javascript:printPDF('www.mysite.com/adobedoc1.pdf');">Print File 1</a><BR>
<a href="javascript:printPDF('www.mysite.com/adobedoc2.pdf');">Print File 2</a><BR>
<a href="javascript:printPDF('www.mysite.com/adobedoc3.pdf');">Print File 3</a>
<object id="Pdf1" type="application/pdf"  style="width:0;height:0"></object>
</body>
</html>





For other browsers you will probably have to create a separate embed or object for each pdf you want to print and have them get loaded when the page loads. (Similar to one of your previous posts):

<html>
<head>

<script>
function printPDF(elementId){
      var x = document.getElementById(elementId);
      x.click();
      x.setActive();
      x.focus();
      x.print();
}
</script>

</head>
<body>
<a href="javascript:printPDF('PDF1');">Print File 1</a><BR>
<a href="javascript:printPDF('PDF2');">Print File 2</a><BR>
<a href="javascript:printPDF('PDF3');">Print File 3</a>


<embed id="PDF1" src ="www.mysite.com/adobedoc2.pdf" width="0" height="0">
<embed id="PDF2" src ="www.mysite.com/adobedoc2.pdf" width="0" height="0">
<embed id="PDF3" src ="www.mysite.com/adobedoc3.pdf" width="0" height="0">

</body>
</html>
I can get this to work in fire fox but in IE it prints all the links and not the pdfs

<html>
<head>
<script>
function printPDF(elementId){
      var elem=document.getElementById(elementId);
      elem.contentWindow.focus();
      elem.contentWindow.print();
}
</script>
</head>
<body>
<a href="javascript:printPDF('PDF1');">Print File 1</a><BR>
<a href="javascript:printPDF('PDF2');">Print File 2</a><BR>
<a href="javascript:printPDF('PDF3');">Print File 3</a><BR>
<iframe id="PDF1" name="PDF1" src ="PCNMap.pdf" width="0" height="0" style="visibility:hidden"></iframe>
<iframe id="PDF2" name="PDF2" src ="PCNMap.pdf" width="0" height="0" style="visibility:hidden"></iframe>
<iframe id="PDF3" name="PDF3" src ="PCNMap.pdf" width="0" height="0" style="visibility:hidden"></iframe>
</body>
</html>

Author

Commented:
I really like this solution, but for some reason it doesn't work:



<html>
<head>
<script>
function printPDF(url){
      document.getElementById('Pdf1').src=url;
      document.getElementById('Pdf1').printWithDialog();
}
</script>
</head>
<body>
<a href="javascript:printPDF('www.mysite.com/adobedoc1.pdf');">Print File 1</a><BR>
<a href="javascript:printPDF('www.mysite.com/adobedoc2.pdf');">Print File 2</a><BR>
<a href="javascript:printPDF('www.mysite.com/adobedoc3.pdf');">Print File 3</a>
<object id="Pdf1" type="application/pdf"  style="width:0;height:0"></object>
</body>
</html>
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Is it not working in IE?  I've tried it with IE 6 and 7.  And I have Adobe 7.0 on my machine.
What configuration do you have?
Also how is it not working?  Is it giving any errors?

Author

Commented:
No it does not give me any errors, just doesn't do anything.
I have IE7 and Adobe 8
Hmmm,  printing PDFs using javascript has been a struggle for me for years, I've never found a real solid solution.  If you expand the size of the <object> so you can see it does the PDF acctually get loaded into the object? (can you see the pdf when you click the print link?)
IT Expert
Top Expert 2009
Commented:
Alternative is to have the pdf print itself.
If you can, insert a print javascript in the pdf file
mplungjan,

So how would you have the javascript with in the PDF get executed when the user clicks on a link in the HTML page?  

So <a href="javascript:makePDFPrint()">Print</a>  What would makePDFPrint() do to call the javascript in the PDF?  

Dave
Michel PlungjanIT Expert
Top Expert 2009

Commented:
It would not

So <a href="pdfFileWithEmbeddedJavascriptThatPrints.pdf">Print</a>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial