//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Pdf.Annotations;usingGrapeCity.Documents.Pdf.Actions; namespaceDsPdfWeb.Demos.Basics{// Shows how to associate a PDF action with a JavaScript script.// In this example the script is associated with a link on a page.// Note that JavaScript may not work in some PDF viewers (e.g. built-in browser viewers). // See JavaScript for Acrobat for details.publicclassJavaScriptAction {conststringjs ="var cChoice = app.popUpMenu(\"Introduction\", \" - \", \"Chapter 1\",\r\n" +"[ \"Chapter 2\", \"Chapter 2 Start\", \"Chapter 2 Middle\",\r\n" +"[\"Chapter 2 End\", \"The End\"]]);\r\n" +"app.alert(\"You chose the '\" + cChoice + \"' menu item\");"; publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var g = doc.NewPage().Graphics;var jsAction = newActionJavaScript(js);var tf = newTextFormat() {Font = StandardFonts.Times,FontSize = 14 };// Draw the link string in a rectangle:var text = "Click this to show the popup menu.";var rect = newRectangleF(newPointF(72, 72), g.MeasureString(text, tf)); g.FillRectangle(rect, Color.LightGoldenrodYellow); g.DrawString(text, tf, rect);var result = newLinkAnnotation(rect, jsAction); doc.Pages.Last.Annotations.Add(result);// Add warning about this possibly not working in a browser:Common.Util.AddNote("Note that JavaScript may not work in some PDF viewers such as built-in browser viewers.", doc.Pages.Last, newRectangleF(rect.X, rect.Bottom + 36, 400, 400));// Done: doc.Save(stream);return doc.Pages.Count; } }}