views:

608

answers:

3

If a user prints a report, and they happen to be using the Microsoft XPS printer, i would like the default the filename to something meaningful.

i would have thought that the XPS printer would take the name of the print job, and use that as the default filename - but it doesn't.

Is there some other, programatic, way to default the name of the generated XPS file when i print to that printer? i was thinking there might be something like:

  • a registry key
  • global shared memory
  • API call like SetDefaultXPSFilename()
  • extended attributes about a print job

References

Bump: 20110515 (10 months later)

A: 

The Microsoft XPS Document Writer (MXDW) will generate an output file path without prompting the user if the application that prints sets lpszOutput in DOCINFO.

If you don't have access to the code of the application then another option is to build an XPS driver that generates a file path even when lpszOutput hasn't been set. The Windows Driver Kit (WDK) is the place to start.

For more details and links see this post.

It doesn't actually work.
Ian Boyd
A: 

Win2PDF 7 can save as XPS, and does default to the name of the print job. If you don't want to use the print job as the name displayed in the File Save dialog, you can change the default file name by setting a registry value named "PDFTitle".

You can also set the output file without prompting either using the lpszOutput field of DOCINFO, or by setting a registry setting named "PDFFileName" as described in the Win2PDF documentation. The file will be created in the XPS format if the file name contains an .xps extension.

Craig Lebakken
Only if i can convince Microsoft to ship Win2PDF with Windows.
Ian Boyd
+1  A: 

Well, here is a simple way (at least in my case):

(myPrintPage inherits from System.Drawing.Printing.PrintDocument)

    With myPrintPage
        With .PrinterSettings
            If .PrinterName = "Microsoft XPS Document Writer" Then
            .PrintToFile = True
            .PrintFileName = "c:\test.pdf"
            End If
        End With
        .Print()
    End With

I haven't found a way, yet, to determine whether or not the printer I have chosen is going to print into a file, hence the test on the printer's name.

PatTheFrog