2015-10-20 161 views
1

我想从Excel打印到Postscript然后打印到打印机。如何在将打印作业发送到打印机之前指定双面打印和装订。如何双面打印并装订打印作业

我一直在看PrintTicket class。看起来很有希望。但是,我正在使用.net 3.5的WinForms项目。

如果我不需要,我真的不想设置多个打印队列。那么我如何控制双面和主要选项?

Public Shared Function PrintSheetsToPS(ByVal wb As Excel.Workbook, _ 
             ByVal arr As Array, _ 
             ByVal PSFileName As String) As String 

    Dim svInputPS As String = TempPath & PSFileName 
    IO.File.Delete (svInputPS) 
    wb.Worksheets(arr).PrintOut(PrintToFile:=True, _ 
            PrToFileName:=svInputPS, _ 
            ActivePrinter:=PSPrinterName) 

    Return svInputPS 

End Function 

回答

2

您可以使用PrintQueue.AddJob方法将文件添加到打印队列。但它只接受XPS文件。然后,您可以使用PrintTicket类指定双面打印和/或装订。而不是使用Postscript,打印到XPS并添加一个作业。

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 

然后,如果你需要一个PDF您可以使用GhostXPS XPS转换为PDF。不幸的是,目前有no way to add bookmarks。但是,未来可能会有addressed