Printing a Word Document in WPF

Hi,
Now that we have our documents ready to go, we want to be able to allow users to print them off through our application. We would like to display the print dialog to have them select their printer and options.
Looking through documentation though, WPF doesnt seem to support the same PrinterSettings object like windows.forms. When I tried using a windows.forms print dialog, it works, but the PrinterSettings didn’t seem to match up to the example available on this site.
Could you provide an example of how to print in WPF?

Hi
Thanks for your request. I think you should use code like the following:

// Create print dialog
System.Windows.Forms.PrintDialog prnDialog = new System.Windows.Forms.PrintDialog();
// Set PrinterSettings. The default settings will assigned
prnDialog.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
// Show print dialog
if (prnDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    // Here you can print the document using prnDialog.PrinterSettings set by user.
    // Open document
    Document doc = new Document(@"C:\Temp\in.doc");
    // Print document
    doc.Print(prnDialog.PrinterSettings);
}

Hope this helps.
Best regards.

So you recomend using the Windows.Forms printer dialog in the WPF app?

I think it is the easiest way to achieve what you need.
Best regards.

ok, thank you for your help.
Using this example though, I can not change page range through the print dialog, how would this be enabled?

Hi
Thanks for your request. You should set AllowSomePages property of PrintDialog as shown in the following code:

// Create print dialog
System.Windows.Forms.PrintDialog prnDialog = new System.Windows.Forms.PrintDialog();
// Set PrinterSettings. The default settings will assigned
prnDialog.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
prnDialog.AllowSomePages = true;

Hope this helps.
Best regards.

Hi!

When I use this method of printing, it seems as if the text is being layed out twice on the page, once with default font, and second with my font in the document.

Also, it takes forever to print in this way. Am I missing something?

I posted about this issue on StackOverflow: http://stackoverflow.com/questions/9720465/print-word-document-from-wpf-with-print-settings-aspose-generated

Best regards,
Cederlof

Hi Cederlof

Thanks for your inquiry.

Could you please attach your document here for testing? By any chance are you using the legacy text frames (not text boxes) in your document? There are some situations where floating tables/frames/textboxes etc will be displaced. If they are large enough this may overlap during rendering.

Also what OS and version of Aspose.Words are you using?

Thanks,

Hi Cederlof,

From your update on StackOverflow I see you found the root of the issue to be a hidden image. Could you please attach this document for testing so we can find out why that hidden image becomes visible during rendering?

Also, did you have any other problems during testing using Aspose.Words to print your documents?

Thanks,