We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Print word document to a specific tray

Hi



I’m trying to print a document to a specific tray but it’s not working.



Here’s a sample code:



AsposeWordsPrintDocument awpDoc = new AsposeWordsPrintDocument(doc);

awpDoc.QueryPageSettings += new System.Drawing.Printing.QueryPageSettingsEventHandler(awpDoc_QueryPageSettings);

awpDoc.PrinterSettings.PrinterName = @"\HP-4515n";



void awpDoc_QueryPageSettings(object sender, QueryPageSettingsEventArgs e)

{

var newPS = new PaperSource();

var oldPS = e.PageSettings.PaperSource;

newPS.SourceName = oldPS.SourceName;

newPS.RawKind = 261;

e.PageSettings.PaperSource = newPS;

}



I’ve also tried setting the FirstPageTray and OtherPagesTray.



foreach (Section section in doc.Sections)

{

section.PageSetup.FirstPageTray = 261;

section.PageSetup.OtherPagesTray = 261;

}

Hi Prestige,


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.

In Microsoft Word printer trays are defined per section and are printer specific. Therefore you can programtically change these values by using the FirstPageTray and OtherPagesTray properties of the PageSetup class for each section.

Please let me know if I can be of any further assistance.