How to duplex and staple a print job

后端 未结 1 1943
攒了一身酷
攒了一身酷 2020-12-12 03:39

I want to print from Excel to Postscript then print to a printer. How can I specify duplex and staple before sending the print job to the printer.

I\'ve been looking

相关标签:
1条回答
  • 2020-12-12 03:58

    You can use PrintQueue.AddJob Method to add a file to the print queue. But it only accepts XPS documents. Then you can use PrintTicket class to specify duplex and/or stapling. Instead of using Postscript, print to XPS and add a job with that.

    Public Shared Function PrintSheetsToXPS(ByVal wb As Excel.Workbook, _
                                           ByVal arr As Array, _
                                           ByVal XPSFileName As String) As String
    
        Dim svInputPS As String = TempPath & XPSFileName
        IO.File.Delete (svInputPS)
        wb.Worksheets(arr).PrintOut(PrintToFile:=True, _
                          PrToFileName:=svInputPS, _
                          ActivePrinter:="Microsoft XPS Document Writer")
    
        Return svInputPS
    
    End Function
    
    Sub demoDuplexStaple(ByVal XPSFileName As String)
        'Imports SysPrint = System.Printing
        'need to reference ReachFramework
        Dim PrintServer As New SysPrint.PrintServer("\\" & My.Computer.Name)
        Dim PrintQ As New SysPrint.PrintQueue(PrintServer, "Ricoh Main")
        Dim Jobs As SysPrint.PrintJobInfoCollection = PrintQ.GetPrintJobInfoCollection
        Dim able As SysPrint.PrintCapabilities = PrintQ.GetPrintCapabilities()
    
        'get the current PrintTicket
        Dim CurrentTicket As SysPrint.PrintTicket _
                = PrintQ.CurrentJobSettings.CurrentPrintTicket
    
        'modify to staple and duplex
        CurrentTicket.Stapling = Printing.Stapling.StapleTopLeft
        CurrentTicket.Duplexing = Printing.Duplexing.TwoSidedLongEdge
    
        'add the XPS file to the print queue to print
        Dim TestJob As SysPrint.PrintSystemJobInfo _
                = PrintQ.AddJob("Test job", XPSFileName, False)
    
    End Sub
    

    Then if you need a PDF you can convert XPS to PDF using GhostXPS. Unfortunately there's no way to add bookmarks at the same time currently. But that may be addressed in the future.

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