Solved

Using javascript: Sending a word file straight to print!

Posted on 2004-03-22
4
3,096 Views
Last Modified: 2008-02-01
Hi,

I would like to print a specific word file, using javascript.

i.e. something like  <input type="button" onclick="Print(wordfile.doc);">

But i am unsure on the correct procedure.

Any help would be greatly appreciated.

Easynow
0
Comment
Question by:Dean OBrien
  • 2
4 Comments
 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
normal html and javascript do not support such a print-command like your's shown above. could be that there is a "special" microsoft-VERSION that is able to handle such a problem. but there is the problem then that no other browser will support this.
the ie is able to load a word-file directly into browsers view-area. you only have to put a link onto the word-document and the client-computer has to have office installed. then the user may print the document.

the javascript-code working with nearly all browsers should be:

<html><head><title>Test</title>
</head><body>
<a href="javascript:window.print()">Print this page...</a>
</body></html>

some browsers do not support it. and the code only prints the currently shown page in browser (html, ...)
0
 
LVL 32

Accepted Solution

by:
shalomc earned 50 total points
Comment Utility
When you click on the document link, it will open the word document.
When you click on the Print.gif (create your own..) image, the word document will be printed automatically.
This trick works with any URL - you can print a web site page without opening it first.


<HTML>
<HEAD>
<!-- place this tag before other LINK tags in the HEAD section --->
<link id="prt" name="prt" rel=alternate media=print href="something"/>

<TITLE>printout</TITLE>

<script>
function printWindow(){
  bV = parseInt(navigator.appVersion)
  if (bV >= 4) window.print()
}

function setPrintedPage(altdoc) {
var prt;
var prt = document.getElementsByTagName("link")[0];
prt.setAttribute("href", altdoc);
printWindow();
}

</script>

</HEAD>

<BODY>
<a href="document1.doc">document #1</a><img src="print.gif" onClick="setPrintedPage('document1.doc');"><br>
<a href="document2.doc">document #2</a><img src="print.gif" onClick="setPrintedPage('document2.doc');"><br>
<a href="document3.doc">document #3</a><img src="print.gif" onClick="setPrintedPage('document3.doc');"><br>
</BODY>
</HTML>

http://www.experts-exchange.com/Web/Q_20712989.html

ShalomC
0
 

Expert Comment

by:HansBaumann
Comment Utility
Nice solution!... but (always a but) ... we've just tried to use it from a flash movie, and it gets unpredictable behavours, sometimes it prints the html page instead of the actual .doc file, other times just prints part of the document. We're using IE 6 in all cases, windows 2000 profesional and windows xp, no matter the window's version nor the explorer's it gives the same problem...

I didn't make too much tests using just the html page without flash, but, should anyone knows if the problems came from the flash movie??

NOTE: I've just used the

getURL("javascript:setPrintedPage('wordocu.doc');");

in the actionscript code...

Thanks, Hans.

0
 
LVL 32

Expert Comment

by:shalomc
Comment Utility
Hey,
I've never tried it with flash actionscript, but it always works fine in a regular browser.

Cheers,
ShalomC
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

743 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

16 Experts available now in Live!

Get 1:1 Help Now