Mylor
asked on
Print PDF form a link
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!
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!
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.getElementBy Id(element Id);
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>
<html>
<head>
<script>
function printPDF(elementId){
var elem=document.getElementBy
elem.contentWindow.focus()
elem.contentWindow.print()
}
</script>
</head>
<body>
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<iframe id="PDF1" name="PDF1" src ="PCNMap.pdf" width="0" height="0" style="visibility:hidden">
<iframe id="PDF2" name="PDF2" src ="PCNMap.pdf" width="0" height="0" style="visibility:hidden">
<iframe id="PDF3" name="PDF3" src ="PCNMap.pdf" width="0" height="0" style="visibility:hidden">
</body>
</html>
ASKER
I really like this solution, but for some reason it doesn't work:
<html>
<head>
<script>
function printPDF(url){
document.getElementById('P df1').src= url;
document.getElementById('P df1').prin tWithDialo g();
}
</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>
<html>
<head>
<script>
function printPDF(url){
document.getElementById('P
document.getElementById('P
}
</script>
</head>
<body>
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<object id="Pdf1" type="application/pdf" style="width:0;height:0"><
</body>
</html>
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?
What configuration do you have?
Also how is it not working? Is it giving any errors?
ASKER
No it does not give me any errors, just doesn't do anything.
I have IE7 and Adobe 8
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?)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:makePDFPr int()">Pri nt</a> What would makePDFPrint() do to call the javascript in the PDF?
Dave
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:makePDFPr
Dave
It would not
So <a href="pdfFileWithEmbeddedJ avascriptT hatPrints. pdf">Print </a>
So <a href="pdfFileWithEmbeddedJ
<html>
<head>
<script>
function printPDF(url){
document.getElementById('P
document.getElementById('P
}
</script>
</head>
<body>
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<object id="Pdf1" type="application/pdf" style="width:0;height:0"><
</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(el
x.click();
x.setActive();
x.focus();
x.print();
}
</script>
</head>
<body>
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<a href="javascript:printPDF(
<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>