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);
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);
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,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.