diff --git a/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF.slnx b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF.slnx new file mode 100644 index 00000000..fbf0225b --- /dev/null +++ b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Data/Input.pdf b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Data/Input.pdf new file mode 100644 index 00000000..17dba6cb Binary files /dev/null and b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Data/Input.pdf differ diff --git a/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF.csproj b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF.csproj new file mode 100644 index 00000000..cbf5a4b5 --- /dev/null +++ b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Preserve_Formfields__in_the_Template_created_from_existing_PDF + enable + enable + + + + + + + diff --git a/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Program.cs b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Program.cs new file mode 100644 index 00000000..18142065 --- /dev/null +++ b/Forms/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Preserve-Formfields- in-the-Template-created-from-existing-PDF/Program.cs @@ -0,0 +1,32 @@ +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; +using System.IO; + +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); +//Flatten all form fields to make them part of the page graphics. +PdfLoadedForm loadedForm = loadedDocument.Form; +loadedForm.FlattenFields(); + +//Create a template from the first page. +PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +PdfTemplate template = loadedPage.CreateTemplate(); + +//Create the destination PDF (no page margins so the template fills it edge-to-edge). +PdfDocument newDocument = new PdfDocument(); +newDocument.PageSettings.Margins.All = 0; +PdfPage newPage = newDocument.Pages.Add(); + +//Draw the template so it fills the entire new page. +newPage.Graphics.DrawPdfTemplate( + template, + PointF.Empty, + new SizeF(newPage.Size.Width, newPage.Size.Height)); + +//Save the result. +newDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); + +//Close documents. +loadedDocument.Close(true); +newDocument.Close(true); \ No newline at end of file