diff --git a/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields.sln b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields.sln new file mode 100644 index 00000000..39f85865 --- /dev/null +++ b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36408.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Disable-Auto-Formatting-in-FormFields", "Disable-Auto-Formatting-in-FormFields\Disable-Auto-Formatting-in-FormFields.csproj", "{34749AFC-1835-4920-BB8C-CB1BA56D30DC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {34749AFC-1835-4920-BB8C-CB1BA56D30DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {34749AFC-1835-4920-BB8C-CB1BA56D30DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {34749AFC-1835-4920-BB8C-CB1BA56D30DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {34749AFC-1835-4920-BB8C-CB1BA56D30DC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FC101EA9-8443-4983-8315-FD8699DF19F9} + EndGlobalSection +EndGlobal diff --git a/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Data/Input.pdf b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Data/Input.pdf new file mode 100644 index 00000000..752d7772 Binary files /dev/null and b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Data/Input.pdf differ diff --git a/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Disable-Auto-Formatting-in-FormFields.csproj b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Disable-Auto-Formatting-in-FormFields.csproj new file mode 100644 index 00000000..376cf186 --- /dev/null +++ b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Disable-Auto-Formatting-in-FormFields.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Disable_Auto_Formatting_in_FormFields + enable + enable + + + + + + + diff --git a/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs new file mode 100644 index 00000000..5117c625 --- /dev/null +++ b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs @@ -0,0 +1,25 @@ +using Syncfusion.Pdf.Parsing; + +// Load the existing PDF document +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)); + +// Access the form field named "email" from the PDF form +PdfLoadedField field = loadedDocument.Form.Fields["email"] as PdfLoadedField; + +// Disable automatic formatting to prevent behaviors like JavaScript execution +loadedDocument.Form.DisableAutoFormat = true; + +// Check if the field is a text box and assign a plain string value +if (field is PdfLoadedTextBoxField textBoxField) +{ + // Set the text box value to a raw email string without formatting + textBoxField.Text = "12345@gmail.com"; +} + +// Save the modified PDF document to a new file using a file stream +using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +{ + loadedDocument.Save(outputStream); +} +// Close and dispose the document to release resources +loadedDocument.Close(true); \ No newline at end of file