Skip to content

Commit 7178a2d

Browse files
committed
1014603-ug: Added feature UG documentation for Support for Page‑Level Actions (OnOpen and OnClose) in PDF Documents
1 parent 428b594 commit 7178a2d

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

Document-Processing/PDF/PDF-Library/NET/Working-with-Pages.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,3 +1590,123 @@ loadedDocument.Close(True)
15901590
{% endtabs %}
15911591

15921592
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Pages/Insert-New-Page-in-Existing-PDF-with-Same-Size/.NET).
1593+
1594+
## Support for Page‑Level Actions in PDF
1595+
1596+
Added full support for page‑level actions in the .NET PDF library, enabling developers to add, retrieve, edit, and remove actions triggered by PDF page events such as `OnOpen` and `OnClose`.
1597+
1598+
Refer to the following code example to define custom behavior for PDF page‑level actions.
1599+
1600+
{% tabs %}
1601+
1602+
{% highlight c# tabtitle="C# [Cross-platform]" %}
1603+
1604+
using Syncfusion.Pdf;
1605+
using Syncfusion.Pdf.Interactive;
1606+
1607+
// Create a new PDF document.
1608+
using (PdfDocument document = new PdfDocument())
1609+
{
1610+
// Add a page to the document.
1611+
PdfPage page1 = document.Pages.Add();
1612+
document.Actions.AfterOpen =
1613+
// 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.\");");
1615+
// Create and add new URI action to execute when the first page closes
1616+
Page1.Actions.OnClose = new PdfUriAction("http://www.google.com");
1617+
// Add second page to the document.
1618+
PdfPage page2 = document.Pages.Add();
1619+
// Create a sound action
1620+
PdfSoundAction soundAction = new PdfSoundAction("Startup.wav");
1621+
soundAction.Sound.Bits = 16;
1622+
soundAction.Sound.Channels = PdfSoundChannels.Stereo;
1623+
soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
1624+
soundAction.Volume = 0.9f;
1625+
// Set the sound action to execute when the second page opens
1626+
Page2.Actions.OnOpen = soundAction;
1627+
// 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);
1633+
//Save the document
1634+
document.Save("Output.pdf");
1635+
}
1636+
1637+
{% endhighlight %}
1638+
1639+
{% highlight c# tabtitle="C# [Windows-specific]" %}
1640+
1641+
using Syncfusion.Pdf;
1642+
using Syncfusion.Pdf.Interactive;
1643+
1644+
// Create a new PDF document.
1645+
using (PdfDocument document = new PdfDocument())
1646+
{
1647+
// Add a page to the document.
1648+
PdfPage page1 = document.Pages.Add();
1649+
document.Actions.AfterOpen =
1650+
// 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+
// Create and add new URI action to execute when the first page closes
1653+
Page1.Actions.OnClose = new PdfUriAction("http://www.google.com");
1654+
// Add second page to the document.
1655+
PdfPage page2 = document.Pages.Add();
1656+
// Create a sound action
1657+
PdfSoundAction soundAction = new PdfSoundAction("Startup.wav");
1658+
soundAction.Sound.Bits = 16;
1659+
soundAction.Sound.Channels = PdfSoundChannels.Stereo;
1660+
soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
1661+
soundAction.Volume = 0.9f;
1662+
// Set the sound action to execute when the second page opens
1663+
Page2.Actions.OnOpen = soundAction;
1664+
// 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);
1670+
//Save the document
1671+
document.Save("Output.pdf");
1672+
}
1673+
1674+
{% endhighlight %}
1675+
1676+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
1677+
1678+
1679+
Imports Syncfusion.Pdf
1680+
Imports Syncfusion.Pdf.Interactive
1681+
1682+
' Create a new PDF document.
1683+
Using document As New PdfDocument()
1684+
' Add a page to the document.
1685+
Dim page1 As PdfPage = document.Pages.Add()
1686+
' Create and add new JavaScript action to execute when the first page opens
1687+
page1.Actions.OnOpen = New PdfJavaScriptAction("app.alert(""Welcome! This page has just been opened."");")
1688+
' Create and add new URI action to execute when the first page closes
1689+
page1.Actions.OnClose = New PdfUriAction("http://www.google.com")
1690+
' Add second page to the document.
1691+
Dim page2 As PdfPage = document.Pages.Add()
1692+
' Create a sound action
1693+
Dim soundAction As New PdfSoundAction("Startup.wav")
1694+
soundAction.Sound.Bits = 16
1695+
soundAction.Sound.Channels = PdfSoundChannels.Stereo
1696+
soundAction.Sound.Encoding = PdfSoundEncoding.Signed
1697+
soundAction.Volume = 0.9F
1698+
' Set the sound action to execute when the second page opens
1699+
page2.Actions.OnOpen = soundAction
1700+
' Create and add new Launch action to execute when the second page closes
1701+
page2.Actions.OnClose = New PdfLaunchAction("logo.png")
1702+
' Removing the close action on first page
1703+
page1.Actions.OnClose = Nothing
1704+
' Removing both open and close actions on second page
1705+
page2.Actions.Clear(True)
1706+
' Save the document
1707+
document.Save("Output.pdf")
1708+
End Using
1709+
1710+
{% endhighlight %}
1711+
1712+
{% endtabs %}

0 commit comments

Comments
 (0)