Recently I used the pdf controls and I got something weird with iOS coordinates. Using the below function in an Android device I got the correct coordinates, but if I use an iOS device the coordinates aren't the same. For example, using Android device I got
{{X=177.4717,Y=227.54,Width=66.04127,Height=11.04}}
and using iOS device:
{{X=17747,17,Y=-6047,08,Width=6604,129,Height=1104}}.
X, Width and Height are 100 times the same but Y coordinate doesn't make sense for me. It's a negative coordinate and I couldn't find the relationship with the others.
How do you get the Y coordinate in a iDevice?
Hope you can help me.
Regards.
public static MemoryStream HighLightPdf(this byte[] bytes, Dictionary<string, IList<string>> words)
{
Color color = Color.Yellow;
PdfLoadedDocument doc = new PdfLoadedDocument(bytes);
Dictionary<int, List<RectangleF>> matchRect = new Dictionary<int, List<RectangleF>>();
foreach (var key in words.Keys)
{
if (key == "Locations")
color = Color.Blue;
else if (key == "Organizations")
color = Color.Red;
else if (key == "People")
color = Color.Green;
foreach (var word in words[key])
{
var matched = doc.FindText(word, out matchRect);
if (matched)
{
foreach (KeyValuePair<int, List<RectangleF>> item in matchRect)
{
PdfLoadedPage page = doc.Pages[item.Key] as PdfLoadedPage;
foreach (var rect in item.Value)
{
PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation(newRect);
textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
textannot.TextMarkupColor = new PdfColor(color);
page.Annotations.Add(textannot);
}
}
}
}
}
MemoryStream memStream = new MemoryStream();
doc.Save(memStream);
return memStream;
}