We’re replacing our word-automation with Aspose.
Generating documents seems to work fine, but printing to a printer with tray selections doesn’t seem to work.
The linked issue above seems to conclude that saving to XPS does not include the tray-/bin-information in the printticket.
While Preserve paper tray information when rendering to/printing via XPS says it should work.
We are using the dotnet 20.2 version of Aspose.
These are the steps we use now:
generate a Word document, set the PageSetup.FirstPageTray and OtherPagesTray for all sections to the desired tray
save the word document
– check the paperSrc in the docx and see the correct tray (262 in this specific case)
supply the word document to a .exe based on your example XpsPrintHelper from Printing a Document in C#|Aspose.Words for .NET
– debugging learns that pageInfo.PaperTray, section.PageSetup.FirstPageTray and OtherPagesTray all contain the expected tray
sadly the document is printed from the default tray
in XpsPrintHelper the document is saved to a stream as XPS: document.Save(stream, Aspose.Words.SaveFormat.Xps);.
When saving to a file and checking the psk:JobInputBin shows a value of psk:AutoSelect.
To convert a Word document to XPS and print it while ensuring that the printer uses the correct tray settings, you can follow these steps:
Generate the Word Document: Make sure to set the PageSetup.FirstPageTray and OtherPagesTray properties for all sections in your Word document to specify the desired tray.
Save the Document: After setting the tray properties, save the Word document. You can verify that the paperSrc in the DOCX file reflects the correct tray settings.
Use XpsPrintHelper: When printing, utilize the XpsPrintHelper class to send the document to the printer. This class allows you to print the document directly from a stream after converting it to XPS format.
Here is a code snippet demonstrating how to implement this:
using Aspose.Words;
using Aspose.Words.Rendering;
public void PrintDocument(string filePath, string printerName)
{
// Load the document
Document document = new Document(filePath);
// Set the tray settings
foreach (Section section in document.Sections)
{
section.PageSetup.FirstPageTray = 262; // Set to your desired tray
section.PageSetup.OtherPagesTray = 262; // Set to your desired tray
}
// Save the document to a stream in XPS format
using (MemoryStream stream = new MemoryStream())
{
document.Save(stream, SaveFormat.Xps);
stream.Position = 0; // Reset stream position
// Print the document using XpsPrintHelper
XpsPrintHelper.Print(stream, printerName, "My Test Job", true);
}
}
Important Notes:
Ensure that the printer you are targeting supports the specified tray settings.
The XpsPrintHelper class is designed to handle the printing process, but you may need to verify that the printer driver is correctly installed and configured to recognize the tray settings.
If you encounter issues where the document prints from the default tray, it may be necessary to check the printer’s configuration or the print ticket settings being used.
For further details, you may want to refer to the documentation on printing with Aspose.Words and the specific examples provided in the Aspose GitHub repository.
If you continue to experience difficulties, consider checking related forum discussions for additional insights or solutions.
@brm Only few default paper trays are available in public and others are private, custom namespace must be declared for them to use them in XPS print ticket. We have an issue (WORDSNET-12229) for this in our defect tracking system. I linked your request to the appropriate issue. We will keep you updated and let you know once it is resolved.