Hi
We are currently experiencing issues where a document (can be a blank document) prints to the wrong tray. This is only happening when we print to tray 4 of a printer but happens on several printers.
Example:
Printing a batch of documents where you send a document to each tray of a 4 tray printer (tray 1 is a manual feed). All documents sent to tray 1, 2 and 3 are printed as expected. The document that is sent to tray 4 is printed but comes from tray 1.
Version: 2013.08.31 / 13.8.0.0
Code:
-----------------------------------------------------------------------------------
Dim awPrintDoc As New AsposeWordsPrintDocument(awDoc)
awPrintDoc.PrinterSettings.PrinterName = strPrintername
Dim s As PaperSource = _wordUtilHelper.GetInputTray(awPrintDoc, printerTray)
awPrintDoc.PrinterSettings.DefaultPageSettings.PaperSource = s
awPrintDoc.PrinterSettings.Duplex = Duplex.Simplex
' force the page tray
For Each sec As Section In awDoc.Sections
sec.PageSetup.FirstPageTray = s.RawKind
sec.PageSetup.OtherPagesTray = s.RawKind
Next
' setting up simple of duplex printing
If awPrintDoc.PrinterSettings.CanDuplex Then
SetDuplexPrinting(awPrintDoc, documentType, objCertificate)
End If
awPrintDoc.Print()
Hi Adam,
Thanks for your inquiry. Please note that Aspose.Words reads values from document in Raw format (i.e. as int) and after Print method is called, a function compares the Raw value of PaperTray of current page and values in PrinterSettings.PaperSources and if it doesn’t find coincidence, function returns “Automatic” value. Then it pass value for PaperTray to underlying Windows function that actually sends document to printer.
Also, note that paper tray numbers are printer specific. I suppose the problem might occur because paper trays numbers specified in your document do not match paper tray numbers of the printer running on your local environment. So, first of all you should make sure that paper trays in your document are specified correctly.
Could you please run the following code to determine whether a tray with number 4 actually exists in your printer?
Dim Settings As PrinterSettings = New
PrinterSettings()
Settings.PrinterName = "name of your multi-tray printer"
For Each ps As PaperSource In Settings.PaperSources
Console.WriteLine(ps.RawKind)
Next
Best regards,
Hi Awais
Below is the function that returns the correct paper source for the document. In this function we lookup the installed printer and find the paper source based on the name .e.g Tray 4. This way we definitely know that the tray exists and later use the rawkind for that tray on the document.
I added some logging to our code to lets us track what printer and tray is being used and every time the correct rawkind is returned (in our case 262 - Tray 4). We add printers to our software for the user to use which means that they can only ever add printers that have been installed on their machines. By doing this we know that the printer and tray definitely exist before sending the document.
'''
''' Gets the printer input tray associated with a document.
'''
'''
'''
'''
'''
Public Function GetInputTray(ByVal MyPrintDocument As AsposeWordsPrintDocument,
ByVal PrinterTrayName As String) As PaperSource
Try
Dim myPageSettings As PageSettings = MyPrintDocument.DefaultPageSettings
Dim myPrinterSettings As PrinterSettings = myPageSettings.PrinterSettings
' Fix printer case
For Each printerName As String In PrinterSettings.InstalledPrinters
If printerName.ToLower().Trim() = MyPrintDocument.PrinterSettings.PrinterName.ToLower().Trim() Then
MyPrintDocument.PrinterSettings.PrinterName = printerName
Exit For
End If
Next
Dim s As PaperSource = Nothing
For Each source As PaperSource In myPrinterSettings.PaperSources
If source.SourceName.Trim().ToLower() = PrinterTrayName.Trim().ToLower() Then
s = source
Exit For
End If
Next
Return s
Catch ex As Exception
DSSLErrorLog.GeneralExceptionHandler(ex, "Unable to get input tray for document. Printer tray name: " &
PrinterTrayName & ", (DSSLWordUtils.GetInputTray). ")
End Try
Return Nothing
End Function
Hi Adam,
Thanks for the additional information. I would suggest you please upgrade to the latest version of Aspose.Words 14.5.0. You can download it from the following link. I hope, this helps:
https://releases.aspose.com/words/net
Also, please try executing the following simple code and see how it goes on your end?
' Load document
Dim doc As New Document(MyDir & "in.doc")
' Choose the printer to be used for printing this document.
Dim settings As New System.Drawing.Printing.PrinterSettings()
settings.PrinterName = "PrinterName"
' Set the page tray which will be used for each section
For Each section As Section In doc.Sections
' Specify the correct index of PaperSource whose RawKind value is 262
section.PageSetup.FirstPageTray = settings.PaperSources(0).RawKind
section.PageSetup.OtherPagesTray = settings.PaperSources(0).RawKind
Next section
doc.Print(settings)
Best regards,
Hi
I have just tried your example in a separate project and get the same result. Tray 4 still prints to tray 1.
I have also attached the test project so you can try this yourself to see if you can replicate the issue. (you will need to reference the aspose libraries as I have removed them so I could attach the archive to the post).
The project will allow you to select an installed printer and send a test document to each tray. The document will say what tray it is expecting to come out of. You will need to mark the paper in each tray so you can check that the document has come out of the correct tray.
We currently have tray 1 (manual feed) set to any size and any paper type which lets us replicate the issue that our customers are experiencing. However they have all of their trays set to plain and a4. If we do the same thing for all of our trays then the document is printed out of the correct tray.
Edit: I have now found that it is always the last tray in the stack that gets sent to tray 1. We have added another tray (Tray 5) and now tray 4 is ok but tray 5 goes to tray 1.
Hi Adam,
Thanks for the additional information and it is great that you managed to workaround this problem on your end. There should not be any problem as Aspose.Words correctly sets values of PageSetup.FirstPageTray and PageSetup.OtherPagesTray properties. Please let me know if I can be of any further assistance.
Best regards,
Hi
We have found the actual issue and have had to remove the call to UpdateFields. When using UpdateFields something happens to the word document to make it no longer go to the correct tray.
If we loop through the sections and only update the fields in the document we get the same issue.
Do you know what we can do to update Date fields within the word document and it not affect printing to the correct tray?
Hi Adam,
Thanks for your inquiry. You can try updating the DATE fields separately by using the following code:
For Each field As Field In doc.Range.Fields
If field.Type = FieldType.FieldDate Then
field.Update()
End If
Next
Please let me know if I can be of any further assistance.
Best regards,