默认生成的 XPS 文件的名称的方法? [英] Way to default the name of the generated XPS file?

查看:78
本文介绍了默认生成的 XPS 文件的名称的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户打印报告,并且他们碰巧使用的是 Microsoft XPS 打印机,我希望文件名默认为有意义的名称.

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.

我本以为 XPS 打印机会采用打印作业的名称,并将其用作默认文件名 - 但事实并非如此.

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.

当我打印到该打印机时,是否有其他一些编程方式来默认生成的 XPS 文件的名称?我在想可能是这样的:

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:

  • 一个注册表项
  • 全局共享内存
  • API 调用,如 SetDefaultXPSFilename()
  • 关于打印作业的扩展属性

自动化 Excel 以创建电子表格:

Automate Excel to create a spreadsheet:

Excel xl = new ExcelApplication();
Workbook wb = xl.Workbooks.Add();
GenerateReport(wb);
wb.PrintOut();

现在如果用户的默认打印机是Microsoft XPS Document Writer,那么用户将得到:

Now if the user's default printer is the Microsoft XPS Document Writer, then the user will get:

我想要一种将文件名默认为有用的东西的方法,例如:

i would like a way for that File name to be defaulted to something useful, such as:

20110729 - Chip Bank Settlement Sheet.xps

用户将接受默认文件名,文件将自动组织,而不是用户输入:

The user will accept the default filename, and files will organized automatically, rather than the user typing:

asdfadf.xps

<小时>

参考文献

  • eggheadcafe:XPS 默认文件名
  • MSDN:XPS发送到打印机时的名称
  • 撞击:20110729(12 个月后)

    推荐答案

    嗯,这是一个简单的方法(至少在我的情况下):

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

    (myPrintPage 继承自 System.Drawing.Printing.PrintDocument)

    (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:

    假设我的默认打印机不是 XPS Document Writer.我的代码需要自动存档一些数据,在 XPS 中打印报告,然后让用户在默认打印机上打印报告.在第二步中,我需要更改 myPrintPage 的 PrinterSettings.
    方法如下:

    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.

    这篇关于默认生成的 XPS 文件的名称的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