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

Free Support Forum - aspose.com

How can I open specific embed file?

Click on LinkAnnotation and I want to open specific file in EmbededFiles.

Document doc = new Document(filePath);

FileStream fileStream = null;
string[] filePaths = Directory.GetFiles(rootPath);

foreach (string item in filePaths)
{
fileStream = new FileStream(item, FileMode.Open);
doc.EmbeddedFiles.Add(new FileSpecification(fileStream, Path.GetFileName(item)));
}

TextFragmentAbsorber absorber = new TextFragmentAbsorber(pattern, new TextSearchOptions(true));
doc.Pages.Accept(absorber);

TextFragmentCollection textFragmentCollection = absorber.TextFragments;
LinkAnnotation linkAnnotation = null;

foreach (TextFragment item in textFragmentCollection)
{
item.TextState.BackgroundColor = Aspose.Pdf.Color.Yellow;

linkAnnotation = new LinkAnnotation(item.Page, item.Rectangle);
linkAnnotation.Action = new LaunchAction(doc, item.Text);

    **It doesn't work. What should I do?**

item.Page.Annotations.Add(fileAnnotation);

}

doc.Save(filePath, SaveFormat.Pdf);

@Junyoung

Thank you for contacting support.

We would like to request you to use below code snippet in your environment and then share your kind feedback with us. It adds a file as an attachment in a PDF file and you can open that specific file by double clicking the annotation.

    Document document = new Document();
    Page page = document.Pages.Add();
    FileSpecification fs = new FileSpecification(dataDir + "Test.txt", "This is attachment.");
    FileAttachmentAnnotation file = new FileAttachmentAnnotation(page, new Aspose.Pdf.Rectangle(40, 800, 60, 820), fs);
    fs.Params = new FileParams(fs);
    fs.Params.ModDate = DateTime.Now;
    fs.Params.CreationDate = DateTime.Now;
    file.Color = Aspose.Pdf.Color.Transparent;
    file.Hyperlink = new FileHyperlink(dataDir + "Test.txt");
    file.Contents = "This is Attachment.";
    page.Annotations.Add(file);
    file.Name = "AttachedFile";
    document.Save(dataDir + "Test_18.6.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.