Skip to content

Commit 327753d

Browse files
Merge pull request #2370 from syncfusion-content/1014603-ug
1014603-ug: Added feature UG documentation for Support for Page‑Level Actions (OnOpen and OnClose) in PDF Documents
2 parents 428b594 + b6876c1 commit 327753d

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

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

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,3 +1590,122 @@ 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+
## Page-level actions in PDF documents
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+
Imports Syncfusion.Pdf
1679+
Imports Syncfusion.Pdf.Interactive
1680+
1681+
' Create a new PDF document.
1682+
Using document As New PdfDocument()
1683+
' Add a page to the document.
1684+
Dim page1 As PdfPage = document.Pages.Add()
1685+
' 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."");")
1687+
' Create and add new URI action to execute when the first page closes
1688+
page1.Actions.OnClose = New PdfUriAction("http://www.google.com")
1689+
' Add second page to the document.
1690+
Dim page2 As PdfPage = document.Pages.Add()
1691+
' Create a sound action
1692+
Dim soundAction As New PdfSoundAction("Startup.wav")
1693+
soundAction.Sound.Bits = 16
1694+
soundAction.Sound.Channels = PdfSoundChannels.Stereo
1695+
soundAction.Sound.Encoding = PdfSoundEncoding.Signed
1696+
soundAction.Volume = 0.9F
1697+
' Set the sound action to execute when the second page opens
1698+
page2.Actions.OnOpen = soundAction
1699+
' Create and add new Launch action to execute when the second page closes
1700+
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)
1705+
' Save the document
1706+
document.Save("Output.pdf")
1707+
End Using
1708+
1709+
{% endhighlight %}
1710+
1711+
{% endtabs %}

0 commit comments

Comments
 (0)