Skip to content

Commit 8bbb972

Browse files
committed
1016957:Resolved the given feedback.
1 parent 4c19f6f commit 8bbb972

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed
Binary file not shown.

Pages/Removing-page-level-actions-from-PDF/.NET/Removing-page-level-actions-from-PDF/Program.cs

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,21 @@
11
using Syncfusion.Pdf;
22
using Syncfusion.Pdf.Interactive;
33

4-
// Create a new PDF document.
5-
using (PdfDocument document = new PdfDocument())
4+
// Load the existing PDF document
5+
using (PdfLoadedDocument document = new PdfLoadedDocument(
6+
Path.GetFullPath(@"Data/Input.pdf")))
67
{
7-
// Add a page to the document.
8-
PdfPage page1 = document.Pages.Add();
9-
// Create and add new JavaScript action to execute when the first page opens
10-
page1.Actions.OnOpen = new PdfJavaScriptAction("app.alert(\"Welcome! This page has just been opened.\");");
11-
// Create and add new URI action to execute when the first page closes
12-
page1.Actions.OnClose = new PdfUriAction("http://www.google.com");
13-
// Add second page to the document.
14-
PdfPage page2 = document.Pages.Add();
15-
// Create a sound action
16-
PdfSoundAction soundAction = new PdfSoundAction(Path.GetFullPath(@"Data/Startup.wav"));
17-
soundAction.Sound.Bits = 16;
18-
soundAction.Sound.Channels = PdfSoundChannels.Stereo;
19-
soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
20-
soundAction.Volume = 0.9f;
21-
// Set the so und action to execute when the second page opens
22-
page2.Actions.OnOpen = soundAction;
23-
// Create and add new Launch action to execute when the second page closes
24-
page2.Actions.OnClose = new PdfLaunchAction(Path.GetFullPath(@"Data/logo.png"));
25-
// Add third page to the document
26-
PdfPage page3 = document.Pages.Add();
27-
// Create and add new JavaScript action to execute when the third page opens
28-
PdfAction jsAction = new PdfJavaScriptAction("app.alert(\"Welcome! Third page has just been opened.\");");
29-
jsAction.Next = new PdfJavaScriptAction("app.alert(\"This is the second action.\");");
30-
jsAction.Next.Next = new PdfJavaScriptAction("app.alert(\"This is the third action.\");");
31-
page3.Actions.OnOpen = jsAction;
32-
// Removing the open action on first page
33-
page1.Actions.OnOpen = null;
34-
// Removing the close action on second page
35-
page2.Actions.OnClose = null;
36-
// Removing both actions on third page
37-
page3.Actions.Clear(false);
38-
//Save the document
8+
// Iterate through all pages in the document
9+
foreach (PdfLoadedPage page in document.Pages)
10+
{
11+
// Remove any JavaScript or actions that execute
12+
// when the page is opened
13+
page.Actions.OnOpen = null;
14+
// Remove any JavaScript or actions that execute
15+
// when the page is closed
16+
page.Actions.OnClose = null;
17+
}
18+
// Save the modified PDF document
3919
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4020
// Close the document
4121
document.Close(true);

0 commit comments

Comments
 (0)