Click here to Skip to main content
15,908,264 members
Home / Discussions / C#
   

C#

 
GeneralRe: Graphics Class Pin
Muhammad Gulzaib Khan16-Jul-05 9:03
Muhammad Gulzaib Khan16-Jul-05 9:03 
GeneralRe: Graphics Class Pin
Amir Jalaly16-Jul-05 20:56
Amir Jalaly16-Jul-05 20:56 
Generalcommunicate with other app from an app Pin
ppp00115-Jul-05 6:19
ppp00115-Jul-05 6:19 
GeneralRe: communicate with other app from an app Pin
Alexander Kent15-Jul-05 10:24
Alexander Kent15-Jul-05 10:24 
GeneralUpdating Windows components Pin
Heapster15-Jul-05 6:18
Heapster15-Jul-05 6:18 
GeneralRe: Updating Windows components Pin
Alexander Kent15-Jul-05 10:23
Alexander Kent15-Jul-05 10:23 
GeneralRe: Updating Windows components Pin
Heapster15-Jul-05 11:22
Heapster15-Jul-05 11:22 
GeneralPrinting Word Documents Pin
tartanmonkey15-Jul-05 4:56
tartanmonkey15-Jul-05 4:56 
I feel I need to share this pain. I have been struggling for days now to get something simple to work for me. That is to print out a Word document(rtf format) to a printer using Word. It also has to work with multiple versions of Word (so far 2000 and 2003). I thought I would share everything that I have learnt.

If you want this to work for multiple versions, install the earliest version of Word and Add Reference to it's COM component and develop against these.

Next to the code...

<br />
// Create an Application object<br />
Word.ApplicationClass ac = new Word.ApplicationClass();<br />
Word.Application app = ac.Application;<br />
<br />
// I'm setting all of the alerts to be off as I am trying to get<br />
// this to print in the background<br />
app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;<br />
<br />
// Open the document to print...<br />
object filename = "myFile.rtf";<br />
object missingValue = Type.Type.Missing;<br />
<br />
// Using OpenOld so as to be compatible with other versions of<br />
// Word<br />
Word.Document document = app.Documents.OpenOld(ref filename,<br />
                    ref missingValue, ref missingValue, <br />
ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);<br />
<br />
// Set the active printer<br />
app.ActivePrinter = "My Printer Name";<br />
<br />
object myTrue = true; // Print in background<br />
object myFalse = false;<br />
<br />
// Using PrintOutOld to be version independant<br />
m_App.ActiveDocument.PrintOutOld(ref myTrue, <br />
                    ref myFalse, ref missingValue, ref missingValue, ref missingValue, missingValue, ref missingValue, <br />
ref missingValue, ref missingValue, ref missingValue, ref myFalse, ref missingValue, ref missingValue,    ref m_MissingValue);<br />
<br />
document.Close(ref missingValue, ref missingValue, ref missingValue);<br />
<br />
// Make sure all of the documents are gone from the queue<br />
while(m_App.BackgroundPrintingStatus > 0)<br />
{<br />
     System.Threading.Thread.Sleep(250);<br />
}<br />
<br />
app.Quitref missingValue, ref missingValue, ref missingValue);<br />


I do not claim that this is perfect, but it's as good as I can get. It works on my machine anyway
GeneralRe: Printing Word Documents Pin
Dave Kreskowiak15-Jul-05 5:36
mveDave Kreskowiak15-Jul-05 5:36 
GeneralRe: Printing Word Documents Pin
tartanmonkey15-Jul-05 5:45
tartanmonkey15-Jul-05 5:45 
GeneralWriting into a .def file(definition file) Pin
Member 211897915-Jul-05 4:52
Member 211897915-Jul-05 4:52 
GeneralRe: Writing into a .def file(definition file) Pin
Colin Angus Mackay15-Jul-05 5:31
Colin Angus Mackay15-Jul-05 5:31 
GeneralRe: Writing into a .def file(definition file) Pin
Dave Kreskowiak15-Jul-05 5:35
mveDave Kreskowiak15-Jul-05 5:35 
GeneralRe: Writing into a .def file(definition file) Pin
Member 211897917-Jul-05 23:19
Member 211897917-Jul-05 23:19 
GeneralMethod Access Pin
zaboboa15-Jul-05 4:45
zaboboa15-Jul-05 4:45 
GeneralRe: Method Access Pin
Hugo Migneron15-Jul-05 6:05
Hugo Migneron15-Jul-05 6:05 
GeneralRe: Method Access Pin
zaboboa15-Jul-05 6:52
zaboboa15-Jul-05 6:52 
GeneralRe: Method Access Pin
Hugo Migneron15-Jul-05 7:02
Hugo Migneron15-Jul-05 7:02 
GeneralNetbios Messages sent before UDP packet Pin
Will987654321015-Jul-05 4:05
Will987654321015-Jul-05 4:05 
GeneralRe: Netbios Messages sent before UDP packet Pin
leppie15-Jul-05 6:05
leppie15-Jul-05 6:05 
GeneralRe: Netbios Messages sent before UDP packet Pin
Will987654321015-Jul-05 9:25
Will987654321015-Jul-05 9:25 
Questionopen direcory dialog? Pin
zhujp9815-Jul-05 3:54
zhujp9815-Jul-05 3:54 
AnswerRe: open direcory dialog? Pin
Werdna15-Jul-05 6:42
Werdna15-Jul-05 6:42 
GeneralChange order of tab pages in tab control Pin
Darryl Borden15-Jul-05 2:47
Darryl Borden15-Jul-05 2:47 
GeneralRe: Change order of tab pages in tab control Pin
Werdna15-Jul-05 6:43
Werdna15-Jul-05 6:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.