Question

In his blog entry Printing documents to Microsoft XPS Document Writer without user interaction Feng Yuan says

If you're printing from your own applications, it's easy to specify MXDW as the printer driver and provide a file name for the XPS document to be saved to

Can anyone explain how to do that and provide a code sample?

The main problem I am having is suppressing the Save As dialog that the Microsoft XPS Document Writer pops up. I am loathed to resort to UI hacking as Yuan does in his post.

Currently my application makes GDI drawing calls on the Device Context of what ever printer the user wants to use. I can make those calls on the XPS Document Writer fine, but when it come times to complete the printing the XPS Writer pops up the save as dialog box.

Was it helpful?

Solution

Indeed the same author provides the answer Printing to Microsoft XPS Document Writer without showing File Save Dialog Box. The solution is to print to a file using the Microsoft XPS Document Writer printer.

OTHER TIPS

And if you're wanting to avoid hitting the filesystem with your XPS document, Shahed Kahn gives sample code in Loading Xps From MemoryStream.

Here's what works for me:

  With Me.PrintDocument
     With .PrinterSettings
        .PrinterName = "Microsoft XPS Document Writer"
        .PrintToFile = True
        .PrintFileName = "c:\test.xps"
     End With
    .Print()
  End With

As far as I know, this is undocumented. Give it a try and you won't get the dreaded Save As dialog. Instead you get a clean XPS file generated by MXDW (c:\test.xps).

Just remove and re-install Microsoft XPS Document Writer, follow the steps below during re-installation..

Go to Start - Control Panel - Add new printer. Then choose Local printer and Create new port. Select Local Port in combo box. The dialog asking for a port name will appear. For our XPS driver to print to specified file without asking a user for a location, write in full path for this output file. This file need not to exist at the moment (something like c:\mydriveroutput.xps for example).

See this link for detail: https://kibitzercz.blogspot.in/2012/01/building-and-using-xpsdrvsmpl-under.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top