Free Support Forum - aspose.com

Display the text of the file name

Hi

var pdfConv = new Aspose.Pdf.Generator.Pdf();
Document pdfDocument = new Document();
pdfDocument.Pages.Add();
Page pdfPage = pdfDocument.Pages[1];
FileStream fs = new FileStream("C:\\TAMSTemplate.docx", FileMode.Open);
FileSpecification fileSpecification = new FileSpecification(fs, "TAMSTemplate.docx", "Testing");
pdfDocument.EmbeddedFiles.Add(fileSpecification);
FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(pdfPage, new Rectangle(0, 0, 16, 16), pdfDocument.EmbeddedFiles[1]);
fileAttachment.Icon = FileIcon.Paperclip;
fileAttachment.Title = fileAttachment.RichText= "Attached file"; pdfDocument.Pages[1].Annotations.Add(fileAttachment);
const string fullpath = "C:\\output1.pdf";
pdfDocument.Save(fullpath);

I require to display the text of the file name which will be adjacent to paperclip icon
can you just help me with this?

This message was posted using Email2Forum by Imran Rafique. (private)
Hi

var pdfConv = new Aspose.Pdf.Generator.Pdf();
Document pdfDocument = new Document();
pdfDocument.Pages.Add();
Page pdfPage = pdfDocument.Pages[1];
FileStream fs = new FileStream("C:\\TAMSTemplate.docx", FileMode.Open);
FileSpecification fileSpecification = new FileSpecification(fs, "TAMSTemplate.docx", "Testing");
pdfDocument.EmbeddedFiles.Add(fileSpecification);
FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(pdfPage, new Rectangle(0, 0, 16, 16), pdfDocument.EmbeddedFiles[1]);
fileAttachment.Icon = FileIcon.Paperclip;
fileAttachment.Title = fileAttachment.RichText= "Attached file"; pdfDocument.Pages[1].Annotations.Add(fileAttachment);
const string fullpath = "C:\\output1.pdf";
pdfDocument.Save(fullpath);

I require to display the text of the file name which will be adjacent to paperclip icon
can you just help me with this?

Hi John,


Thanks for contacting support.

Please try using following code snippet to accomplish your requirement. Please note that when you need to place Text or other paragraph object on obsolete position, please try using FloatingBox object.

[C#]

Document pdfDocument = new Document();<o:p></o:p>

pdfDocument.Pages.Add();

Page pdfPage = pdfDocument.Pages[1];

Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox(100, 10);

floatBox.Padding.Left = 165;

floatBox.Padding.Top = 553;

Aspose.Pdf.Text.TextFragment fragment = new TextFragment("Inline Text");

floatBox.Paragraphs.Add(fragment);

pdfPage.Paragraphs.Add(floatBox);

FileStream fs = new FileStream("C:\\pdftest\\sample_01.jpg", FileMode.Open);

FileSpecification fileSpecification = new FileSpecification(fs, "TAMSTemplate.docx", "Testing");

pdfDocument.EmbeddedFiles.Add(fileSpecification);

FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(pdfPage, new Aspose.Pdf.Rectangle(240, 210, 256, 226), pdfDocument.EmbeddedFiles[1]);

fileAttachment.Icon = FileIcon.Paperclip;

fileAttachment.Title = fileAttachment.RichText = "Attached file"; pdfDocument.Pages[1].Annotations.Add(fileAttachment);

const string fullpath = "C:\\pdftest\\InlineImageTest.pdf";

pdfDocument.Save(fullpath);

Hi John,


The reason file appears twice in file attachment tab is because we have added file as attachment twice i.e. Once in EmbeddedFiles collection and second as FileAttachmentAnnotation. However in order to have one file in attachment tab as well as in page body area, please try using following updated code snippet.

[C#]

Document pdfDocument = new Document();<o:p></o:p>

pdfDocument.Pages.Add();

Page pdfPage = pdfDocument.Pages[1];

Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox(100, 10);

floatBox.Padding.Left = 165;

floatBox.Padding.Top = 553;

Aspose.Pdf.Text.TextFragment fragment = new TextFragment("Inline Text");

floatBox.Paragraphs.Add(fragment);

pdfPage.Paragraphs.Add(floatBox);

FileStream fs = new FileStream("C:\\pdftest\\PDF_A2b_ComplianceCheck.PNG", FileMode.Open);

FileSpecification fileSpecification = new FileSpecification(fs, "Contacts Center.png", "Testing");

// pdfDocument.EmbeddedFiles.Add(fileSpecification);

FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(pdfPage, new Aspose.Pdf.Rectangle(240, 210, 256, 226),fileSpecification);// pdfDocument.EmbeddedFiles[1]);

fileAttachment.Icon = FileIcon.Paperclip;

fileAttachment.Title = fileAttachment.RichText = "Attached file";

pdfDocument.Pages[1].Annotations.Add(fileAttachment);

const string fullpath = "C:\\pdftest\\InlineImageTest.pdf";

pdfDocument.Save(fullpath);

How Can i have link to the attachment for the Text(Inline Text) instead of linking it to paper clip Icon


Hi John,


Thanks for your inquiry. Please note file would be attached to some icon. However, as a workaround you can reduce opacity of FileAttachmentAnnotation Icon and place it over the required text. So it will impression of Text link. Please check following code snippet for the purpose. Hopefully it will help you to accomplish the task.

Document pdfDocument = new Document();<o:p></o:p>

Aspose.Pdf.Page pdfPage = pdfDocument.Pages.Add();

Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox(100, 10);

floatBox.Padding.Left = 165;

floatBox.Padding.Top = 553;

Aspose.Pdf.Text.TextFragment fragment = new TextFragment("Inline Text");

floatBox.Paragraphs.Add(fragment);

pdfPage.Paragraphs.Add(floatBox);

FileStream fs = new FileStream("E:\\data\\aspose-Pdf-for-net.PNG", FileMode.Open);

FileSpecification fileSpecification = new FileSpecification(fs, "Contacts Center.png", "Testing");

// pdfDocument.EmbeddedFiles.Add(fileSpecification);

FileAttachmentAnnotation fileAttachment = new FileAttachmentAnnotation(pdfPage, new Aspose.Pdf.Rectangle(200, 210, 230, 216), fileSpecification);// pdfDocument.EmbeddedFiles[1]);

fileAttachment.Icon = FileIcon.Paperclip;

fileAttachment.Opacity = .01;

fileAttachment.Title = fileAttachment.RichText = "Attached file";

pdfDocument.Pages[1].Annotations.Add(fileAttachment);

const string fullpath = myDir+"InlineImageTest.pdf";

pdfDocument.Save(fullpath);

Please feel free to contact us for any further assistance.

Best Regards,