简体   繁体   中英

How can I print a Word document in C# without showing the print dialog

I'm using C# and Word Interop to automate a mail merge. I want to print each merged document to the default printer with the default options but don't want the print options dialog to show each time. How can I do this? When I try this code on my client machine, a print options dialog displays when the PrintOut method is called. Here's my code:

Word.Application oWord = new Word.Application();
oWord.Visible = false;
Word.Document oWordDoc = new Word.Document();
object oTemplatePath = Path.Combine(baseDir, fileName);
oWordDoc = oWord.Documents.Add((ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
object copies = "1";
object pages = "";
object range = Word.WdPrintOutRange.wdPrintAllDocument;
object items = Word.WdPrintOutItem.wdPrintDocumentContent;
object pageType = Word.WdPrintOutPages.wdPrintAllPages;
object oTrue = true;
object oFalse = false;
oWordDoc.PrintOut(ref oTrue, ref oFalse, ref range, ref oMissing, ref oMissing, ref oMissing, ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

I am using this one, it works ok for word docs.

        Process p = new Process();
        p.StartInfo = new ProcessStartInfo();
        p.CreateNoWindow = true;
        p.Verb = "print";
        p.FileName = file;

        p.Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM