Skip to main content

Documentation

Version: 4.0

Printing Page Ranges

When printing, you are not limited to printing an entire PDF document. You can also print a specific page range by selecting only the pages you want included in the print job. This can be accomplished either by using one of the overloaded constructors of the PrintJob class or by specifying a page range when adding pages to a print job.

PrintJob Constructor​

The PrintJob class provides overloaded constructors that allow printing only a specified page range from a PDF document. These constructors accept startPage and pageCount integer parameters, which define the starting page and the number of pages to include in the print job.

PrintJob printJob = new PrintJob(Printer.Default,pdfPath, 1, 3);
printJob.Print();
Dim printJob As New PrintJob(Printer.Default, pdfPath, 1, 3)
printJob.Print()

[PageRangeExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/PageRangeExample.cs){#gitlink-id target=_blank}


[PageRangeExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/PageRangeExample.vb){#gitlink-id target=_blank}

PrintJobPage​

The Pages property is an PrintJobPageList that contains an Add method that allows adding only the pages in a page range from a PDF.

public void Add(InputPdf pdf, int startPage, int pageCount)
Sub Add(pdf As InputPdf, startPage As Integer, pageCount As Integer)

In this example, you add a range of pages from different PDFs to a print job. When printing the PDF, the output for the first job is pages one through three, the second job pages three and four, and the third job pages two through five.

PrintJob printJob = new PrintJob(Printer.Default);
printJob.Pages.Add(pdfFilePath, 1, 3);
printJob.Pages.Add(pdfFilePath, 3, 2);
printJob.Pages.Add(pdfFilePath, 2, 4);
printJob.Print();
Dim printjob As PrintJob = New PrintJob(Printer.Default)
printJob.Pages.Add(pdfFilePath, 1, 3)
printjob.Pages.Add(pdfFilePath, 3, 2)
printjob.Pages.Add(pdfFilePath, 2, 4)
printjob.Print()

[PageRangeExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/PageRangeExample.cs){#gitlink-id target=_blank}


[PageRangeExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/PageRangeExample.vb){#gitlink-id target=_blank}

tip

You can also use an InputPdf instance directly and access specific InputPdfPage instances from the InputPdf.Pages collection (see PDF Input Sources: Printing Select Pages)