Solved

Printing pdf from javascript

Posted on 2006-11-03
5
3,341 Views
Last Modified: 2008-02-01
Hi, is it possible to print a pdf from javascript?

I looked into using the window.open() method which opens the pdf but how can I call a print method on the child window?
0
Comment
Question by:Chriseybaby
5 Comments
 
LVL 4

Expert Comment

by:pzepernick
ID: 17865663
Maybe this thread will help:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20846776.html

I think you can reference the open window like so:

var mywin = window.open(...);

mywin.document.afunction()


Paul
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17865818
You cannot.

However you can have a javascript instruction in the PDF that will make it print itself

2 0 obj
<</S /JavaScript
/JS (this.print(true))>>
endobj


Michel
0
 

Author Comment

by:Chriseybaby
ID: 17866704
Sorry i dont have much experience with pdf's, how do you put js in a pdf?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17867007
You do that when you create it.
If you do not create the pdf, I cannot help you. Sorry.
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 125 total points
ID: 17873693
Hi,

http://www.planetpdf.com/forumarchive/forum34.asp
http://www.planetpdf.com/developer/article.asp?ContentID=printing_page_ranges_quickly_w

Sample Code:
<html>
<head>
<script>
function doit() {
var x = document.getElementById("doodad");
//.document.plugins.whatever
x.click();
x.setActive();
x.focus();
x.print();
}
</script>

</head>
<body>
<embed id="doodad" src ="D:\Documents and
Settings\ron\Desktop\eth_cli.pdf" width="550" height="550"
name="whatever">
<button onclick="doit()">howdy</button>
</body>
</html>

OR

<frameset framespacing="0" border="false" rows="0,*" frameborder="0">
  <frame name="hidden" scrolling="no" noresize src="http://www.boston.com/globe/acrobat/today.pdf">
  <frame name="main" scrolling="no">
</frameset>

OR

alternatively try this:

<link ref="alternate" media="print" href="certificate.pdf">

pdf page MUST be static for that to work. Whatever method the user uses to print the page, the pdf will print instead

Should work in IE5+ and NS6+/Mozilla

R.K
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now