Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing pdf from javascript

Posted on 2006-11-03
5
Medium Priority
?
3,347 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 500 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

670 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