Show note on clicking or onmouseover of Image in PDF

i have attached a image in pdf . i like to show detail of image in pop up (like Note on attachment) rather clicking on image it or on mouse over.

Hello Manish,

As far as I’ve understood from image details, you need to display the image in Notes popup, where notes contents and heading are displayed? If so, is the case, then I am sorry to inform you that Aspose.Pdf doesn’t support this feature.

Else if you need to display image details image location and name, Attachment type, its very possible. Please try using the following code snippet. The resultant PDF is also in attachment.

[C#]

Pdf pdf = new Pdf();
Aspose.Pdf.Section sec1 = pdf.Sections.Add();

//Instantiate attachment instance by calling its empty constructor
Attachment fileAttachment = new Attachment();

//Add attachment in the paragraphs collection of the section
sec1.Paragraphs.Add(fileAttachment);

//Set attachment type to File using AttachmentType enumeration
fileAttachment.AttachmentType = AttachmentType.File;

//Set the path of the attachment file
fileAttachment.AttachedFileName = "d:/pdftest/Aspose.JPG";

//Set the type of the file to be attached
fileAttachment.AttachedFileType  ="Image"

//Set the file icon type to Graph
fileAttachment.FileIconType = FileIconType.Graph;

//Set the color of the icon to Brown
fileAttachment.IconColor = new Aspose.Pdf.Color("Brown");
fileAttachment.AttachmentType = AttachmentType.Note;

// set note contents information
fileAttachment.NoteContent = "Attachment location is = " + fileAttachment.AttachedFileName.ToString() + " and type is = " + fileAttachment.AttachedFileType.ToString();

// set the value for Note as open note is open when the Pdf document is opened.
fileAttachment.IsNoteOpen = true;

// save the PDF file
pdf.Save(@"d:/pdftest/File_attachment.pdf");

Please correct me if I’ve not properly understood your requirement.

no, in sort i like to have tooltip of image in pdf. i have added an image in pdf and how to show tooltip (with html formatted).

Hello Manish,

Sorry for replying to you late. In order to accomplish your requirement, please try using FloatingBox, which can be placed anywhere in the PDF file and can display the text with HTML formatting. Please try using the following code snippet. The resultant PDF file is in attachment, please take a look.

[C#]

Pdf pdf = new Pdf();

Aspose.Pdf.Section sec1 = pdf.Sections.Add();

Aspose.Pdf.Attachment fileAttachment = new Attachment();

// Add Image attachment in the paragraphs collection of the section
sec1.Paragraphs.Add(fileAttachment);

// Set attachment type to File using AttachmentType enumeration
fileAttachment.AttachmentType = AttachmentType.File;

// Set the path of the attachment file
fileAttachment.AttachedFileName = "d:/pdftest/Aspose.jpg";

// Set the type of the file to be attached
fileAttachment.AttachedFileType = "jpg";

// Set the file icon type to Graph
fileAttachment.FileIconType = FileIconType.Graph;

// Set the color of the icon to Brown
fileAttachment.IconColor = new Aspose.Pdf.Color("Brown");

// Create string variables with text containing html tags
string s = "<font face=\"Times New Roman\" size=10><u>This is a test </u><i> for <strong> HTML </strong> support </i><s> in Text paragraph. </s></font>";

// Create text paragraphs containing HTML text
Text t2 = new Text(s);

// Enable this option to display text in HTML formatting
t2.IsHtmlTagSupported = true;

// Create a FloatingBox to display the Tooltip for Image attachment
FloatingBox box1 = new FloatingBox(225, 15);

sec1.Paragraphs.Add(box1);

// Create a BorderInfo object for FloatingBox
BorderInfo binfo = new BorderInfo((int)BorderSide.All, .1f, new Aspose.Pdf.Color("Red"));

box1.Border = binfo;
box1.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;
box1.Left = 13;
box1.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
box1.Top = 52;
box1.Paragraphs.Add(t2);

// save the PDF file
pdf.Save(@"d:/pdftest/File_attachment.pdf");

In case it does not satisfy your requirement, please feel free to share more details.
For information on related topics covered in code snippet please visit:

I want to create an annotation that will appear when the mouse goes over some text. Something similar to the annotation in this file: [http://examples.itextpdf.com/results/part2/chapter07/movie_posters_2.pdf ](http://examples.itextpdf.com/results/part2/chapter07/movie_posters_2.pdf)

This example uses iText. Can I achieve something like that using Aspose?

Hi Diego,


Thanks for your inquiry. After initial investigation we have logged your requirement in our issue tracking system as PDFNEWNET-36228 for further investigation. We will keep you updated about its resolution via this forum thread.


We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36228) have been fixed in Aspose.Pdf for .NET 9.4.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Diego,

In reference to PDFNEWNET-36228 fix, we have enhanced the API to support showing text/note on mouseover events of an Image/text. Now you can make popup window notes that appear on mouseover or another events you need. Please use the following code snippet. It will help you to accomplish the task.

Declaring of parameters

Unique name of annotation

string name = "IMDB0145487";

Title of popup window

string title = "Spider-Man";

Description that will be in popup window

string comment = "Movie produced in 2002; run length: 121";

Path to image for that popup window will appeared on mouse over

string imagePath = ("36228.jpg");

Position of image on page of document

Aspose.Pdf.Rectangle imageRect = new Aspose.Pdf.Rectangle(2, 700, 97, 840);

Position of popup on page of document

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

Document creating

Document doc = new Document();
doc.Pages.Add();

Page for adding of image

Page page = doc.Pages[1];

Add image on page

load image into stream

FileStream imageStream = new FileStream(imagePath, FileMode.Open);

add image to Images collection of Page Resources

page.Resources.Images.Add(imageStream);

using GSave operator: this operator saves current graphics state

page.Contents.Add(new Operator.GSave());

create Rectangle and Matrix objects

Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[]
{
    imageRect.URX - imageRect.LLX, 0, 0,
    imageRect.URY - imageRect.LLY, imageRect.LLX, imageRect.LLY
});

using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed

page.Contents.Add(new Operator.ConcatenateMatrix矀matrix));
XImage ximage = page.Resources.Images[page.Resources.Images.Count];

using Do operator: this operator draws image

page.Contents.Add(new Operator.Do(ximage.Name));

using GRestore operator: this operator restores graphics state

page.Contents.Add(new Operator.GRestore());

Add text annotation

TextAnnotation text = new TextAnnotation(page, imageRect);
text.Name = name;
text.Title = title;
text.Contents = comment;

This flag must be raised to suppress showing of annotation icon

text.Flags = AnnotationFlags.NoView | AnnotationFlags.ReadOnly;
page.Annotations.Add(text);

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, imageRect);
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("36228.pdf");

Please feel free to contact us for any further assistance.

Best Regards,