Forum Moderators: open

Message Too Old, No Replies

Print in ASP?

I don't find a proper solution for printing with ASP

         

Droopy890

2:03 pm on Mar 13, 2002 (gmt 0)



I'd like to find a way so that I can print Word document with lay-out using ASP. If I use the OpenTextFile method, then where only be plain text of HTML source code. Does anyone know how to fix this problem? So that I can print Word documents with ASP.
I know that there are solutions for sale (expensive solutions), but it's for my final work for school. So I would appreciate it very much if somebody could help me with a code example or a suggestion.

Xoc

3:32 pm on Mar 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So let me get this right. You want to have a web server (on an Intranet?) that when you click on something, a Word document gets printed to a printer on your corporate network? And this is a low traffic web server?

If so, you can have your ASP page invoke Word as an out of process application on the server, then use Automation to tell word to open the document and print it. You will have to flip a registry setting on the server before IIS will let you open an out of process application, as it is considered a security risk if a web page can execute an arbitrary executable.

Droopy890

12:05 pm on Mar 14, 2002 (gmt 0)



Can't I call a Word-macro from an ASP-script, If I open the Worddocument by changing the contentType ( response.contentType = "application/msword").

Xoc

3:59 pm on Mar 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the client or the server? ASP code can't mess with Word on the client. ASP code can manipulate Word on the server.

I don't have a clear enough description of what you are trying to accomplish--can you be more explicit?

Droopy890

5:29 pm on Mar 14, 2002 (gmt 0)



If you have an intranet and you want to print Word-files from your intranet, how can you do this?
Can I use a macro to give a command to Word to open the file and print the file ( and after the printing close Word again )? Or can I accomplisch this with vbScript and ASP? (The first time I read the files using OpenTextFile and Printed them using CreateTextFile("LPT1:", True.... but then I lose the lay-out and get plain text)
Minor detail: the Word-files are HTML-files that are saved as .doc (It's something about generating dynamic files, my mentor wants it so!)
If I read the files using (OpenTextFile) and I print them in the browser (response.write) can I give a command then to print the file from the browser?
I have tried several things but most of them aint giving me a good lay-out (plain text or wrong papersettings).
I really hope that you can help me! :-)

Xoc

5:44 pm on Mar 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first step is to set a registry setting on the server. Run RegEdit and go here:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\ASP\Parameters

Then add AllowOutOfProcCmpnts and set the value to a DWORD with the value 1.

This will allow an ASP page to invoke Word on the server.

Then you can do automation to start up Word and print the document. An untested example (I'm not at a place where I can test this, so it might not work on first pass, but the idea is right):

Dim wrd
Set wrd = Server.CreateObject("MSWord.Application")

wrd.Documents.Open FileName:="test.doc", ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", Format:=wdOpenFormatAuto

wrd.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False

wrd.Close

Set wrd=Nothing

Droopy890

6:57 pm on Mar 14, 2002 (gmt 0)



thank you very much!!