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

Free Support Forum - aspose.com

.Net Popup annotations display only

Hi

I’ve added a colour box to my page and following examples I found here am trying to add a popup annotation.

It works but in Acrobat Reader the popup isn’t read only and the user gets a reply button. I’ve attached an example and the code below is what I’m using. If they do try to reply all manner of weird flickering happens.

Ultimately when they hover over the coloured rectangle I want it to just popup a window with the title and comments and nothing else, no reply button etc. Tried all sorts of flags but can’t seem to get it to work.

Also once you’ve hovered over and leave it leaves a dashed border behind, how do I remove that too?

string name = $"TXTANNOT{pageCount}";
string title = "Notes";
string comment = "Some notes the user entered";

var height = pdf.PageInfo.Height;
var actualRect = new Aspose.Pdf.Rectangle(73, height - 230, 526, height - 174);
var popupRect = new Aspose.Pdf.Rectangle(73, height - 230, 526, height - 174);

var text = new Aspose.Pdf.Annotations.TextAnnotation(page, actualRect);
text.Name = name;
text.Title = title;
text.Contents = comment;

text.Flags = Aspose.Pdf.Annotations.AnnotationFlags.NoView | Aspose.Pdf.Annotations.AnnotationFlags.ReadOnly;

page.Annotations.Add(text);

var popup = new Aspose.Pdf.Annotations.PopupAnnotation(page, popupRect);
page.Annotations.Add(popup);
text.Popup = popup;
popup.Parent = text;

var field = new Aspose.Pdf.Forms.ButtonField(page, actualRect);
pdf.Form.Add(field);

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 Aspose.Pdf.Annotations.JavascriptAction(openScript);
field.Actions.OnExit = new Aspose.Pdf.Annotations.JavascriptAction(closeScript);

Any help would be appreciated

example.pdf (184.1 KB)

@simon.fairey

Thanks for contacting support.

As per our understandings, you need to add a tooltip inside PDF document at your desired location (i.e Rectangle). You may achieve this by following instructions given over “Add Tooltip to Text” article(s) in our API documentation. In case you still face any issue, please share original source PDF document with us, so that we can test the scenario in our environment and address it accordingly. It seems that the document you provided with your post, is an output PDF.

Ahh this works much better thanks, I was using a buttonfield and a textboxfield but this way is cleaner.

2 follow up questions, the delay before the AlternateName appears on hover over, can that be changed/reduced?
Secondly, it doesn’t work when viewing in Chrome, is there anything that can be done about that?

Thanks

Si

@simon.fairey

Thanks for your feedback.

The delay in appearing AlternateName on mouse hover, is according to default behavior of Adobe Reader for populating tooltips. However, if you need to reduce the popup time of text on mouse over, you may please use “Create a Hidden Text Block and Show it on Mouse Over” example where JavaScript actions are used to show a hidden text block.

We have also observed the same behavior with resultant PDF document that tooltips were not showing when document was opened in Chrome Browser. For the sake of investigation, we have generated a ticket as PDFNET-44539 in our issue tracking system. We will further look into the details of this behavior and keep you posted with the status of ticket resolution. Please spare us little time.

We are sorry for the inconvenience.

Hi

