Way to default the name of the generated XPS file?

后端 未结 3 2039
遇见更好的自我
遇见更好的自我 2021-02-20 13:53

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

相关标签:
3条回答
  • 2021-02-20 14:45

    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.

    0 讨论(0)
  • 2021-02-20 14:50

    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.

    0 讨论(0)
  • 2021-02-20 14:53

    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.

    In addition to above, here is a piece of code I found useful:

    Let's say that my default printer is NOT the XPS Document Writer. My code needs to archive automatically some data, print a report in XPS, then offer the user to print the report on the default printer. In the second step, I need to change the PrinterSettings of myPrintPage.
    Here is how:

      'save xps results
        'is the XPS printer installed?
        Dim myXPSfound As Boolean = False
        For Each s As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            If s.Contains("XPS") Then
                myXPSfound = True
                Exit For
            End If
        Next
        If myXPSfound Then
            'Manual settings of the XPS printerSettings
            Dim myXPSPrinterSettings As New Drawing.Printing.PrinterSettings
            myXPSPrinterSettings.Collate = False
            myXPSPrinterSettings.Copies = 1
            myXPSPrinterSettings.Duplex = Drawing.Printing.Duplex.Simplex
            myXPSPrinterSettings.FromPage = 0
            myXPSPrinterSettings.MaximumPage = 9999
            myXPSPrinterSettings.MinimumPage = 0
            myXPSPrinterSettings.PrinterName = "Microsoft XPS Document Writer"
            myXPSPrinterSettings.PrintRange = Drawing.Printing.PrintRange.AllPages
            myXPSPrinterSettings.PrintToFile = True
            myXPSPrinterSettings.ToPage = 1
    
            myPrintPage.PrinterSettings = myXPSPrinterSettings
            myPrintPage.PrinterSettings.PrintToFile = True
            myPrintPage.PrinterSettings.PrintFileName = mytargetFileName & ".xps"
            Try
                myPrintPage.Print()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Information, "Error Printing the XPS File")
            End Try
        Else
            MsgBox("The Microsoft XPS Writer was no found on this computer", MsgBoxStyle.Information, "Error Printing the XPS File")
        End If
    


    It can be handy sometimes.

    0 讨论(0)
提交回复
热议问题