code for printing

meLikeNoOther

New Member
good day everyone!!
i believe you could help me with this..how could i directly print a certain document in such a way that it would only take a click of button avoiding the print dialog box..is this possible in webspeed??please help..it would be of great use..
 

Casper

ProgressTalk.com Moderator
Staff member
I found something which supposed to work, but I can't seem to get it to work in IE6..... :D (Dialog keeps popping up...grrr....) But anyhow, this should work:

Code:
<html>
<head>
<title>Print Page Test</title>
<SCRIPT>
 function print_moz() 
   {window.print() ;
    print() ;} 
 function print_ms() {        
        var OLECMDID_PRINT = 6;
        var OLECMDEXECOPT_DONTPROMPTUSER = 2;
        var OLECMDEXECOPT_PROMPTUSER = 1;
        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        oldHandler = window.onerror;        
        window.onerror = deal;
        WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
        WebBrowser1.outerHTML = "";        
        window.onerror = oldHandler;}
 
  function deal() {                
        WebBrowser1.outerHTML = "";
        window.onerror = oldHandler;                
        return true;
        }
</SCRIPT>
</head>
<body bgcolor="#ffffff">
<h1>This is the test page</h1>
Lets see if it works!
<FORM>
<SCRIPT LANGUAGE="javascript">
  <!--
  var version="";
  if (navigator.userAgent.indexOf("Mozilla/4") != -1) version =
"moz_valid";
  else if (navigator.userAgent.indexOf("Mozilla/5") != -1) version =
"moz_valid";
  else if (navigator.userAgent.indexOf("Mozilla/6") != -1) version =
"moz_valid";
  else if (navigator.userAgent.indexOf("Mozilla/7") != -1) version =
"moz_valid";
  if (navigator.userAgent.indexOf("MSIE 5") != -1) version = "ms_valid";
  else if (navigator.userAgent.indexOf("MSIE 6") != -1) version =
"ms_valid";
  else if (navigator.userAgent.indexOf("MSIE 7") != -1) version =
"ms_valid";
  else if (navigator.userAgent.indexOf("MSIE 4") != -1) version =
"ms_valid";
  if (version == "moz_valid") {
    document.write('<input type=button value="PRINT" name="Print"
onClick=print_moz()>') ;  }
  else if (version == "ms_valid") {
    document.write('<input type=button value="PRINT" name="Print"
onClick=print_ms()>') ;  }
    version = "" ;
  // -->
</SCRIPT>
</FORM>
</html>

The point is that Mozilla browsers do it easy without a dialog and MS browser need some OLE handling of the browser.

HTH,

Casper.

edited:
--> To not show the dialog according to microsoft OLECMDEXECOPT_DONTPROMPTUSER should do the trick. Unfortunately I didn't succeed in that.
If anyone else does, I'm happy to hear. I just started to look for a solution and I'm positive this is the way except.... :)
 

YOSANTO

New Member
hi,

i think u can use PdfInclude plugins,
before u should install adobe reader.
then copy the pdfinclude plugin to ur working directory (/usr/wrk)
compile the file *.p (pdfinclude file).

make a simple xxx.html to get input value, then make a yyy.p file that have printing code (get sample code in documentation). if u submit to yyy.p from xxx.html, webspeed will show a pdf file (ur report)....

it works in IE, Opera Browser...

hope this help u.
best regards yosanto.
 
Top