Solved

Printing pdf from javascript

Posted on 2006-11-03
5
3,345 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

617 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