如何在c#中使用PrintDialog类打印word文件 [英] How to print a word file using PrintDialog class in c#
本文介绍了如何在c#中使用PrintDialog类打印word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#中使用PrintDialog类打印word文件,我尝试使用以下代码但无法打印。
请参阅下面的代码片段并请建议
How to print a word file using PrintDialog class in c#, I have tried with following code but failed to print.
see below snippet and please suggest
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
PrinterSettings prnsetting = new PrinterSettings();
prnsetting.PrintFileName = @"D:\\.docx";
prnsetting.PrintRange = PrintRange.SomePages;
prnsetting.FromPage = 6;
prnsetting.ToPage = 8;
// printDoc.PrintPage += printDoc_PrintPage;
PageSettings pge = new PageSettings(prnsetting);
pge.Landscape = false;
printDoc.DocumentName = "test";
printDoc.PrinterSettings = prnsetting;
printDoc.PrintController = new StandardPrintController();
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
////Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK)
printDoc.Print();
推荐答案
我会使用自动化,例如,请参阅此Code Project文章:使用Word Automation打印Word文档 [ ^ ]。
I would use automation, see, for instance this Code Project article: "Printing a Word Document using Word Automation"[^].
这篇关于如何在c#中使用PrintDialog类打印word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文