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

Free Support Forum - aspose.com

Tray printing question

Hi there,

We’re using your product (v and have hit a bit of a snag. I’ve got this document printing to a Hewlett Packard 5500 LaserJet printer. In the document, I’ve setup the first page to print to tray 1 and all other pages to print to tray 3 (see image1). I print this from Word and the print works as expected.

An interesting note is when I close the document, reopen in Word and then change the printer (before hit the OK to print) is that the settings become stuffed up (see image2). The trays are now both on tray 1 (with one being the manual).

When I have stepped through the code, the page setup for the first section is:
OtherPagesTray = 261
FirstPageTray = 259

I created a script in Word to get the names and numbers of the trays - and this matches up - those values are what Word thinks are the trays (and also what the PaperSources are in the PrinterSettings class) for this printer.

So everything looks correct as far as I can see with the tray values, so I’m just wondering if anyone else has come across this before?

The code I’m using to print is this:

Public Function PrintDocument(ByVal Path As String, ByVal Printer As String, ByVal Copies As Integer, ByVal DeleteFile As Boolean) As Boolean

Dim aspDoc As Aspose.Words.Document = Nothing
Dim awPrintDoc As Aspose.Words.Rendering.AsposeWordsPrintDocument = Nothing
Dim myPrintSettings As System.Drawing.Printing.PrinterSettings
' create instances.
myPrintSettings = New System.Drawing.Printing.PrinterSettings
aspDoc = New Aspose.Words.Document(Path)

' setup the print settings and print the document.
awPrintDoc = New AsposeWordsPrintDocument(aspDoc)
myPrintSettings.FromPage = 1
myPrintSettings.ToPage = aspDoc.PageCount
myPrintSettings.Copies = CShort(Copies)
myPrintSettings.PrinterName = Printer
awPrintDoc.PrinterSettings = myPrintSettings

' do we delete?
If (DeleteFile) Then
Catch ex As Exception
' ignore exceptions on this.
End Try
End If

Return True

Catch ex As Exception
Return False

If (awPrintDoc IsNot Nothing) Then
End If
End Try
End Function

I haven’t gone as far as to override the entire print process yet, but I’m not entirely sure this will fix this problem. We have got a workaround at the moment (setup the printer to only print from a certain tray) - works, but not the ideal solution.

And I may have overlooked something simple as, so any help would be much appreciated.


Just thought I’d add some quick info to this - when I print to a printer that only has 2 trays - the bin/tray printing works normally - it only seems to be when I print to a printer that has more than the standard trays.


Thanks for your request. It seems the problem occurs, because only standard trays can be used (trays from PaperTray enum). We will further investigate the problem and let you know as soon as the issue is resolved.

Best regards.

Awesome - cheers for that.

Depending on which location we have this installed is how important this is - some places don’t have printers with more than two trays, other’s do (and causes them issues). The workaround does work, but it would be awesome to see this functionality in place.

Great work with the update from 6.5 to 6.6 by the way - saw heaps of improvements!

Hey again - I’ve just downloaded version 7 and this issue with printing still seems to be there. Just checking to see if I’m doing something wrong (still the same code as above) or if this is a real tricky problem and will be in an upcoming release.

Hi Tyron,

Thanks for your inquiry. Unfortunately, the issue is still unresolved. We will let you know once it is fixed.

Best regards.

Hey again, just keeping this post alive basically and seeing if this printing issue/feature has been implemented yet. If not, do you know of any workaround?


Thanks for your inquiry. The original issue is unresolved yet.

Maybe as a workaround, you can try converting your document to images and then use PrintDocuemnt class to print these images. For instance, see the following code:

public void Test001()
    Document doc = new Document(@"Test001\in.doc");

private class PrintHelper
    private PrintHelper(Image image, PaperTray tray)
        mImage = image;
        mTray = PaperTrayToInt(tray);

    public static void Print(Document doc)
        // Print each page in the document using PrintDocument class.
        for (int i = 0; i < doc.PageCount; i++)
            using (MemoryStream imageStream = new MemoryStream())
                doc.SaveToImage(i, 1, imageStream, ImageFormat.Jpeg, null);
                using (Image image = Image.FromStream(imageStream))
                    PrintHelper helper = new PrintHelper(image, doc.GetPageInfo(i).PaperTray);
                    PrintDocument printDoc = new PrintDocument();
                    printDoc.PrinterSettings.PrinterName = @"\\\hp LaserJet 1010 Series Driver";
                    printDoc.PrintPage += helper.Doc_PrintPage;

    // Converts PaperTary to int.
    private static int PaperTrayToInt(PaperTray tray)
        switch (tray)
            case PaperTray.AutomaticSheetFeed:
                return (int)PaperSourceKind.AutomaticFeed;
            case PaperTray.PaperCassette:
                return (int)PaperSourceKind.Cassette;
            case PaperTray.EnvelopeFeed:
                return (int)PaperSourceKind.Envelope;
            case PaperTray.FormSource:
                return (int)PaperSourceKind.FormSource;
            case PaperTray.LargeCapacityBin:
                return (int)PaperSourceKind.LargeCapacity;
            case PaperTray.LargeFormatBin:
                return (int)PaperSourceKind.LargeFormat;
            case PaperTray.LowerBin:
                return (int)PaperSourceKind.Lower;
            case PaperTray.ManualFeed:
                return (int)PaperSourceKind.Manual;
            case PaperTray.ManualEnvelopeFeed:
                return (int)PaperSourceKind.ManualFeed;
            case PaperTray.MiddleBin:
                return (int)PaperSourceKind.Middle;
            case PaperTray.SmallFormatBin:
                return (int)PaperSourceKind.SmallFormat;
            case PaperTray.TractorFeed:
                return (int)PaperSourceKind.TractorFeed;
            case PaperTray.UpperBin:
                return (int)PaperSourceKind.Upper;
                return (int)tray;

    private void Doc_PrintPage(object sender, PrintPageEventArgs e)
        e.PageSettings.PaperSource.RawKind = mTray;
        e.Graphics.DrawImage(mImage, 0, 0);

    private readonly Image mImage;
    private readonly int mTray;

I do not have printer with multiple trays on my side, so I haven’t got a chance to test this code with multiple trays. Please let me know how it goes on your side.

Best regards.

Thanks for the reply, tried that with code like this:

Dim doc As New Document("C:\in.doc")
Dim imageStream As New MemoryStream()
doc.SaveToImage(0, 1, imageStream, ImageFormat.Jpeg, Nothing)

Running this code with the attached document results in this error:

  • InvalidOperationException, Cannot convert ‘260’

Obviously code missing above, but this will re-create the exception.

I’m pretty sure this is related to printer trays - only happens on Tray 2 or 3. On other documents, I also get other integer values such as "Cannot convert ‘292’).

Totally not meaning to double post, but also put some notes on this post as well:

Kinda related I guess, looking forward to full tray support!


Thanks for your request. I already answered this question in the following thread:

Best regards,

The issues you have found earlier (filed as 10223) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.