Hi asad ali,
Please find attached screen. I am trying to annotate the word
“This is a small demonstration” on the pdf of first line but it is drawn on second line.
And i am sharing my coordinates and code here.
Coordinates of the first word:(annotated_screen1)-This is drawn correctly
height: 9.333343505859375
left: 260.50189208984375
selectedText: " approva"
top: 232.77084350585938
width: 30.618896484375
Coordinates of the second word:(annotated_screen2)- This is drawn wrongly
- height: 9.333328247070312
- left: 410.60418701171875
- pageNumber: “1”
- selectedText: “CTN LOB DIMENHYDRINATE TAB BP 50MG 10”
- top: 67.04167175292969
- width: 154.4189453125annotated_screen2.png (157.7 KB)
annotated_screen1.png (201.5 KB)
string contentRootPath = _hostingEnvironment.ContentRootPath;
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.PDF.Product.Family.lic”);
Aspose.Pdf.Document document = new Aspose.Pdf.Document(Path.Combine(contentRootPath + “\ClientApp\src\assets\” + annotate.filename));
double pageHeight = document.Pages[annotate.pageNumber].Rect.Height;
var page = document.Pages[annotate.pageNumber];
document.FitWindow = true;
double X = (annotate.yValue - 30), Y = (annotate.xValue - 10), Height = (annotate.height), Width = annotate.width;
TextAnnotation textAnnotation = new TextAnnotation(document.Pages[annotate.pageNumber], new Aspose.Pdf.Rectangle(X, page.Rect.Height - Y - Height, X + Width, page.Rect.Height - Y));
TextFragmentAbsorber ta = new TextFragmentAbsorber();
Border border = new Border(textAnnotation);
border.Width = 30;
border.Dash = new Dash(1, 1);
textAnnotation.Border = border;
textAnnotation.Color = Aspose.Pdf.Color.DarkRed;
textAnnotation.Rect = new Aspose.Pdf.Rectangle(X, page.Rect.Height - Y - Height, X + Width, page.Rect.Height - Y);
ta.TextSearchOptions = new TextSearchOptions(textAnnotation.Rect);
ta.Visit(document.Pages[annotate.pageNumber]);
document.Pages[annotate.pageNumber].Annotations.Add(textAnnotation);
var squareAnnotation = new SquareAnnotation(document.Pages[annotate.pageNumber], new Aspose.Pdf.Rectangle(X, page.Rect.Height - Y - Height, X + Width, page.Rect.Height - Y))
{
Title = loggedInUser + "-" + "(" + annotate.department + ")" + ":" + DateTime.Now.ToString(),
Color = Aspose.Pdf.Color.Red,
InteriorColor = Aspose.Pdf.Color.MistyRose,
Contents = annotate.annotatedText,
Opacity = 0.5,
Popup = new PopupAnnotation(document.Pages[annotate.pageNumber], new Aspose.Pdf.Rectangle(X, page.Rect.Height - Y - Height, X + Width, page.Rect.Height - Y))
};
document.Pages[annotate.pageNumber].Annotations.Add(squareAnnotation);
document.Save(System.IO.Path.Combine(Path.Combine(contentRootPath + "\\ClientApp\\src\\assets\\" + annotate.filename)));
pdfsave.SaveAnnotation(annotate);
What i observed here is, If i selecte bigger font size word on PDF the rect or circles are drawn above the text.