0

Using C# 3.5, I’m trying to programmatically create XPS files by sending them to the “Microsoft XPS Document Writer” printer. I’m able to set the print queue, but I’m unable to add a job to the print queue using the PrintQueue.AddJob() because it’s expecting a XPS file. I’ve also tried setting the PrintSystemInfo JobStream to a byte array to no avail.

Basically I want to mimic what a user does manually when printing to the “Microsoft XPS Document Writer”: 1. Select “Microsoft XPS Document Writer” from the list of printers. 2. Specify the new XPS file name. 3. Print it (which saves it as a .xps file)

I would think with the System.Printing and System.Windows.Xps namespaces there would be an easy way to do this. I’ve spent lots of time researching this and have seen other people trying to accomplish the same task, but no was able to provide an elegant solution.

Any insight would be much appreciated.

Thanks.

Binary Worrier
  • 50,774
  • 20
  • 136
  • 184

1 Answers1

1

What you should be seeking for is how to ask applications, that know how to read this files, to print them. I mean, Excel can render xslt, so you should ask Excel to print it to XPS writer (via COM maybe).

System.Windows.Xps namespace can help if you know how to read & render a document - then you make corresponding calls to XpsDocuments methods similar to this https://stackoverflow.com/a/352551/332528, rendering your document to xps and then printing it.

Community
  • 1
  • 1
torvin
  • 6,515
  • 1
  • 37
  • 52