Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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();
Posted
Comments
phil.o 26-Oct-15 3:32am    
"but failed to print"
Please tell us what error/exception you are getting.
koolprasad2003 26-Oct-15 7:52am    
No error message, but file printed as empty page basically how to give file name to be printed using print dialog

1 solution

I would use automation, see, for instance this Code Project article: "Printing a Word Document using Word Automation"[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900