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
Solved

Auto Print Word Document

Posted on 2004-08-24
7
690 Views
Last Modified: 2013-12-24
OK, I have an invoice I want to automatically print when I post the order. No one else can print and there is a default printer. However, I am using cfheader and making it a word document. The following code works fine in a html document but does not auto print when I call to the invoice.cfm (ms word template)

<body>

Hello Kendra

<script language=JScript>
function doprint() {
document.body.insertAdjacentHTML("beforeEnd", "<object id='idWBPrint' width=0 height=0 classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'></object>");
idWBPrint.ExecWB(6, -1);
idWBPrint.outerHTML = ""; }
if (window.self) window.doprint();
</script>

</body>

Anyone know of a way to auto print using this or something better? It has to be a word document though. Thanks
0
Comment
Question by:alabamsterdam
  • 3
7 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11888111
Hi

Er...

<html>
<head>
<title>Test Word Print</title>
</head>
<body>
<?php
//Word Path
$word_file="someFile.doc";
$save_as="someFile.html";

$errmsg = "";
if ($w=new com("Word.Application")) {
   if ($w->Visible=1) {
      if ($w->Documents->Open($word_file)) {
         $w->Documents[1]->saveas($save_as, wbFormatHTML);
         $w->Quit();
      } else {
         $errmsg+="Could not open $word_file!<br>";
      }
   } else {
      $errmsg+="Could not set Word to visible state!<br>";
   }
} else {
   $errmsg+="Could not open Word. Make sure Word is installed on your machine.";
}
echo($errmsg);

if ($errmsg=="") {
   if ($fp=fopen($save_as,"r")) {
      $contents = fread($fp,filesize($fp));
      echo($contents);
   } else {
      echo("Error reading file $save_as!<br>");
      exit;
   }
} else {
   exit;
}

?>
<script language=JScript>
function doprint() {
document.body.insertAdjacentHTML("beforeEnd", "<object id='idWBPrint' width=0 height=0 classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'></object>");
idWBPrint.ExecWB(6, -1);
idWBPrint.outerHTML = ""; }
if (window.self) window.doprint();
</script>
</body>
</html>

Regards,
Zyloch
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11888116
Not the cleanest code, but should work if you have Word2000+ and PHP. If you have Word97 only, then you should change $save_as to someFile.txt and change vbFormatHTML to vbFormatText or vbFormatTextLineBreaks whichever one suits you better.

Regards
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11888124
Oops, just noticed this was in ColdFusion, sorry about the PHP example...

Regards
0
 
LVL 17

Accepted Solution

by:
anandkp earned 250 total points
ID: 11889520
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cloud web Service looking for a home... 3 111
IIS 8.5 2 52
Websocket through haproxy reused connection causes "Not a valid frame" error. 4 106
System Analysis 5 61
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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