如何双面和装订打印作业 [英] How to duplex and staple a print job
问题描述
我想从 Excel 打印到 Postscript,然后打印到打印机.如何在将打印作业发送到打印机之前指定双面和装订.
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.
我一直在查看 PrintTicket 类.看起来很有希望.但我在 .net 3.5 中使用 WinForms 项目.
I've been looking at the PrintTicket class. It looks promising. But I'm using WinForms project with .net 3.5.
如果不是必须的话,我真的不想设置多个打印队列.那么如何控制双面打印和装订选项?
I really don't want to set up multiple print queues if I don't have to. So how do I control the duplex and staple options?
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
推荐答案
您可以使用 PrintQueue.AddJob 将文件添加到打印队列的方法.但它只接受 XPS 文件.然后你可以使用 PrintTicket 类来指定双工和/或装订.不要使用 Postscript,而是打印到 XPS 并使用它添加作业.
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
然后,如果您需要 PDF,您可以使用 GhostXPS 将 XPS 转换为 PDF.不幸的是,无法添加书签 同时当前.但这可能会在未来解决.
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.
这篇关于如何双面和装订打印作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!