views:

504

answers:

5
+2  Q: 

GDI To XPS

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.

A: 

Covered in another post by the same author - Creating XPS Documents from Visual, plus an insider look at an XPS Document.

dirkgently
That is not what I was after. Ive got an application that draws to a printer device context, and i want that printer to be the XPS Document Writer. The problem i face is the XPS printer pops up the save as dialog box.
Frank
A: 

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

marklam
+1  A: 

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.

Frank
A: 

You can use pdftron.PDF.PDFDCEx (pdftron.PDF.PDFDc) write to a DC (or Graphic object under .NET) the save to XPS using pdftron.PDF.Convert.ToXPS

For example, see http://www.pdftron.com/pdfnet/samplecode.html#PDFDC and Convert sample project).

Nick

Ivan
A: 

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).

emtipace

emtipace