0

I'm creating a WPF application and I want print a word document using spire.doc. I read some tutorials and they say that I should use this code.

//Create Word document.
Document document = new Document();
document.LoadFromFile(@"..\..\..\..\..\..\Data\Template.docx");
//Print doc file.
System.Windows.Forms.PrintDialog dialog = new System.Windows.Forms.PrintDialog();
dialog.AllowCurrentPage = true;
dialog.AllowSomePages = true;
dialog.UseEXDialog = true;
try
{
document.PrintDialog = dialog;
dialog.Document = document.PrintDocument;
dialog.Document.Print();
}

But it doesn't work because document.PrintDialog type is System.Windows.Controls.PrintDialog and I get this error:

cannot implicitly convert type 'System.Windows.Forms.PrintDialog' to 'System.Windows.Controls.PrintDialog'

Adrian
  • 8,271
  • 2
  • 26
  • 43
omid naghipoor
  • 178
  • 1
  • 2
  • 12

2 Answers2

0

Can you not use Document.PrintOut() documentation can be found here.

Seth
  • 1
  • 1
0

You can use Spire.Doc.Wpf.dll to print Word document in WPF applications. Refer to the following code:

private void button1_Click(object sender, RoutedEventArgs e)
    {
        Document doc = new Document();
        doc.LoadFromFile(@"Test.docx");
        PrintDialog dialog = new PrintDialog();

        if (dialog.ShowDialog() == true)
        {
            dialog.PrintDocument(doc.PrintDocument.DocumentPaginator, "test");
        }
    }

If my answer helps, please mark it as answer, thanks :)

Dheeraj Malik
  • 703
  • 1
  • 4
  • 8