Free Support Forum -

Rename a file attachment


I have attached a file using the CreateFileAttachment method. The filename is visible in the Attachment secion and i need to change the name to make it a relevent one. How do i rename the attached fie.



Hi Pooja,

Thanks for using our products.

In order to add an attachment to PDF file, please try using the following code snippet which provides the capability to specify the name of attachment in PDF document.

You may also consider visiting the following link for more information on Add Attachment in a PDF Document


//open document<o:p></o:p>

Document pdfDocument = new Document("c:/pdftest/Annotated_output.pdf");

//setup new file to be added as attachment

FileSpecification fileSpecification = new FileSpecification("c:/pdftest/output.jpg", "Sample Image file");

// specify the name of attachment

fileSpecification.Name = "test file";

//add attachment to document's attachment collection


//save new output



I actually need the file as a link at certain locations (without any icons) in the PDF file therefore i put a temporary string at that location and then seach and replace it with a blank space and create a link using the following code

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(fileName);
for (int pageCnt = 1; pageCnt <= pdfDocument.Pages.Count; pageCnt++)
//accept the absorber for a single page
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
if (textFragmentCollection.Count > 0)
Aspose.Pdf.Rectangle rect;
TextFragment textFragment = textFragmentCollection[1];
textFragment.Text = "";
rect = textFragment.Rectangle;

contentEditor.ReplaceText(fileName, pageCnt, "");

contentEditor.CreateFileAttachment(new System.Drawing.Rectangle((Int32)rect.URX + 15, (Int32)rect.URY + 7, 20, 0),
"", attachFileName, pageCnt, "");

The files at the server which are being attached are saved as their metadata name and these need to be renamed as they are visbile in the attachment section. The code you specified does not let me attach the file at my location without icons. So is it possible to either rename it using the above code or to use your code and specify the location witout a icon.



Hi Pooja,

Thanks for your inquiry. We are looking into to your requirement and will update you soon.

Best Regards,

Hi Pooja,

Please accept my apologies for the delayed response. I’m afraid Aspose.Pdf doesn’t support creation of file attachment annotation without icon, at
the moment. However, I’ve logged a new feature request as
PDFNEWNET-35042 in our issue tracking
system. You will be notified via this thread as soon as it gets available.

Please feel free for contact us for any further assistance.

Best Regard,

Hi Pooja,

Thanks for your patience.

We have investigated the requirement of creating File Annotation without Icon, but I am afraid we could not find any information in PDF specification about changing opacity of the annotation icon but we have noticed that Adobe Acrobat allows to change it. For this purpose annotation dictionary has CA entry which takes double values from 0 (completely transparant) to 1 (completely opaque). So FileAttachmentAnnotation was extended with double property Opacity and PdfContentEditor was extended with 2 methods CreateFileAttachment which take opacity argument.

You may try using the following code snippet to accomplish your requirement.


PdfContentEditor editor = new


editor.CreateFileAttachment(new System.Drawing.Rectangle(50, 50, 10, 10), "here", "simple.doc", 1, "Paperclip", 0.005);


Note. If opacity = 0 then Adobe Reader doesn’t change cursor, when its placed on annotation area. So give opacity small number to both hide icon and keep showing special cursor.

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

This message was posted using Notification2Forum from Downloads module by aspose.notifier.