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.

Thu Feb 09, 2017 4:55 pm

I need to print a single page from a multipage pdf document.

1. How can I find the page
2. How can I tell it to print just that page only.

Thank you.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Feb 10, 2017 3:53 am

Hi,

Thanks for your inquiry.
If you know the page number of the page you want to print, you can set the print range when printing.
But if you don't know the page number, firstly you can find the page number by finding special text which is only on the page you want to print. And then set the print range and print.
Here is sample code for your kind reference.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"F:\testing\pdf form testing\original document\9223.pdf");
            PdfTextFind[] result = null;
            foreach (PdfPageBase page in pdf.Pages)
            {
                result = (page.FindText("Special").Finds);
                foreach (PdfTextFind find in result)
                {
                    //find the page number you want
                    int pageNumber = find.SearchPageIndex;
                    PrintPage(pdf, pageNumber);
                }
            }
        }
        public static void PrintPage(PdfDocument doc, int index)
        {
            doc.PrintFromPage = index;
            doc.PrintToPage = index;
            doc.PrintDocument.Print();
        }

If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Feb 10, 2017 5:34 pm

Thank you very much, that code worked perfectly.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Mon Feb 13, 2017 1:32 am

Hi,

Thanks for your feedback.
Please feel free to contact us if you have any question, we are here for help.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron