@@ -1599,7 +1599,7 @@ Refer to the following code example to define custom behavior for PDF page‑lev
15991599
16001600{% tabs %}
16011601
1602- {% highlight c# tabtitle="C# [ Cross-platform] " %}
1602+ {% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink=" https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Add-Page-Level-Actions-in-PDF/.NET/Add-Page-Level-Actions-in-PDF/Program.cs " %}
16031603
16041604using Syncfusion.Pdf;
16051605using Syncfusion.Pdf.Interactive;
@@ -1726,6 +1726,8 @@ End Using
17261726
17271727{% endtabs %}
17281728
1729+ You can download a complete working sample from [ GitHub] ( https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Pages/Add-Page-Level-Actions-in-PDF/.NET ) .
1730+
17291731## Removing page-level actions from PDF
17301732
17311733Removes 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.
@@ -1734,47 +1736,29 @@ Refer to the following code example for removing PDF page‑level actions.
17341736
17351737{% tabs %}
17361738
1737- {% highlight c# tabtitle="C# [ Cross-platform] " %}
1739+ {% highlight c# tabtitle="C# [ Cross-platform] " playgroundButtonLink=" https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/Pages/Removing-page-level-actions-from-PDF/.NET/Removing-page-level-actions-from-PDF/Program.cs " %}
17381740
17391741using Syncfusion.Pdf;
17401742using Syncfusion.Pdf.Interactive;
17411743
1742- // Create a new PDF document.
1743- using (PdfDocument document = new PdfDocument( ))
1744+ // Load the existing PDF document
1745+ using (PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf") ))
17441746{
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");
1747+ // Iterate through all pages in the document
1748+ foreach (PdfLoadedPage page in document.Pages)
1749+ {
1750+ // Remove any JavaScript or actions that execute
1751+ // when the page is opened
1752+ page.Actions.OnOpen = null;
1753+
1754+ // Remove any JavaScript or actions that execute
1755+ // when the page is closed
1756+ page.Actions.OnClose = null;
1757+ }
1758+ // Save the modified PDF document
1759+ document.Save(Path.GetFullPath(@"Output/Output.pdf"));
1760+ // Close the document
1761+ document.Close(true);
17781762}
17791763
17801764{% endhighlight %}
@@ -1784,42 +1768,23 @@ using (PdfDocument document = new PdfDocument())
17841768using Syncfusion.Pdf;
17851769using Syncfusion.Pdf.Interactive;
17861770
1787- // Create a new PDF document.
1788- using (PdfDocument document = new PdfDocument( ))
1771+ // Load the existing PDF document
1772+ using (PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf") ))
17891773{
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");
1774+ // Iterate through all pages in the document
1775+ foreach (PdfLoadedPage page in document.Pages)
1776+ {
1777+ // Remove any JavaScript or actions that execute
1778+ // when the page is opened
1779+ page.Actions.OnOpen = null;
1780+ // Remove any JavaScript or actions that execute
1781+ // when the page is closed
1782+ page.Actions.OnClose = null;
1783+ }
1784+ // Save the modified PDF document
1785+ document.Save(Path.GetFullPath(@"Output/Output.pdf"));
1786+ // Close the document
1787+ document.Close(true);
18231788}
18241789
18251790{% endhighlight %}
@@ -1829,52 +1794,29 @@ using (PdfDocument document = new PdfDocument())
18291794Imports Syncfusion.Pdf
18301795Imports Syncfusion.Pdf.Interactive
18311796
1832- ' Create a new PDF document.
1833- Using document As New PdfDocument()
1797+ ' Load the existing PDF document
1798+ Using document As New PdfLoadedDocument(
1799+ Path.GetFullPath("Data/Input.pdf"))
1800+ ' Iterate through all pages in the document
1801+ For Each page As PdfLoadedPage In document.Pages
1802+ ' Remove any JavaScript or actions that execute
1803+ ' when the page is opened
1804+ page.Actions.OnOpen = Nothing
1805+ ' Remove any JavaScript or actions that execute
1806+ ' when the page is closed
1807+ page.Actions.OnClose = Nothing
1808+
1809+ Next
1810+ ' Save the modified PDF document
1811+ document.Save(Path.GetFullPath("Output/Output.pdf"))
1812+
1813+ ' Close the document
1814+ document.Close(True)
18341815
1835- ' Add a page to the document.
1836- Dim page1 As PdfPage = document.Pages.Add()
1837- ' Create and add new JavaScript action to execute when the first page opens
1838- page1.Actions.OnOpen = New PdfJavaScriptAction(
1839- "app.alert(""Welcome! This page has just been opened."");"
1840- )
1841- ' Create and add new URI action to execute when the first page closes
1842- page1.Actions.OnClose = New PdfUriAction("http://www.google.com")
1843- ' Add second page to the document.
1844- Dim page2 As PdfPage = document.Pages.Add()
1845- ' Create a sound action
1846- Dim soundAction As New PdfSoundAction("Startup.wav")
1847- soundAction.Sound.Bits = 16
1848- soundAction.Sound.Channels = PdfSoundChannels.Stereo
1849- soundAction.Sound.Encoding = PdfSoundEncoding.Signed
1850- soundAction.Volume = 0.9F
1851- ' Set the sound action to execute when the second page opens
1852- page2.Actions.OnOpen = soundAction
1853- ' Create and add new Launch action to execute when the second page closes
1854- page2.Actions.OnClose = New PdfLaunchAction("logo.png")
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)
1874- ' Save the document
1875- document.Save("Output.pdf")
18761816End Using
18771817
18781818{% endhighlight %}
18791819
1880- {% endtabs %}
1820+ {% endtabs %}
1821+
1822+ You can download a complete working sample from [ GitHub] ( https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Pages/Removing-page-level-actions-from-PDF/.NET ) .
0 commit comments