print .doc file using Office Solutions Development

appleLover

New member
Joined
Mar 13, 2005
Messages
4
Hi all,

Im currently doing a project that allows the user to print doc file from asp.net mobile web application. It means that the user can print doc file while they are on the move.

My project is using asp.net mobile web application. I had made the enumeration of printer to allow the user to select the printer they want their document print to. Im using the Microsoft Word 1.0 Object Library, which I add reference from the COM, to print doc file.

Here are some of my code that called the Microsoft Word to print doc file for me:

Code:
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim wordapp As New Word.Application
        Dim docPolicy As Word.Document
        docPolicy = wordapp.Documents.Open("C:\TestPrinting.doc")
        wordapp.PrintOut( _
            Background:=True, _
              Append:=False, _
              Range:=Word.WdPrintOutRange.wdPrintAllDocument, _
              Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
              Copies:=1, _
              Pages:=1, _
              PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
              PrintToFile:=False, _
              Collate:=True, _
              ManualDuplexPrint:=False)
End Sub

However, there is an error. It said that my wordap.PrintOut(...) Type Mismatch. I get this code from the msdn:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/WordObject.asp

Could u please help me in solving this problem?

Another problem is that I want to allow the user to select the printer they want to print to. How can I call the selected printer to print the document?

If u see this thread, please replied to me. I need ur help greatly. I hope that u can replied as soon as possible. Your help is greatly appreciated.

Thanks.
 
Thanks for replying. But the help gave me printing of Excel and Access. And said that using "ThisDocument.PrintOut()" for printing of doc file. But I need to specific which printer to print to.

The Automating Word using the Word Object Model does not have "objApp.PrintOut(ActivePrinter:=strSelectedPrinter)". Only Excel has "objApp.Worksheets.PrintOut(ActivePrinter:=strSelectedPrinter)".

So if I dont use Word Object Model if there any class or help that I can specific the printer. I have tried using PrintDocument class but it does not allow me to print doc file and image in the doc file. Using PrintDocument class to print my doc file, it gave me funny characters.
 
I was just able to print out a Word Doc utilising the following:

[VB]
Dim wordapp As New Word.Application
Dim docPolicy As Word.Document
docPolicy = wordapp.Documents.Open("C:\TestPrinting.doc")
wordapp.PrintOut()
[/VB]

As to selecting the printer I normally use a print dialog to capture the existing default and the printer they want to use:
[VB]

Dim ps As New Printing.PrinterSettings
PrintDialog1.PrinterSettings = ps
Capture the Original Printer
strDefaultPrinter = Me.PrintDialog1.PrinterSettings.PrinterName
Need to Select the Printer
Me.PrintDialog1.ShowDialog()
strSelectedPrinter = Me.PrintDialog1.PrinterSettings.PrinterName

Change the default printer to reflect the selection
Call ChangeDefaultPrinter(strSelectedPrinter)

[/VB]

And then change the default printer in the registry:
[VB]
Public Function ChangeDefaultPrinter(ByVal prtName As String) As Boolean

Dim s As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Dim m As Microsoft.Win32.RegistryKey

m = s.OpenSubKey("Software")
m = m.OpenSubKey("Microsoft")
m = m.OpenSubKey("Windows NT")
m = m.OpenSubKey("CurrentVersion")
m = m.OpenSubKey("Windows", True)
m.SetValue("Device", prtName & ",winspool,FILE:")

m.Flush()
m.Close()
s.Close()


End Function
[/VB]

Then once I have finished the printing task I set the printer back to its default.

[VB]
Revert Back to the original default printer
Call ChangeDefaultPrinter(strDefaultPrinter)
[/VB]

Hope this helps
 
Thanks for your quick response. I appreciated your help greatly.

Emm.. I have another qns. If I want to print powerpoint slide, how can I do the same things as mentioned before.
 
Back
Top