Enumerate PDF pages, split and merge based on text found

Posted by: philippe.durand on 24 February 2020, 1:34 am EST

  • Posted 24 February 2020, 1:34 am EST


    TLDR - We have old code that parse PDFs using C1.WPF.PdfViewer, does not work with newer version of C1. We need to update our code.

    Here are the details.

    Our WPF application uses PdfViewer version "4.0.20143.434" to parses mobile bills (PDF) and split pages according to phone numbers found.

    For each page found, the application enumerates the elements and whenever a TextBlock is found it checks if the Text property matches a phone number. Matching pages are added to a collection, then merged later in a new PDF.

    We tried several times upgrading to a newer version of C1 but everytime we did it break the application. Newer version of PdfViewer returns Path objects instead of TextBlock, it is much slower and ends up with an out of memory exception.

    We are looking for a way to update our code. Maybe using C1PdfDocumentSource, but I don't know how to parse the pages.

    Dictionary<string, PhoneNumberData> GetPhoneNumbers(C1PdfViewer viewer)
    var phoneNumbers = new Dictionary<string, PhoneNumberData>();
    foreach(var page in pages)
    string phoneNumber;

    if (FindPhoneNumber(page, out phoneNumber))


    return phoneNumbers;

    bool FindPhoneNumber(FrameworkElement frameworkElement, out string phoneNumber)
    var phoneNumberFound = false;
    phoneNumber = null;

    if(frameworkElement != null)
    var i = 0;
    var c = VisualTreeHelper.GetChildrenCount(frameworkElement);
    while(i < c)
    var child = VisualTreeHelper.GetChild(frameworkElement, i);

    if(child is TextBlock)


  • Marked as Answer

    Replied 24 February 2020, 10:35 pm EST


    Though, I understand your requirement, it would be helpful if you can share your stripped down application with all logics you have implemented for the various phases of this task. This would speed up the process and allow us to help you quickly.

  • Replied 17 March 2020, 12:48 am EST

  • Replied 23 March 2020, 11:51 pm EST


    I apologize for the delay.
    I am discussing your requirement with the developer [TFS: 427033] and will let you know the solution/information soon.

  • Replied 3 May 2020, 4:33 pm EST


    We've attached an application 'PdfDocumentSource.zip' that demonstrates how to search text in document. But C1PdfDocumentSource does not allow to contain functionality to edit loaded document.
    To meet your requirement, we suggest to use GcPdf document library. It is available as nuget package: GrapeCity.Documents.Pdf
    We've attached a demo application 'GcPdf.zip' implementing your requirement.

    Thanks & Regards,
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels