We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Pdf Text Annotation overlapping issue

Hi Support,

We are using annotations with aspose pdf but the annotation icon is overlapping the content. 
Can you please take a look at the following code and attached image to see what the problem is?
Aspose pdf version: 16.10.1.0
Dim textAnnotation As TextAnnotation = New TextAnnotation(pdfDocument.Pages(intPageNmbr), New Aspose.Pdf.Rectangle(imageStamp.XIndent, imageStamp.YIndent, imageStamp.XIndent, imageStamp.YIndent))

textAnnotation.Title = user.GivenName & " " & user.SirName
textAnnotation.Subject = “”
textAnnotation.State = AnnotationState.Marked
textAnnotation.Contents = (DateTime.Now()).ToString(“MM.dd.yyyy hh:mm tt”) & " " & GetShortTimeZoneName(loggedInUser.NotificationTimeZones)
textAnnotation.Open = False
textAnnotation.Icon = TextIcon.Help

pdfDocument.Pages(intPageNmbr).Annotations.Add(textAnnotation)
Issue has been happening both on IE and also chrome
Is there a way to hide the icon and only make it visible upon mouse hover or prevent it from overlapping the underneath text?
Please advise how to solve the problem. 

Hi Kanakesh,


Thanks for contacting support.

I have tried to run the code snippet which you have shared and noticed that there are some objects which were undefined (e.g. imageStamp, pdfDocument, user). Please note that when you add a TextAnnotation inside the PDF it displays at the very position which you define by passing Rectangle object inside constructor. In a case if icon of the annotation is overlapping the content, you may change its position by specifying different coordinates of Rectangle object. I have highlighted the part of your code snippet where you need to modify the position of annotation.

Dim textAnnotation As TextAnnotation = New TextAnnotation(pdfDocument.Pages(intPageNmbr), New Aspose.Pdf.Rectangle(imageStamp.XIndent, imageStamp.YIndent, imageStamp.XIndent, imageStamp.YIndent))

Moreover I am afraid that you are using an old version of API whereas it is always recommended to use the latest version which is 17.3.0. Please try specifying different position of the annotation so that it cannot overlap the content with latest version of the API. In a case you still face any issue please share your sample input file(s) along with working code snippet so that we can try to replicate the scenario in our environment and address it accordingly.



Best Regards,
asad.ali:

