diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons.sln b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons.sln new file mode 100644 index 00000000..6d02fdf4 --- /dev/null +++ b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35707.178 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adding-PDF-Attachments-with-Interactive-Launch-Buttons", "Adding-PDF-Attachments-with-Interactive-Launch-Buttons\Adding-PDF-Attachments-with-Interactive-Launch-Buttons.csproj", "{2BAE2C1D-2436-4DE8-A255-F0CD3CE3BFE4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2BAE2C1D-2436-4DE8-A255-F0CD3CE3BFE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BAE2C1D-2436-4DE8-A255-F0CD3CE3BFE4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BAE2C1D-2436-4DE8-A255-F0CD3CE3BFE4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BAE2C1D-2436-4DE8-A255-F0CD3CE3BFE4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Adding-PDF-Attachments-with-Interactive-Launch-Buttons.csproj b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Adding-PDF-Attachments-with-Interactive-Launch-Buttons.csproj new file mode 100644 index 00000000..535f1234 --- /dev/null +++ b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Adding-PDF-Attachments-with-Interactive-Launch-Buttons.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Handle_attachments_in_PDF + enable + enable + + + + + + + diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Data/Attachment.pdf b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Data/Attachment.pdf new file mode 100644 index 00000000..cfd2c5ce Binary files /dev/null and b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Data/Attachment.pdf differ diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Data/Input.pdf b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Data/Input.pdf new file mode 100644 index 00000000..6402c2ed Binary files /dev/null and b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Data/Input.pdf differ diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Output/gitkeep.txt b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs new file mode 100644 index 00000000..e93745e7 --- /dev/null +++ b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs @@ -0,0 +1,58 @@ +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf; +using Syncfusion.Drawing; +using System.Reflection.Metadata; + +//Create FileStream object to read the input PDF file +using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +{ + // Load the existing PDF file + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); + + // Get the first page of the PDF + PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; + + // Create a PDF attachment + PdfAttachment attachment = new PdfAttachment("Attachment.pdf", File.ReadAllBytes(Path.GetFullPath(@"Data/Attachment.pdf"))); + attachment.Description = "PDF Attachment"; + + // Create attachments section if it doesn't exist + if (loadedDocument.Attachments == null) + loadedDocument.CreateAttachment(); + + // Add the attachment to the document + loadedDocument.Attachments.Add(attachment); + + // Create a button field on the page + PdfButtonField buttonField = new PdfButtonField(lpage, "Button"); + buttonField.Bounds = new RectangleF(100, 100, 100, 20); + buttonField.BorderColor = new PdfColor(Color.Black); + buttonField.BackColor = new PdfColor(Color.LightGray); + buttonField.Text = "Click Me"; + buttonField.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); + + // Add JavaScript action to open the attachment + buttonField.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: \"Attachment.pdf\", nLaunch: 2 });"); + + // Create a form if it doesn't exist + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); + + // Add the button field to the form + loadedDocument.Form.Fields.Add(buttonField); + + // Set default appearance for form fields + loadedDocument.Form.SetDefaultAppearance(false); + + //Create file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) + { + //Save the PDF document to file stream. + loadedDocument.Save(outputFileStream); + } + + //Close the document. + loadedDocument.Close(true); +}