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

Free Support Forum - aspose.com

PDF Javascript at TextFragment or TextSegment level?


We are currently evaluating Aspose.Pdf for .Net as a replacement for iTextSharp. I am using the new Aspose.Pdf API (i.e., not the Generator)

So far, I believe Aspose.Pdf can do everything that we currently do with iTextSharp, with one possible exception involving javascript.

What I Need to Do
Please let me know how I can accomplish the following:
Add some javascript that will be invoked when a reader clicks on a word or other section of text.

I have found the Actions allowing me to invoke javascript when the document is opened/closed/printed, and when a page is opened/closed, but nothing resembling Actions on a TextFragment or TextSegment (where I would expect to be able to do what I’m trying to do.)

To illustrate, I would like to be able to do something similar to this…

var fragment = new TextFragment(“hello, World!”);
fragment.Actions.OnClick =
new JavascriptAction(“app.alert(‘fragment clicked’)”);

or this…

var segment = new TextSegment(“hello, World!”);
segment.Actions.OnClick =
new JavascriptAction(“app.alert(‘segment clicked’)”);

Is there any way to achieve something like this. Some kind of workaround?

Please reply at your earliest convenience, as we will be making our decision regarding the use of Aspose.Pdf in our product. If I unable to accomplish this javascript functionality, it will mean that we cannot use Aspose.Pdf.

Thank you,
R. Ernst

Hi Richard,

Thanks for your inquiry. We will appreciate if you please share a sample PDF document containing desired feature. We will look into it and hopefully we will suggest you a workaround for the requirement.

Best Regards,
Hi Tilal,

Thank you for your response. Attached is a PDF created with iTextSharp which demonstrates what I am trying to achieve. Javascript code is executed whenever any of the underlined text elements are clicked.

R. Ernst

Hi Richard,

Thanks for sharing sample document. It helped us to understand your exact requirement. We have logged an investigation ticket PDFNEWNET-37220 for your requirement in our issue tracking system. We will keep you updated about the issue resolution progress.

Best Regards,