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?

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 the following code snippet to accomplish your requirement. Please note that when you need to place Text or other paragraph objects on an obsolete position, please try using the FloatingBox object.

[C#]

Document pdfDocument = new Document();
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 the file appears twice in the file attachment tab is because we have added the file as an attachment twice, i.e., once in the EmbeddedFiles collection and secondly as FileAttachmentAnnotation. However, in order to have one file in the attachment tab as well as in the page body area, please try using the following updated code snippet.

[C#]

Document pdfDocument = new Document();
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 the file is attached to an icon. However, as a workaround, you can reduce the opacity of the FileAttachmentAnnotation icon and place it over the required text, giving the impression of a text link. Please check the following code snippet for this purpose. Hopefully, it will help you accomplish the task.

Document pdfDocument = new Document();
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,