Solved

Using javascript: Sending a word file straight to print!

Posted on 2004-03-22
4
3,309 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
[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
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

734 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