Solved

Printing pdf from javascript

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

762 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

10 Experts available now in Live!

Get 1:1 Help Now