Posted 24 February 2020, 1:34 am EST
Hi,
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)
{
…
}
}
}
}