Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Document-Processing/PDF/PDF-Library/NET/Working-with-Pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -1590,3 +1590,122 @@ loadedDocument.Close(True)
{% endtabs %}

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).

## Page-level actions in PDF documents

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`.

Refer to the following code example to define custom behavior for PDF page‑level actions.

{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" %}

using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;

// Create a new PDF document.
using (PdfDocument document = new PdfDocument())
{
// Add a page to the document.
PdfPage page1 = document.Pages.Add();
document.Actions.AfterOpen =
// Create and add new JavaScript action to execute when the first page opens
Page1.Actions.OnOpen = new PdfJavaScriptAction("app.alert(\"Welcome! This page has just been opened.\");");
// Create and add new URI action to execute when the first page closes
Page1.Actions.OnClose = new PdfUriAction("http://www.google.com");
// Add second page to the document.
PdfPage page2 = document.Pages.Add();
// Create a sound action
PdfSoundAction soundAction = new PdfSoundAction("Startup.wav");
soundAction.Sound.Bits = 16;
soundAction.Sound.Channels = PdfSoundChannels.Stereo;
soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
soundAction.Volume = 0.9f;
// Set the sound action to execute when the second page opens
Page2.Actions.OnOpen = soundAction;
// Create and add new Launch action to execute when the second page closes
Page2.Actions.OnClose = new PdfLaunchAction("logo.png");
// Removing the close action on first page
Page1.Actions.OnClose = null;
// Removing both open and close actions on second page
Page2.Actions.Clear(true);
//Save the document
document.Save("Output.pdf");
}

{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}

using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;

// Create a new PDF document.
using (PdfDocument document = new PdfDocument())
{
// Add a page to the document.
PdfPage page1 = document.Pages.Add();
document.Actions.AfterOpen =
// Create and add new JavaScript action to execute when the first page opens
Page1.Actions.OnOpen = new PdfJavaScriptAction("app.alert(\"Welcome! This page has just been opened.\");");
// Create and add new URI action to execute when the first page closes
Page1.Actions.OnClose = new PdfUriAction("http://www.google.com");
// Add second page to the document.
PdfPage page2 = document.Pages.Add();
// Create a sound action
PdfSoundAction soundAction = new PdfSoundAction("Startup.wav");
soundAction.Sound.Bits = 16;
soundAction.Sound.Channels = PdfSoundChannels.Stereo;
soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
soundAction.Volume = 0.9f;
// Set the sound action to execute when the second page opens
Page2.Actions.OnOpen = soundAction;
// Create and add new Launch action to execute when the second page closes
Page2.Actions.OnClose = new PdfLaunchAction("logo.png");
// Removing the close action on first page
Page1.Actions.OnClose = null;
// Removing both open and close actions on second page
Page2.Actions.Clear(true);
//Save the document
document.Save("Output.pdf");
}

{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Interactive

' Create a new PDF document.
Using document As New PdfDocument()
' Add a page to the document.
Dim page1 As PdfPage = document.Pages.Add()
' Create and add new JavaScript action to execute when the first page opens
page1.Actions.OnOpen = New PdfJavaScriptAction("app.alert(""Welcome! This page has just been opened."");")
' Create and add new URI action to execute when the first page closes
page1.Actions.OnClose = New PdfUriAction("http://www.google.com")
' Add second page to the document.
Dim page2 As PdfPage = document.Pages.Add()
' Create a sound action
Dim soundAction As New PdfSoundAction("Startup.wav")
soundAction.Sound.Bits = 16
soundAction.Sound.Channels = PdfSoundChannels.Stereo
soundAction.Sound.Encoding = PdfSoundEncoding.Signed
soundAction.Volume = 0.9F
' Set the sound action to execute when the second page opens
page2.Actions.OnOpen = soundAction
' Create and add new Launch action to execute when the second page closes
page2.Actions.OnClose = New PdfLaunchAction("logo.png")
' Removing the close action on first page
page1.Actions.OnClose = Nothing
' Removing both open and close actions on second page
page2.Actions.Clear(True)
' Save the document
document.Save("Output.pdf")
End Using

{% endhighlight %}

{% endtabs %}