Reputation: 5901
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 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
Upvotes: 1
Views: 1869
Reputation: 5901
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.
Upvotes: 2