|
1 | 1 | using Syncfusion.Pdf; |
2 | 2 | using Syncfusion.Pdf.Interactive; |
3 | 3 |
|
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"))) |
6 | 7 | { |
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 |
39 | 19 | document.Save(Path.GetFullPath(@"Output/Output.pdf")); |
40 | 20 | // Close the document |
41 | 21 | document.Close(true); |
|
0 commit comments