Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - C# - Extract pages based on a keyword match
  FAQ FAQ  Forum Search   Register Register  Login Login

C# - Extract pages based on a keyword match

 Post Reply Post Reply
Author
Message
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Topic: C# - Extract pages based on a keyword match
    Posted: 02 Jul 12 at 7:03AM

This code will iterate through all pages in a PDF file and if the extracted text contains the 'keyword' then the page is added to a list and all matching pages are extracted into a new document.

Of course, you can make the matching more complex to suit your needs.

Andrew.

             string keyword = "garden";

        string extractPages = "";
        int foundCount = 0;

        QP.LoadFromFile("originalfile.pdf", "");

        // Iterate through each page in the document
        for (int page = 1; page <= QP.PageCount(); page++)
        {
            // look for pages that match

            QP.SelectPage(page);
            string TextContent = QP.GetPageText(0);  // Can also use option 8.

            if (TextContent.Contains(keyword))  // we found a page
            {
                if (foundCount != 0)
                    extractPages = extractPages + ",";

                extractPages = extractPages + page.ToString();
                    
                foundCount++;
            } 
        }

        if (foundCount > 0)
        {
            QP.ExtractPageRanges(extractPages);
            QP.SaveToFile("out.pdf");
        }
        else
            MessageBox.Show("Keyword not found");

        QP.RemoveDocument(QP.SelectedDocument());
    }

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store