Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jul 25, 2016 8:33 pm

I have a document that when I print it needs to go to 2 different trays. I need to print the entire document from both trays.
When I try to add 2 trays it only prints to the one tray. I have tried to print twice using the following code and I still only get the first tray to print.

For ind = 0 To 6
If trays(ind) > 0 Then
Dim tray As New PdfPaperSourceTray()
tray.StartPage = 0
tray.EndPage = doc.Pages.Count
tray.PrintPaperSource = collections(ind)
loPaperSources.Add(tray)
doc.PrintDocument.PrinterSettings.Copies = trays(ind)
Dim printDoc As PrintDocument = doc.PrintDocument
dialogPrint.Document = printDoc
printDoc.Print()
loPaperSources.Clear()
End If
Next

[email protected]
 
Posts: 5
Joined: Fri Jul 22, 2016 3:02 pm

Tue Jul 26, 2016 3:15 am

Hi,

Thanks for your inquiry.
From the codes you provided, I found there is only one tray, if you want to print in two trays, you need to create another tray.
Here is sample code for your reference.
Code: Select all
                    PdfPaperSourceTray tray = new PdfPaperSourceTray();
                    tray.StartPage = 0;
                    tray.EndPage = 1;
                    tray.PrintPaperSource = collections[2];
                    loPaperSources.Add(tray);
                    PdfPaperSourceTray tray1 = new PdfPaperSourceTray();
                    tray1.StartPage = 2;
                    tray1.EndPage = 3;
                    tray1.PrintPaperSource = collections[3];
                    loPaperSources.Add(tray1);

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Jul 26, 2016 1:45 pm

Your example expects that I will print a 4 page document 2 pages to 1 tray and 2 pages to another.

With my code when I debug it I see the 2 trays in the array I don't see the name anywhere so i don't see the point of creating 2 separate trays.

I will however try your suggestion. I have also tried to print the document 2 separate times but it comes out blank the second time. Is there a limitation in the trial that only allows a document to be printed once per process.

[email protected]
 
Posts: 5
Joined: Fri Jul 22, 2016 3:02 pm

Tue Jul 26, 2016 2:02 pm

I just ran your sample code and I get 1 copy and it prints to the second tray.

I have also included a screen shot of the tray config from the debugger.


Spirepdf.jpg

[email protected]
 
Posts: 5
Joined: Fri Jul 22, 2016 3:02 pm

Tue Jul 26, 2016 7:41 pm

Since I wanted to print the same document multiple times I am using the Printdoc settings and not using the tray config from Spire.

In my case I have an array with 7 trays and the page quantity in the array value. Nice neat and simple gets the job done. Note that I reload the doc from byte stream since it clears after printing.

Dim Collections As PrinterSettings.PaperSourceCollection = doc.PrintDocument.PrinterSettings.PaperSources
Dim loPaperSources As New List(Of PdfPaperSourceTray)()

For ind = 0 To 6
If trays(ind) > 0 Then

doc.PrintDocument.PrinterSettings.Copies = trays(ind)
Dim printDoc As PrintDocument = doc.PrintDocument
dialogPrint.Document = printDoc
printDoc.DefaultPageSettings.PaperSource = printDoc.PrinterSettings.PaperSources(ind)

printDoc.Print()
loPaperSources.Clear()
doc.LoadFromBytes(bytes)
End If
Next

End Sub

[email protected]
 
Posts: 5
Joined: Fri Jul 22, 2016 3:02 pm

Wed Jul 27, 2016 6:17 am

Hi,

Thanks for your feedback.
Welcome to write to us again for further question.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF

cron