I was using the javascript approach (which does work in Chrome) before but there is one issue in that the text box doesn’t show a scrollbar to allow viewing the entire content of the textbox, I tried setting the scrollable value but that made no difference. This is important as the highlighted area may be small but the hoverover text could be large. See below and I’ve included the output.output.pdf (317.5 KB)

        var cleanImage = @"C:\temp\cleanimage.png";
        var alteredImage = @"C:\temp\alteredimage.png";
        var output = @"C:\temp\output.pdf";
        if (File.Exists(alteredImage)) File.Delete(alteredImage);
        if (File.Exists(output)) File.Delete(output);
        File.Copy(cleanImage, alteredImage);

        var pdf = new Aspose.Pdf.Document();

        using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(alteredImage))
        {
            Aspose.Imaging.Graphics graphic = new Aspose.Imaging.Graphics(image);
            var brush = new Aspose.Imaging.Brushes.SolidBrush();
            brush.Color = Aspose.Imaging.Color.FromArgb(50, Aspose.Imaging.Color.Green);
            graphic.FillRectangle(brush, new Aspose.Imaging.Rectangle(100, 217, 620, 71));
            image.Save();
        }

        var page = pdf.Pages.Add();

        page.PageInfo.Margin.Bottom = 20;
        page.PageInfo.Margin.Top = 0;
        page.PageInfo.Margin.Left = 0;
        page.PageInfo.Margin.Right = 0;

        Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
        image1.File = alteredImage;
        page.Paragraphs.Add(image1);

        var height = pdf.PageInfo.Height;
        var textRect = new Aspose.Pdf.Rectangle(73, height - 230, 200, height - 174);
        var actualRect = new Aspose.Pdf.Rectangle(73, height - 230, 526, height - 174);

        var floatingField = new Aspose.Pdf.Forms.TextBoxField(page, textRect);
        floatingField.Value = "For the first time in his career, Denzel Washington has made a sequel to one of his films. It’s the follow-up to The Equalizer, that unites him again with director Antoine Fuqua (they've made films such as Training Day and The Magnificent Seven together), and Washington will reprisre the role of Robert McCall in the new movie.";
        floatingField.ReadOnly = true;
        floatingField.Flags |= Aspose.Pdf.Annotations.AnnotationFlags.Hidden;

        floatingField.PartialName = "FloatingField_1";

        // Setting characteristics of field appearance isn't necessary but makes it better
        floatingField.DefaultAppearance = new Aspose.Pdf.Annotations.DefaultAppearance("Calibri", 9, System.Drawing.Color.Black);
        floatingField.Characteristics.Background = System.Drawing.Color.LightYellow;
        floatingField.Characteristics.Border = System.Drawing.Color.Black;
        floatingField.Border = new Aspose.Pdf.Annotations.Border(floatingField);
        floatingField.Border.Width = 1;
        floatingField.Multiline = true;
        floatingField.Scrollable = true;

        pdf.Form.Add(floatingField);

        var buttonField = new Aspose.Pdf.Forms.ButtonField(page, actualRect);
        //buttonField.AlternateName = "Note:\nThis is some note the user may have entered";
        buttonField.Actions.OnEnter = new Aspose.Pdf.Annotations.HideAction(floatingField.FullName, false);
        buttonField.Actions.OnExit = new Aspose.Pdf.Annotations.HideAction(floatingField.FullName);

        pdf.Form.Add(buttonField);

        pdf.Save(output);

cleanimage.png (31.9 KB)

@simon.fairey

Thanks for sharing more details with us.

We have tested the scenario in our environment and were managed to observe that the scrollbar was not appearing in the TextBoxField. Hence, we have logged this issue as PDFNET-44543 in our issue tracking system for the sake of correction. We will further look into the details of the issue and keep you informed with the status of its resolution.

Meanwhile, as a workaround, you may please increase the height of textRect in your code snippet, so that the long text could fit within the boundaries of text block. i.e.

var textRect = new Aspose.Pdf.Rectangle(73, height - 230, 200, height - 125);

output_out.pdf (316.6 KB)

For your reference, an output PDF is also attached which was obtained after increasing the height of text box rectangle as above line of code. As soon as we make some significant progress towards issue resolution, we will let you know. Please spare us little time.

We are sorry for the inconvenience.

Hi,

Unfortunately that won’t really work for me as we don’t know how much text a user may have entered when we generate that field so I guess we’ll have to come up with some kind of algorithm that can work out from the text and the font how big the box needs to be.

Is there anything in the toolkit that might help us with this, something that might autofit text in a box that we could then maybe do int he background and find out how big a rectangle is required?

I know the alternateName generates a dynamically sized hoverover popup, any way we can hook into that?

Thanks

Si

@simon.fairey

In case you do not set DefaultAppearance of TextBoxField, it will adjust text automatically within its boundaries with suitable font size. Please check attached PDF which was generated after excluding following line of code:

floatingField.DefaultAppearance = new Aspose.Pdf.Annotations.DefaultAppearance("Calibri", 9, System.Drawing.Color.Black);

output.pdf (277.9 KB)

Furthermore, it is recommended to set Multiline property before assigning the value to the TextBoxField as follows:

floatingField.Multiline = true;
floatingField.Value = fieldValue;

@simon.fairey

Thanks for your patience.

We have investigated the earlier logged ticket and found, that only implementation of HideAction constructor accepting field name, works if Google Chrome browses the document; Using of corresponding constructors is significant if Google Chrome will used for browsing:

buttonField.Actions.OnEnter = new HideAction(floatingField.FullName, false);
buttonField.Actions.OnExit = new HideAction(floatingField.FullName);

However, regarding the second method, i.e. “Add Tooltip to Text” - does work fine when viewing PDF document in Adobe Reader. It seems Google Chrome specific issue that it is not showing the tooltip while displaying the PDF in it.

Concerning to other logged ticket i.e. PDFNET-44543, we will let you know once we have some certain updates regarding its resolution. Please spare us little time.

We are sorry for the inconvenience.

1 Like