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

Free Support Forum - aspose.com

Creating hyperlink to local Excel file

Hello,

Can you please advise best way to insert a hyperlink into a PDF that opens a local Excel file.

I have the PDF and Excel file in the same folder. When I click on the hyperlink in the PDF, it should open the Excel file in the same directory called “workbook.xlsx”

Thanks!

@ast3

You can achieve it using different ways. For example, you can use FileHyperlink and set it against TextFragment.Hyperlink property. Also, you can embed JavaScript to open Excel file:

Document doc = new Document(dataDir + "sample.pdf");
TextFragmentAbsorber absorber = new TextFragmentAbsorber("Link to File");
doc.Pages[1].Accept(absorber);
Page page = doc.Pages[1];
// Add button
Field field = new ButtonField(page, absorber.TextFragments[1].Rectangle);
doc.Form.Add(field);
// Set ButtonField actions
string fieldName = field.PartialName;
string opendocscript = "app.openDoc(\"/D/TestDocument2.pdf\");";
field.Actions.OnPressMouseBtn = new JavascriptAction(opendocscript);
// Save document
doc.Save(dataDir + "OpenPDFFile.pdf");