Solved

Using javascript: Sending a word file straight to print!

Posted on 2004-03-22
4
3,177 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
ID: 10648434
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 33

Accepted Solution

by:
shalomc earned 50 total points
ID: 10648532
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
ID: 11660177
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 33

Expert Comment

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

Cheers,
ShalomC
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Read about why website design really matters in today's demanding market.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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