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!
C# - Extract pages based on a keyword match |
Post Reply |
Author | |
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
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()); } |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store