When we use Aspose to print to 2 different trays the document always comes through the tray specified as FirstPageTray.
I’m using Aspose Words v14.12 and this is the logic I have in the program:
I create a new System.Drawing.Printing.PrinterSettings object and set the PrinterName value to the printer selected by the user. I use the PaperSources property to load the trays in the dropdown lists. PaperSources is a collection of PaperSource objects. I use SourceName for the name and RawKind for the value. RawKind is the value I need to pass to select the tray to print to.
When the person clicks on Print create a new Aspose Document object with the Word document and for each section in the document I set the FirstPageTray and OtherPagesTray properties of the PageSetup property for the section to the RawKind values selected for first page and other pages.
The document is always printed through the tray selected as FirstPageTray. I tried different printers, changing the trays, and changing the order I set the trays and it doesn’t change anything, all pages are printed through the tray selected for the first page.
I’ve created a small project to demonstrate the problem, just select any word document with more than 1 page and you’ll see it failing.
Please advise what I need to do to correct this issue?!
Thanks
Hi Ross,
Thanks for your inquiry. Microsoft
Word stores printer specific values for paper trays in a Word document
and therefore, only printing on the same printer model as the one that
was selected when the user specified the paper trays will result in
printing from the correct trays. If you print a document on a different
printer, then most likely the default paper tray will be used, not the
trays specified in the document.
Following code example changes all sections in a document to use the default paper tray of the selected printer.
Document doc = new Document(MyDir + "in.docx");
// Find the printer that will be used for printing this document. In this case it is the default printer.
// You can define a specific printer using PrinterName.
System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();
// The paper tray value stored in documents is completely printer specific. This means
// The code below resets all page tray values to use the current printers default tray.
// You can enumerate PrinterSettings.PaperSources to find the other valid paper tray values of the selected printer.
foreach (Section section in doc.Sections)
{
section.PageSetup.FirstPageTray = settings.DefaultPageSettings.PaperSource.RawKind;
section.PageSetup.OtherPagesTray = settings.DefaultPageSettings.PaperSource.RawKind;
}
Hi Tahir,
I am using the same printer model as the one the user selected to specify the trays. I have also changed my code like this:
Dim PrinterName As String = lblPrinterName.Text 'printer selected by the user
Dim HeadedPaperTray As Integer = PaperSource1.RawKind 'paper source the user selected for the first page, taken from PrinterSettings.PaperSources
Dim BlankPaperTray As Integer = PaperSource2.RawKind 'paper source the user selected for other pages, taken from PrinterSettings.PaperSources
Dim ps As New System.Drawing.Printing.PrinterSettings
ps.PrinterName = PrinterName
For Each sec As Section In _Document.Sections
sec.PageSetup.FirstPageTray = HeadedPaperTray
sec.PageSetup.OtherPagesTray = BlankPaperTray
Next
_Document.Print(ps)
If I save the document before calling the Print method and then I create a new Document object with it the values in the FirstPageTray and OtherPagesTray are stored there.
The problem is still the same, all pages go through the tray specified in FirstPageTray.
Thanks,
Ross
Hi Ross,
Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.
Apologies for the delay, I was on holiday… Please find document attached
Hi Ross,
Thanks for sharing the detail. Please note that Aspose.Words print or preview document pages using the standard .NET printing infrastructure.
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 passes the value for
PaperTray to underlying Windows function that actually sends document to
printer.
You
should 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.
Please use the latest version of Aspose.Words for .NET 15.1.0. 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.docx")
' 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(1).RawKind
Next section
doc.Print(settings)
Hi Tahir,
I have updated the project to use Aspose v15.1 and tried the simple code you sent to us.
Our printer here has the following values in PaperSources:
RawKind – SourceName
15 – Automatically select
257 – Bypass Tray
258 – One Sheet Bypass Tray
259 – Tray 1
260 – Tray 2
261 – Tray 3
262 – Tray 4
I am passing 259 to FirstPageTray and 260 to OtherPagesTray as we have 2 different types of paper on those trays, and all pages were printed through Tray 1 (259). I tried the other way around, I pass 260 to FirstPageTray and 259 to OtherPagesTray and all pages were printed through Tray 2 (260).
All pages are always printed through the tray specified in FirstPageTray. It’s like Aspose is ignoring the value I set in OtherPagesTray.
Hi Tahir,
I have tried the code example in the link and it worked.
I also tried the following code using Microsoft VSTO:
Dim oWord As New Word.Application
Dim oDoc As Word.Document = oWord.Documents.Open(strPath)
Dim PrinterName As String = lblPrinterName.Text 'printer selected by the user
Dim HeadedPaperTray As Integer = PaperSource1.RawKind 'paper source the user selected for the first page, taken from PrinterSettings.PaperSources
Dim BlankPaperTray As Integer = PaperSource2.RawKind 'paper source the user selected for other pages, taken from PrinterSettings.PaperSources
Dim ps As New System.Drawing.Printing.PrinterSettings
ps.PrinterName = PrinterName
For Each sec As Word.Section In oDoc.Sections
sec.PageSetup.FirstPageTray = HeadedPaperTray
sec.PageSetup.OtherPagesTray = BlankPaperTray
Next
oDoc.PrintOut()
oDoc.Close()
And this works fine, it fails only when using Aspose.
Hi Ross,
Thanks for sharing the detail. I
have logged a Task in our issue tracking system as WORDSNET-11527 to
investigate the shared issue. I will update you about the detail of this
issue asap.
Thank you for your understanding.
Hi Ross,
Thanks for your patience. Aspose.Words supports printing as per the paper tray values stored in the document. So, you can mention paper trays in Document. Pleas check following web link.
http://word.tips.net/T003519_Selecting_Different_Trays_in_a_Mail_Merge.html
To work around this issue, please specify paper sources in your Word document. If there are multiple sections in
your document, you must specify the settings for each section of the document. Please check following web link for your kind reference.
https://support.microsoft.com/en-us/word
Hello Tahir,
I have followed the steps on the links provided. I manually changed the values to Tray 1 for first page and Tray 2 for other pages on all the sections. I then printed the document from Word and it was printed correctly.
Then I execute the app and while debugging I saw the values for FirstPageTray and OtherPageTray were already set to 259 (Tray 1) and 260 (Tray 2) accordingly, but when printing using Aspose all pages went through Tray 1.
And finally I tried printing again, this time setting the values even though they were already there and also all pages went through Tray 1.
Thanks,
Hi Ross,
Thanks
for sharing the detail. Unfortunately, I have not printer with multiple trays at my side to test this scenario. We need your cooperation to check this scenario.
- Please set the tray’s value manually using MS Word.
- Please use latest version of Aspose.Words for .NET 15.2.0.
- Please test this scenario at some different Systems.
- Please create a separate application and execute following code example and share what is the output of FirstPageTray and OtherPagesTray.
Document doc = new Document(MyDir + "DocPrint.docx");
foreach (Section section in doc.Sections)
{
Console.WriteLine("section.PageSetup.FirstPageTray : " + section.PageSetup.FirstPageTray);
Console.WriteLine("section.PageSetup.OtherPagesTray : " + section.PageSetup.OtherPagesTray);
}
doc.Print();
As I shared earlier, Aspose.Words print or preview
document pages using the standard .NET printing infrastructure.So, it should not be an issue with Aspose.Words. Thanks for your cooperation.
Hello Tahir,
I installed the latest Aspose update and set the trays manually in the Word document. Then executed the code and it didn’t work. This is the console output:
section.PageSetup.FirstPageTray : 259
section.PageSetup.OtherPagesTray : 260
section.PageSetup.FirstPageTray : 259
section.PageSetup.OtherPagesTray : 260
section.PageSetup.FirstPageTray : 259
section.PageSetup.OtherPagesTray : 260
I then copied everything to a different machine. I opened the Word document and check the trays were still selected. Then executed the app and it still didn’t work.
Hi Ross,
Thanks
for your feedback. Please spare us some time for the investigation of this issue. We will get back to you as soon as possible.
Hi Ross,
Thanks
for your patience. Please use the values of firstPageTray and otherPagesTray of your printer in following code example and share the results here for our reference. Please find the SimplePrintDocument class in attachment.
SimplePrintDocument printDocument = new SimplePrintDocument(firstPageTray, otherPagesTray);
printDocument.Print();