Click to See Complete Forum and Search --> : Sending text to a printer


tacallah
05-19-2003, 12:02 PM
I have a report stored in a string, and I want to send it to the printer. Has anyone done this? Below is some code that works if I open it as C:\Temp\Test.htm in Internet Explorer, but I receive the error "Automation server can't create object" when I save the same file on the web server and open it in Internet Explorer. If there is better way to do this, please let me know. I know this is the JavaScript forum, but I am using ASP. Could I possible use Response.BinaryWrite instead?

Thanks in advance for your help!
Tim

<INPUT TYPE="Button" VALUE="Print Text" onClick=PrintIt()>

<SCRIPT LANGUAGE="JavaScript">
function PrintIt()
{
var ofs, oPrinter;

ofs = new ActiveXObject("Scripting.FileSystemObject");
oPrinter = ofs.CreateTextFile("LPT1:", true);
oPrinter.Write("Test");
oPrinter.Close();
alert("Done");
}
</SCRIPT>

khalidali63
05-19-2003, 12:14 PM
JavaScript can not do the way you are trying it to.If your activeXcontrol can print this text fileto a fraem window or a new window then you can print it from that window.

window.print();

or parent.frame.window.print();

tacallah
05-19-2003, 12:34 PM
Thanks for the reply! It is interesting that it works if I pull it up as file rather that a URL. Here is what I am trying to do. I have report written in Visual FoxPro. I have COM DLL that runs this report and sends back the report text in a variable to a ASP page. Unfortunately, I cannot simply display the report in the browser since the report text is really the contents of a postscript file. Do you have any ideas?

Thanks again for your help!
Tim

tacallah
05-19-2003, 05:39 PM
FYI, I was able to get this to work with ASP. For those who are curious, here is what I did. In the ASP page, I did the following:

Response.Clear
Response.ContentType = "application/postscript"'
Response.BinaryWrite pcText

On the client, I added a "PS" file type and associated it to C:\WinNt\System32\Print.exe. Click off "confirm open after download" to prevent dialog box from popping up everytime the page is displayed.

Thanks for you help!
Tim