You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/PDF/PDF-Library/NET/Working-with-forms.md
+130Lines changed: 130 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5101,6 +5101,136 @@ doc.Close(True)
5101
5101
5102
5102
{% endtabs %}
5103
5103
5104
+
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF).
5105
+
5106
+
## How to Preserve Form Fields While Creating a Template from an Existing PDF That Contains Form Fields
5107
+
5108
+
When you generate a `PdfTemplate` from an existing page, interactive **AcroForm** fields (textbox, checkbox, etc.) are **not copied** to the template.
5109
+
If you still need the visual appearance of those form fields in the final document, you can flatten the form using the [FlattenFields](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Parsing.PdfLoadedForm.html#Syncfusion_Pdf_Parsing_PdfLoadedForm_FlattenFields) API.
5110
+
5111
+
Please refer the code sample to flatten the form fields before saving the PDF document.
5112
+
5113
+
N> Flattening permanently removes interactivity. The resulting PDF shows the form content exactly as it appears on screen, but users can no longer edit the fields.
5114
+
5115
+
{% tabs %}
5116
+
5117
+
{% highlight c# tabtitle="C# [Cross-platform]" %}
5118
+
using Syncfusion.Drawing;
5119
+
using Syncfusion.Pdf;
5120
+
using Syncfusion.Pdf.Graphics;
5121
+
using Syncfusion.Pdf.Parsing;
5122
+
using System.IO;
5123
+
5124
+
//Open the source PDF that contains form fields.
5125
+
using FileStream fileStream = new FileStream("Form.pdf", FileMode.Open, FileAccess.Read);
5126
+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
5127
+
5128
+
//Flatten all form fields to make them part of the page graphics.
5129
+
PdfLoadedForm loadedForm = loadedDocument.Form;
5130
+
loadedForm.FlattenFields();
5131
+
5132
+
//Create a template from the first page.
5133
+
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
Using fileStream As New FileStream("Form.pdf", FileMode.Open, FileAccess.Read)
5202
+
Dim loadedDocument As New PdfLoadedDocument(fileStream)
5203
+
5204
+
'Flatten all form fields.
5205
+
Dim loadedForm As PdfLoadedForm = loadedDocument.Form
5206
+
loadedForm.FlattenFields()
5207
+
5208
+
'Create a template from the first page.
5209
+
Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage)
5210
+
Dim template As PdfTemplate = loadedPage.CreateTemplate()
5211
+
5212
+
'Create the destination PDF.
5213
+
Dim newDocument As New PdfDocument()
5214
+
newDocument.PageSettings.Margins.All = 0
5215
+
Dim newPage As PdfPage = newDocument.Pages.Add()
5216
+
5217
+
'Draw the template so it fills the entire new page.
5218
+
newPage.Graphics.DrawPdfTemplate(
5219
+
template,
5220
+
PointF.Empty,
5221
+
New SizeF(newPage.Size.Width, newPage.Size.Height))
5222
+
5223
+
'Save the result.
5224
+
newDocument.Save("Output.pdf")
5225
+
5226
+
'Close documents.
5227
+
loadedDocument.Close(True)
5228
+
newDocument.Close(True)
5229
+
End Using
5230
+
{% endhighlight %}
5231
+
5232
+
{% endtabs %}
5233
+
5104
5234
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF).
0 commit comments