Solved

Printing pdf from javascript

Posted on 2006-11-03
5
3,344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
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…

751 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