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.

Sun Jun 03, 2018 5:01 pm

Hi,
I have a Pdf file and I need to print the first page from tray 1 and the rest from tray 2 on the same printer.
How can I do that when I use Spire.PDF and vb.net?

I can loop back into the routine and reprint the other pages, but struggling to understand how to select the tray. I’ve had a look at your sample code, but it’s in C#


The code I have at the moment is;

Dim doc As PdfDocument = New PdfDocument()
doc.LoadFromFile("PrintP1.pdf")

doc.PrintFromPage = 1
doc.PrintToPage = doc.Pages.Count

doc.PrintDocument.Print()


Thank you in advance
Stewart

mabonst
 
Posts: 3
Joined: Wed May 16, 2018 8:15 pm

Mon Jun 04, 2018 3:21 am

Dear Stewart,

Thanks for your inquiry.
Please use the event PaperSettings to select the tray when printing. Here is VB.NET code for your kind reference:
Code: Select all
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim doc As PdfDocument = New PdfDocument
        doc.LoadFromFile("F:\sample.pdf")
        'use the event PaperSettings to set the many trays
        AddHandler doc.PrintSettings.PaperSettings, AddressOf PageSettings
        doc.Print()
    End Sub
    Private Sub PageSettings(ByVal sender As Object, ByVal e As PdfPaperSettingsEventArgs)
        'Set the paper source of page 1 as tray 1
        If ((1 >= e.CurrentPaper)) Then
            e.CurrentPaperSource = e.PaperSources(0)
        Else
            'Set the paper source of the rest of pages as tray
            e.CurrentPaperSource = e.PaperSources(1)
        End If     
    End Sub

Any question, just feel free to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Jun 04, 2018 7:44 pm

Hi,
Thanks for the quick response, but unfortunately, I still can’t get this to work. The first error I getting is that “‘PrintSettings’ is not a member of ‘Spire.Pdf.PdfDocument’” I also get the error that “‘Print’ is not a member of ‘Spire.Pdf.PdfDocument’” and the third one is in the sub PageSettings where I get the message “Type ‘PdfPaperSettingsEventArgs’ is not defined”

mabonst
 
Posts: 3
Joined: Wed May 16, 2018 8:15 pm

Tue Jun 05, 2018 2:11 am

Dear Stewart,

Thanks for your reply.
You should be using an old version which doesn't has that function. Please download the latest Spire.PDF Pack(Hot Fix) Version:4.5.8 and try again.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Jun 05, 2018 9:12 am

Applied the hotfix, and that got rid of two of the errors, still left with the “Type ‘PdfPaperSettingsEventArgs’ is not defined” message. Thanks for your patience

mabonst
 
Posts: 3
Joined: Wed May 16, 2018 8:15 pm

Tue Jun 05, 2018 9:38 am

Dear Stewart,

Thanks for your reply.
Please add the code "Imports Spire.Pdf.Print" at the top of your project. Below are all references for you kind reference:
Code: Select all
Imports Spire.Pdf
Imports Spire.Pdf.Print

Any question, welcome to write back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jun 08, 2018 9:18 am

Dear Stewart,

Greetings from E-iceblue.
How is your issue going now ? Could you please give us some feedback at your convenience ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue May 25, 2021 7:06 pm

I'm using the version 7.5.7 from nuget but it is unable to recognize 'PrintSettings' and 'PdfPaperSettingsEventArgs'.

doc.PrintSettings.PaperSettings += delegate (object sender, PdfPaperSettingsEventArgs e)

ckarthik7
 
Posts: 2
Joined: Tue May 25, 2021 6:01 pm

Wed May 26, 2021 5:58 am

ckarthik7 wrote:I'm using the version 7.5.7 from nuget but it is unable to recognize 'PrintSettings' and 'PdfPaperSettingsEventArgs'.

doc.PrintSettings.PaperSettings += delegate (object sender, PdfPaperSettingsEventArgs e)

Hello,

Thanks for your inquiry.

Your project target framework is .NET Core, right? Please kindly note that if you install our Spire.PDF from NuGet, it will use the .NETStandard dlls by default. Sorry that our .NETStandard dlls do not support printing at present.

To use the printing function, please install the package (Spire.PDF.NETCore 7.5.7·) via NuGet to use our .NETCore dlls. Feel free to contact us if you have further questions.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Jun 01, 2021 2:32 pm

Is there a way to add the printer tray settings without using the PrintSettings, for e.g if this has to run on a cloud environment were there are no printers added to the server executing this code.

ckarthik7
 
Posts: 2
Joined: Tue May 25, 2021 6:01 pm

Wed Jun 02, 2021 6:21 am

ckarthik7 wrote:Is there a way to add the printer tray settings without using the PrintSettings, for e.g if this has to run on a cloud environment were there are no printers added to the server executing this code.

Hello,

Thanks for your reply.
Sorry, our Spire.PDF currently does not support this feature. If you need to add the printer tray settings, you must use the PrintSetting.
If you have any other questions, please feel free to contact us.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.PDF