I have tried to run the code snippet which you have shared and noticed that there are some objects which were undefined (e.g. imageStamp, pdfDocument, user). Please note that when you add a TextAnnotation inside the PDF it displays at the very position which you define by passing Rectangle object inside constructor. In a case if icon of the annotation is overlapping the content, you may change its position by specifying different coordinates of Rectangle object. I have highlighted the part of your code snippet where you need to modify the position of annotation.
Dim textAnnotation As TextAnnotation = New TextAnnotation(pdfDocument.Pages(intPageNmbr), New Aspose.Pdf.Rectangle(imageStamp.XIndent, imageStamp.YIndent, imageStamp.XIndent, imageStamp.YIndent

Is there any settings that I can use to hide the rectangular box and only display it on mouse hover?

Like when the mouse overs on it, the rectangular box pointed in the attached image shows up.
If not, its not visible.

Or the ideal solution that i am looking for is to totally remove the rectangular box, but to just display the text annotation when someone clicks/hover mouse over the area.

Hi Kanakesh,


Thanks for writing back.

kkurra:
Or the ideal solution that i am looking for is to totally remove the rectangular box, but to just display the text annotation when someone clicks/hover mouse over the area.

Please check the following code snippet to achieve the requirement. You can check in the following code snippet that I have hidden the icon of the Annotation and added JavaScript for popup to show/hide on mouse enter/exit.

string name = “TXTANNOT”;<o:p></o:p>

string title = "Mouse Over Annotation";

string comment = "This is test text annotation.";

// Document creating

Document doc = new Document();

doc.Pages.Add().Paragraphs.Add(new TextFragment("This is simple sentence."));

doc.Save(dataDir + "mouseover_annot.pdf");

doc = new Document(dataDir + "mouseover_annot.pdf");

TextFragmentAbsorber absorber = new TextFragmentAbsorber("This is simple sentence.");

doc.Pages[1].Accept(absorber);

Page page = doc.Pages[1];

// Add text annotation

TextAnnotation text = new TextAnnotation(page, absorber.TextFragments[1].Rectangle);

text.Name = name;

text.Title = title;

text.Contents = comment;

// This flags must be raised to suppress showing of annotation icon

text.Flags = AnnotationFlags.NoView | AnnotationFlags.ReadOnly;

page.Annotations.Add(text);

Aspose.Pdf.Rectangle popupRect = new Aspose.Pdf.Rectangle(90, 610, 235, 710);

// Add popup annotation

PopupAnnotation popup = new PopupAnnotation(page, popupRect);

page.Annotations.Add(popup);

// Link text and popup annotations

text.Popup = popup;

popup.Parent = text;

// Add button

Field field = new ButtonField(page, absorber.TextFragments[1].Rectangle);

doc.Form.Add(field);

// Set ButtonField actions

string fieldName = field.PartialName;

string openScript = "var t = this.getAnnot(this.pageNum, '" + name + "'); t.popupOpen = true; var w = this.getField('" + fieldName + "'); w.setFocus();";

string closeScript = "var t = this.getAnnot(this.pageNum, '" + name + "'); t.popupOpen = false;";

field.Actions.OnEnter = new JavascriptAction(openScript);

field.Actions.OnExit = new JavascriptAction(closeScript);

// Save document

doc.Save(dataDir + "mouseover_annot.pdf");


I have also attached an output generated by above code for your reference. In case if you need any further assistance please feel free to let us know.


Best Regards,

asad.ali:

I have also attached an output generated by above code for your reference. In case if you need any further assistance please feel free to let us know.


Thank you for your detailed response. very much apprecite your time.
I only added the following statement to my existing code, but the downloaded document does not show the popup on mouse hover
textAnnotation.Flags = AnnotationFlags.NoView

Is a textabsorbtion and Javascript call necessary to openup the popup as given in your example?
Can't i just set the annotation NoView flag and hover over the spot where i know the icon is and see the annotation text popup?

here is the entire code..
Dim textAnnotation As TextAnnotation = New TextAnnotation(pdfDocument.Pages(intPageNmbr), New Aspose.Pdf.Rectangle(imageStamp.XIndent, imageStamp.YIndent, imageStamp.XIndent, imageStamp.YIndent))
textAnnotation.Title = "Abc"
textAnnotation.Subject = ""
textAnnotation.State = AnnotationState.Marked
textAnnotation.Contents = (DateTime.Now()).ToString("MM.dd.yyyy hh:mm tt") & " " & GetShortTimeZoneName(loggedInUser.NotificationTimeZones)
textAnnotation.Open = False
textAnnotation.Flags = AnnotationFlags.NoView

Please advise.....

Hi Kanakesh,


Thanks for your feedback.

kkurra:
Is a textabsorbtion and Javascript call necessary to openup the popup as given in your example?
Can’t i just set the annotation NoView flag and hover over the spot where i know the icon is and see the annotation text popup?

Setting the flag of annotation to NoView means that annotation will have no view or be hidden in the document. By doing this user will not be able to interact with the annotation. If you look at the example which I have shared earlier you will notice that it is not the TextAnnotation which displays at mouse over. It is the popup annotation which is associated with the TextAnnotation.

Moreover, I have used the TextFragmentAbsorber to determine the position where I had to add the TextAnnotation so that it can be displayed when mouse pointer enters the particular region of the page. However there is no such property to make an annotation display on mouse over. That is why you need to use Javascript to achieve the functionality.

kkurra:
the downloaded document does not show the popup on mouse hover

Please check the previous attached document by opening it with Adobe Reader and share if you still face problem noticing the mouse over feature. In case if you have any other query please feel free to ask.


Best Regards,