appleLover Posted March 13, 2005 Posted March 13, 2005 Hi all, I'm 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. I'm 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: 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. Quote
SonicBoomAu Posted March 13, 2005 Posted March 13, 2005 Don't know if these wil help or not but they might be worth a look. http://www.xtremedotnettalk.com/showthread.php?t=91147&highlight=printing http://www.xtremedotnettalk.com/showthread.php?t=90681&highlight=printing Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
appleLover Posted March 14, 2005 Author Posted March 14, 2005 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 don't 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. Quote
SonicBoomAu Posted March 14, 2005 Posted March 14, 2005 I was just able to print out a Word Doc utilising the following: Dim wordapp As New Word.Application Dim docPolicy As Word.Document docPolicy = wordapp.Documents.Open("C:\TestPrinting.doc") wordapp.PrintOut() As to selecting the printer I normally use a print dialog to capture the existing default and the printer they want to use: 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) And then change the default printer in the registry: 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 Then once I have finished the printing task I set the printer back to it's default. ' Revert Back to the original default printer Call ChangeDefaultPrinter(strDefaultPrinter) Hope this helps Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
appleLover Posted March 14, 2005 Author Posted March 14, 2005 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. Quote
SonicBoomAu Posted March 14, 2005 Posted March 14, 2005 Haven't honestly tried to print Powerpoint before. The following site might give you some ideas though. http://support.microsoft.com/default.aspx?scid=kb;en-us;q311452 http://support.microsoft.com/kb/308330/EN-US/ http://support.microsoft.com/kb/303717/EN-US/ Sorry I can't give you anymore info. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
appleLover Posted March 15, 2005 Author Posted March 15, 2005 Its ok. You had helped me greatly. Thanks for helping me. :) Quote
MSHANE Posted October 26, 2010 Posted October 26, 2010 Providing solutions is essential to all kinds of business. Thus, having the right partner for this field is necessary in order to function fast and easy and have great results. Soluzione Ufficio di Mario Salsano Quote
Recommended Posts