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

Free Support Forum - aspose.com

Adding a text label next to attachment in PDF?


I want to create a PDF document with attached documents.
That works great, I get a nice icon in my PDF document.

Now I want to add a name to that attachement, next to that icon.
E.g. when I add a word file with a customer review in the PDF document I want to have the icon and right next to it “customer review”.

I’ve searched the documentation for this, but all I could find was the possibility to add notes to the attachment icon. This is not what I’m looking for since I need to move over the icon with my cursor to view the note. I want to have it visible at all times.

A screenshot of what I have now in the generated PDF document:

An edited screenhot of what I’m looking for to accomplish in the generated PDF document:

Is it possible to generate the PDF document this way ?

To add the attachment I’m using this code:

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

//Add attachment in the paragraphs collection of the section

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

//Set the path of the attachment file
fileAttachment.AttachedFileName = "C:/ps4BA15.doc";
fileAttachment.NoteContent = "customer review";

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

Thanks in advance!

Hello Kurt,

Thanks for considering Aspose.

Aspose.Pdf has a great feature named Floating Box, its a sub-class of Paragraph and it can contain one or more paragraphs and the best part is you can place it any where in the document. Using this feature you can display the name of Attachments next to an icon. Please try the following code snippet and in case of any concerned issue, please feel free to share.

Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();

Attachment fileAttachment = new Attachment();
fileAttachment.AttachmentType = AttachmentType.File;
fileAttachment.AttachedFileName = @"C:/pdftest/Document.pdf";
fileAttachment.AttachedFileType = "pdf";
fileAttachment.FileIconType = FileIconType.PaperClip;

FloatingBox box1 = new FloatingBox(108,80);
box1.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;
box1.Left = 20;
box1.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
box1.Top = 70;
int Slash = fileAttachment.AttachedFileName.IndexOf('/',3);
int Dot = fileAttachment.AttachedFileName.IndexOf('.', Slash);
box1.Paragraphs.Add(new Text("" + fileAttachment.AttachedFileName.Substring(Slash+1,Dot-(Slash+1))));


For more information on floating box kindly visit Let's start with Hello.

That approach works great, thanks!