@@ -1609,11 +1609,10 @@ using (PdfDocument document = new PdfDocument())
16091609{
16101610 // Add a page to the document.
16111611 PdfPage page1 = document.Pages.Add();
1612- document.Actions.AfterOpen =
16131612 // Create and add new JavaScript action to execute when the first page opens
1614- Page1 .Actions.OnOpen = new PdfJavaScriptAction("app.alert(\" Welcome! This page has just been opened.\" );");
1613+ page1 .Actions.OnOpen = new PdfJavaScriptAction("app.alert(\" Welcome! This page has just been opened.\" );");
16151614 // Create and add new URI action to execute when the first page closes
1616- Page1 .Actions.OnClose = new PdfUriAction("http://www.google.com ");
1615+ page1 .Actions.OnClose = new PdfUriAction("http://www.google.com ");
16171616 // Add second page to the document.
16181617 PdfPage page2 = document.Pages.Add();
16191618 // Create a sound action
@@ -1623,13 +1622,16 @@ using (PdfDocument document = new PdfDocument())
16231622 soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
16241623 soundAction.Volume = 0.9f;
16251624 // Set the sound action to execute when the second page opens
1626- Page2 .Actions.OnOpen = soundAction;
1625+ page2 .Actions.OnOpen = soundAction;
16271626 // Create and add new Launch action to execute when the second page closes
1628- Page2.Actions.OnClose = new PdfLaunchAction("logo.png");
1629- // Removing the close action on first page
1630- Page1.Actions.OnClose = null;
1631- // Removing both open and close actions on second page
1632- Page2.Actions.Clear(true);
1627+ page2.Actions.OnClose = new PdfLaunchAction("logo.png");
1628+ // Add third page to the document
1629+ PdfPage page3 = document.Pages.Add();
1630+ // Create and add new JavaScript action to execute when the third page opens
1631+ PdfAction jsAction = new PdfJavaScriptAction("app.alert(\" Welcome! Third page has just been opened.\" );");
1632+ jsAction.Next = new PdfJavaScriptAction("app.alert(\" This is the second action.\" );");
1633+ jsAction.Next.Next = new PdfJavaScriptAction("app.alert(\" This is the third action.\" );");
1634+ page3.Actions.OnOpen = jsAction;
16331635 //Save the document
16341636 document.Save("Output.pdf");
16351637}
@@ -1646,11 +1648,10 @@ using (PdfDocument document = new PdfDocument())
16461648{
16471649 // Add a page to the document.
16481650 PdfPage page1 = document.Pages.Add();
1649- document.Actions.AfterOpen =
16501651 // Create and add new JavaScript action to execute when the first page opens
1651- Page1 .Actions.OnOpen = new PdfJavaScriptAction("app.alert(\" Welcome! This page has just been opened.\" );");
1652+ page1 .Actions.OnOpen = new PdfJavaScriptAction("app.alert(\" Welcome! This page has just been opened.\" );");
16521653 // Create and add new URI action to execute when the first page closes
1653- Page1 .Actions.OnClose = new PdfUriAction("http://www.google.com ");
1654+ page1 .Actions.OnClose = new PdfUriAction("http://www.google.com ");
16541655 // Add second page to the document.
16551656 PdfPage page2 = document.Pages.Add();
16561657 // Create a sound action
@@ -1660,13 +1661,16 @@ using (PdfDocument document = new PdfDocument())
16601661 soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
16611662 soundAction.Volume = 0.9f;
16621663 // Set the sound action to execute when the second page opens
1663- Page2 .Actions.OnOpen = soundAction;
1664+ page2 .Actions.OnOpen = soundAction;
16641665 // Create and add new Launch action to execute when the second page closes
1665- Page2.Actions.OnClose = new PdfLaunchAction("logo.png");
1666- // Removing the close action on first page
1667- Page1.Actions.OnClose = null;
1668- // Removing both open and close actions on second page
1669- Page2.Actions.Clear(true);
1666+ page2.Actions.OnClose = new PdfLaunchAction("logo.png");
1667+ // Add third page to the document
1668+ PdfPage page3 = document.Pages.Add();
1669+ // Create and add new JavaScript action to execute when the third page opens
1670+ PdfAction jsAction = new PdfJavaScriptAction("app.alert(\" Welcome! Third page has just been opened.\" );");
1671+ jsAction.Next = new PdfJavaScriptAction("app.alert(\" This is the second action.\" );");
1672+ jsAction.Next.Next = new PdfJavaScriptAction("app.alert(\" This is the third action.\" );");
1673+ page3.Actions.OnOpen = jsAction;
16701674 //Save the document
16711675 document.Save("Output.pdf");
16721676}
@@ -1680,15 +1684,165 @@ Imports Syncfusion.Pdf.Interactive
16801684
16811685' Create a new PDF document.
16821686Using document As New PdfDocument()
1687+
1688+ ' Add a page to the document.
1689+ Dim page1 As PdfPage = document.Pages.Add()
1690+ ' Create and add new JavaScript action to execute when the first page opens
1691+ page1.Actions.OnOpen = New PdfJavaScriptAction(
1692+ "app.alert(""Welcome! This page has just been opened."");"
1693+ )
1694+ ' Create and add new URI action to execute when the first page closes
1695+ page1.Actions.OnClose = New PdfUriAction("http://www.google.com")
1696+ ' Add second page to the document.
1697+ Dim page2 As PdfPage = document.Pages.Add()
1698+ ' Create a sound action
1699+ Dim soundAction As New PdfSoundAction("Startup.wav")
1700+ soundAction.Sound.Bits = 16
1701+ soundAction.Sound.Channels = PdfSoundChannels.Stereo
1702+ soundAction.Sound.Encoding = PdfSoundEncoding.Signed
1703+ soundAction.Volume = 0.9F
1704+ ' Set the sound action to execute when the second page opens
1705+ page2.Actions.OnOpen = soundAction
1706+ ' Create and add new Launch action to execute when the second page closes
1707+ page2.Actions.OnClose = New PdfLaunchAction("logo.png")
1708+ ' Add third page to the document
1709+ Dim page3 As PdfPage = document.Pages.Add()
1710+ ' Create and add new JavaScript action to execute when the third page opens
1711+ Dim jsAction As PdfAction = New PdfJavaScriptAction(
1712+ "app.alert(""Welcome! Third page has just been opened."");"
1713+ )
1714+ jsAction.Next = New PdfJavaScriptAction(
1715+ "app.alert(""This is the second action."");"
1716+ )
1717+ jsAction.Next.Next = New PdfJavaScriptAction(
1718+ "app.alert(""This is the third action."");"
1719+ )
1720+ page3.Actions.OnOpen = jsAction
1721+ ' Save the document
1722+ document.Save("Output.pdf")
1723+ End Using
1724+
1725+ {% endhighlight %}
1726+
1727+ {% endtabs %}
1728+
1729+ ## Removing page-level actions from PDF
1730+
1731+ Removes page‑level actions from PDF documents by disabling actions triggered on page open and page close events, ensuring that pages no longer execute automatic behaviors while preserving existing annotation actions where required.
1732+
1733+ Refer to the following code example for removing PDF page‑level actions.
1734+
1735+ {% tabs %}
1736+
1737+ {% highlight c# tabtitle="C# [ Cross-platform] " %}
1738+
1739+ using Syncfusion.Pdf;
1740+ using Syncfusion.Pdf.Interactive;
1741+
1742+ // Create a new PDF document.
1743+ using (PdfDocument document = new PdfDocument())
1744+ {
1745+ // Add a page to the document.
1746+ PdfPage page1 = document.Pages.Add();
1747+ // Create and add new JavaScript action to execute when the first page opens
1748+ page1.Actions.OnOpen = new PdfJavaScriptAction("app.alert(\" Welcome! This page has just been opened.\" );");
1749+ // Create and add new URI action to execute when the first page closes
1750+ page1.Actions.OnClose = new PdfUriAction("http://www.google.com ");
1751+ // Add second page to the document.
1752+ PdfPage page2 = document.Pages.Add();
1753+ // Create a sound action
1754+ PdfSoundAction soundAction = new PdfSoundAction("Startup.wav");
1755+ soundAction.Sound.Bits = 16;
1756+ soundAction.Sound.Channels = PdfSoundChannels.Stereo;
1757+ soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
1758+ soundAction.Volume = 0.9f;
1759+ // Set the sound action to execute when the second page opens
1760+ page2.Actions.OnOpen = soundAction;
1761+ // Create and add new Launch action to execute when the second page closes
1762+ page2.Actions.OnClose = new PdfLaunchAction("logo.png");
1763+ // Add third page to the document
1764+ PdfPage page3 = document.Pages.Add();
1765+ // Create and add new JavaScript action to execute when the third page opens
1766+ PdfAction jsAction = new PdfJavaScriptAction("app.alert(\" Welcome! Third page has just been opened.\" );");
1767+ jsAction.Next = new PdfJavaScriptAction("app.alert(\" This is the second action.\" );");
1768+ jsAction.Next.Next = new PdfJavaScriptAction("app.alert(\" This is the third action.\" );");
1769+ page3.Actions.OnOpen = jsAction;
1770+ // Removing the open action on first page
1771+ page1.Actions.OnOpen = null;
1772+ // Removing the close action on second page
1773+ page2.Actions.OnClose = null;
1774+ // Removing both actions on third page
1775+ page3.Actions.Clear(false);
1776+ //Save the document
1777+ document.Save("Output.pdf");
1778+ }
1779+
1780+ {% endhighlight %}
1781+
1782+ {% highlight c# tabtitle="C# [ Windows-specific] " %}
1783+
1784+ using Syncfusion.Pdf;
1785+ using Syncfusion.Pdf.Interactive;
1786+
1787+ // Create a new PDF document.
1788+ using (PdfDocument document = new PdfDocument())
1789+ {
1790+ // Add a page to the document.
1791+ PdfPage page1 = document.Pages.Add();
1792+ // Create and add new JavaScript action to execute when the first page opens
1793+ page1.Actions.OnOpen = new PdfJavaScriptAction("app.alert(\" Welcome! This page has just been opened.\" );");
1794+ // Create and add new URI action to execute when the first page closes
1795+ page1.Actions.OnClose = new PdfUriAction("http://www.google.com ");
1796+ // Add second page to the document.
1797+ PdfPage page2 = document.Pages.Add();
1798+ // Create a sound action
1799+ PdfSoundAction soundAction = new PdfSoundAction("Startup.wav");
1800+ soundAction.Sound.Bits = 16;
1801+ soundAction.Sound.Channels = PdfSoundChannels.Stereo;
1802+ soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
1803+ soundAction.Volume = 0.9f;
1804+ // Set the sound action to execute when the second page opens
1805+ page2.Actions.OnOpen = soundAction;
1806+ // Create and add new Launch action to execute when the second page closes
1807+ page2.Actions.OnClose = new PdfLaunchAction("logo.png");
1808+ // Add third page to the document
1809+ PdfPage page3 = document.Pages.Add();
1810+ // Create and add new JavaScript action to execute when the third page opens
1811+ PdfAction jsAction = new PdfJavaScriptAction("app.alert(\" Welcome! Third page has just been opened.\" );");
1812+ jsAction.Next = new PdfJavaScriptAction("app.alert(\" This is the second action.\" );");
1813+ jsAction.Next.Next = new PdfJavaScriptAction("app.alert(\" This is the third action.\" );");
1814+ page3.Actions.OnOpen = jsAction;
1815+ // Removing the open action on first page
1816+ page1.Actions.OnOpen = null;
1817+ // Removing the close action on second page
1818+ page2.Actions.OnClose = null;
1819+ // Removing both actions on third page
1820+ page3.Actions.Clear(false);
1821+ //Save the document
1822+ document.Save("Output.pdf");
1823+ }
1824+
1825+ {% endhighlight %}
1826+
1827+ {% highlight vb.net tabtitle="VB.NET [ Windows-specific] " %}
1828+
1829+ Imports Syncfusion.Pdf
1830+ Imports Syncfusion.Pdf.Interactive
1831+
1832+ ' Create a new PDF document.
1833+ Using document As New PdfDocument()
1834+
16831835 ' Add a page to the document.
16841836 Dim page1 As PdfPage = document.Pages.Add()
16851837 ' Create and add new JavaScript action to execute when the first page opens
1686- page1.Actions.OnOpen = New PdfJavaScriptAction("app.alert(""Welcome! This page has just been opened."");")
1838+ page1.Actions.OnOpen = New PdfJavaScriptAction(
1839+ "app.alert(""Welcome! This page has just been opened."");"
1840+ )
16871841 ' Create and add new URI action to execute when the first page closes
16881842 page1.Actions.OnClose = New PdfUriAction("http://www.google.com")
16891843 ' Add second page to the document.
16901844 Dim page2 As PdfPage = document.Pages.Add()
1691- ' Create a sound action
1845+ ' Create a sound action
16921846 Dim soundAction As New PdfSoundAction("Startup.wav")
16931847 soundAction.Sound.Bits = 16
16941848 soundAction.Sound.Channels = PdfSoundChannels.Stereo
@@ -1698,10 +1852,25 @@ Using document As New PdfDocument()
16981852 page2.Actions.OnOpen = soundAction
16991853 ' Create and add new Launch action to execute when the second page closes
17001854 page2.Actions.OnClose = New PdfLaunchAction("logo.png")
1701- ' Removing the close action on first page
1702- page1.Actions.OnClose = Nothing
1703- ' Removing both open and close actions on second page
1704- page2.Actions.Clear(True)
1855+ ' Add third page to the document
1856+ Dim page3 As PdfPage = document.Pages.Add()
1857+ ' Create and add new JavaScript action to execute when the third page opens
1858+ Dim jsAction As PdfAction = New PdfJavaScriptAction(
1859+ "app.alert(""Welcome! Third page has just been opened."");"
1860+ )
1861+ jsAction.Next = New PdfJavaScriptAction(
1862+ "app.alert(""This is the second action."");"
1863+ )
1864+ jsAction.Next.Next = New PdfJavaScriptAction(
1865+ "app.alert(""This is the third action."");"
1866+ )
1867+ page3.Actions.OnOpen = jsAction
1868+ ' Removing the open action on first page
1869+ page1.Actions.OnOpen = Nothing
1870+ ' Removing the close action on second page
1871+ page2.Actions.OnClose = Nothing
1872+ ' Removing both actions on third page
1873+ page3.Actions.Clear(False)
17051874 ' Save the document
17061875 document.Save("Output.pdf")
17071876End Using
0 commit comments