Thought I’d post again regarding this issue, I’ve downloaded the latest version (8.2.0) and although the exception has been fixed (the cannot convert 260 or whatever integer), the print still does not occur on the correct tray.
This is a major issue for us, and we have found a possible workaround for anyone else encountering this. Essentially the code is this:
Public Class PrintHelper
Private _CurrentPage As Integer = 0
Private _ResizePercent As Single = 0.95
Private _Document As Aspose.Words.Document
Private _TrayInfo As New Dictionary(Of Integer, Integer)
Private _TotalPages As Integer
Private WithEvents _PrintDoc As PrintDocument = Nothing
Public Sub Print(ByVal aspDoc As Document, ByVal PrinterName As String, ByVal Copies As Integer)
Dim myPrintSettings As System.Drawing.Printing.PrinterSettings
'
Try
' get the current page numbers from the document.
For i As Integer = 0 To aspDoc.PageCount - 1
_TrayInfo.Add(i, aspDoc.GetPageInfo(i).PaperTray)
Next
' reset the number to known bins.
For Each sec As Section In aspDoc.Sections
sec.PageSetup.FirstPageTray = PaperTray.DefaultBin
sec.PageSetup.OtherPagesTray = PaperTray.DefaultBin
Next
aspDoc.UpdatePageLayout()
_TotalPages = aspDoc.PageCount
_Document = aspDoc
_CurrentPage = 0
' setup the print settings and print the document.
_PrintDoc = New PrintDocument
myPrintSettings = New System.Drawing.Printing.PrinterSettings
myPrintSettings.FromPage = 1
myPrintSettings.ToPage = aspDoc.PageCount
myPrintSettings.Copies = CShort(Copies)
myPrintSettings.PrinterName = PrinterName
_PrintDoc.PrinterSettings = myPrintSettings
_PrintDoc.Print()
Catch ex As Exception
Throw
Finally
If (_PrintDoc IsNot Nothing) Then
_PrintDoc.Dispose()
End If
End Try
End Sub
Private Sub Doc_QuerySettings(ByVal sender As Object, ByVal e As QueryPageSettingsEventArgs) Handles _PrintDoc.QueryPageSettings
For i As Integer = 0 To e.PageSettings.PrinterSettings.PaperSources.Count - 1
If (e.PageSettings.PrinterSettings.PaperSources(i).RawKind = TrayInfo (_CurrentPage)) Then
e.PageSettings.PaperSource = e.PageSettings.PrinterSettings.PaperSources(i)
End If
Next
' set page options.
e.PageSettings.PaperSize = _Document.GetPageInfo (_CurrentPage).GetDotNetPaperSize
e.PageSettings.PrinterSettings)
e.PageSettings.Landscape = _Document.GetPageInfo(_CurrentPage).Landscape
End Sub
Private Sub Doc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles _PrintDoc.PrintPage
Dim top As Integer
Dim left As Integer
Dim width As Integer
Dim height As Integer
' set the initial values.
width = e.PageBounds.Width
height = e.PageBounds.Height
' then resize to fit page.
width = CInt(width * _ResizePercent)
height = CInt(height * _ResizePercent)
' position image in middle.
top = CInt((e.PageBounds.Height - height) / 2)
left = CInt((e.PageBounds.Width - width) / 2)
' render the document to the printer.
_Document.RenderToSize(_CurrentPage, e.Graphics, left, top, width, height)
If (_CurrentPage < (_TotalPages - 1)) Then
e.HasMorePages = True
_CurrentPage += 1
Else
' we are at the end.
e.HasMorePages = False
End If
End Sub
End Class
We’re still testing the code (still needs some work), but so far it’s looking pretty good. Each page of the Word document will print to the specified tray, even custom trays.
So for us, on a given document, one page will go to tray 259, the other ones will go to tray 260. Both are custom trays. Using the latest version of Aspose, the document will print, but not to the correct tray (unless I’m missing something in code).
This code works (not sure about that resize either - we’re just testing that) and it is based on an example Aspose provided, but changed around quite a lot.
The biggest thing I noticed is the method on the Aspose document - RenderToSize. Basically I render the document onto the graphics using specified page and dimensions. There is another method which saves a page in the document to a stream using Aspose image options. We tried this method and cranking the DPI up to 600 and although the quality increased, it was never as good as a plain old normal Print using Aspose. Using RenderToSize however gives the same quality.