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
title: Flatten PDF form fields in Angular PDF Viewer | Syncfusion
4
+
description: Learn how to flatten interactive PDF form fields before download or save-as in EJ2 Angular PDF Viewer.
5
+
platform: document-processing
6
+
control: PDF Viewer
7
+
documentation: ug
8
+
domainurl: ##DomainURL##
9
+
---
10
+
11
+
# Flatten PDF form fields in Angular
12
+
13
+
## Overview
14
+
15
+
Flattening PDF forms converts interactive fields such as textboxes, dropdowns, checkboxes, signatures, etc., into non‑editable page content. Use this when you want to protect filled data, finalize a document, or prepare it for secure sharing.
16
+
17
+
## Prerequisites
18
+
19
+
- EJ2 Angular PDF Viewer installed and configured
20
+
- Basic viewer setup completed with toolbar and page organizer services injected. For more information, see [getting started guide](../getting-started)
21
+
22
+
## Flatten forms before downloading PDF
23
+
24
+
1. Add a ViewChild to the [`PdfViewerComponent`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer) so you can access viewer APIs from event handlers.
25
+
2. Intercept the download flow using [`downloadStart`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer#downloadstart) and cancel the default flow.
26
+
3. Retrieve the viewer's blob via [`saveAsBlob()`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer#saveasblob) and convert the blob to base64.
27
+
4. Use `PdfDocument` from Syncfusion PDF Library to open the document, set `field.flatten = true` for each form field, then save.
28
+
5. For the flattening the form fields when downloading through *Save As* option in Page Organizer, repeat steps 2–4 by using [`pageOrganizerSaveAs`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer#pageorganizersaveas) event.
29
+
30
+
## Complete example
31
+
32
+
{% tabs %}
33
+
{% highlight ts tabtitle="Standalone" %}
34
+
import { Component, ViewChild } from '@angular/core';
- The downloaded or "Save As" PDF will contain the visible appearance of filled form fields as static, non-editable content.
111
+
- Form fields will no longer be interactive or editable in common PDF readers.
112
+
113
+
## Troubleshooting
114
+
115
+
- If pdfViewer is null, ensure `#pdfViewer` is present and the component has mounted before invoking [`saveAsBlob()`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer#saveasblob).
116
+
- Missing [`resourceUrl`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer#resourceurl): If viewer resources are not reachable, set [`resourceUrl`](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer#resourceurl) to the correct CDN or local path for the ej2-pdfviewer-lib.
@@ -43,6 +43,14 @@ You can select, group or ungroup, reorder, and delete form fields as needed.
43
43
**Save and Print Forms**
44
44
Designed form fields can be saved into the PDF document and printed with their appearances.
45
45
46
+
## Form Designer with UI interaction
47
+
48
+
When [Form Designer mode](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/formdesigner) is enabled in the Syncfusion [Angular PDF Viewer](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/angular/overview), a default [Form Designer user interface (UI)](https://document.syncfusion.com/demos/pdf-viewer/angular/#/tailwind3/pdfviewer/formdesigner.html) is displayed. This UI provides a built-in toolbar for adding common form fields such as text boxes, check boxes, radio buttons, drop down lists, and signature fields. Users can place fields on the PDF, select them, resize or move them, and configure their properties using the available editing options, enabling interactive form creation directly within the viewer.
For more information about creating and editing form fields in the PDF Viewer, refer to the [Form Creation](./manage-form-fields/create-form-fields) in Angular PDF Viewer documentation.
53
+
46
54
## Enable Form Designer
47
55
48
56
To enable form design features, inject the [FormDesigner](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/formdesigner) module into the PDF Viewer. After injecting the module, use the `enableFormDesigner` property or API to enable or disable the Form Designer option in the main toolbar (set to `true` to enable). Note: the standalone examples below show `enableFormDesigner` set to `false`; change this to `true` to enable form design in those samples.
@@ -100,16 +108,6 @@ export class AppComponent implements OnInit {
100
108
{% endhighlight %}
101
109
{% endtabs %}
102
110
103
-
## Form Designer UI
104
-
105
-
When [Form Designer mode](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/formdesigner) is enabled in the Syncfusion [Angular PDF Viewer](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/angular/overview), a default [Form Designer user interface (UI)](https://document.syncfusion.com/demos/pdf-viewer/angular/#/tailwind3/pdfviewer/formdesigner.html) is displayed. This UI provides a built-in toolbar for adding common form fields such as text boxes, check boxes, radio buttons, drop down lists, and signature fields. Users can place fields on the PDF, select them, resize or move them, and configure their properties using the available editing options, enabling interactive form creation directly within the viewer.
For more information about creating and editing form fields in the PDF Viewer, refer to the [Form Creation](./manage-form-fields/create-form-fields) in Angular PDF Viewer documentation.
112
-
113
111
## Form Designer Toolbar
114
112
115
113
The **Form Designer toolbar** appears at the top of the PDF Viewer and provides quick access to form field creation tools. It includes frequently used field types such as:
@@ -123,183 +121,54 @@ The **Form Designer toolbar** appears at the top of the PDF Viewer and provides
Each toolbar item allows users to place the corresponding form field by selecting the tool and clicking on the desired location in the PDF document.
124
+
#### Show or Hide the Built-in Form Designer Toolbar
127
125
128
-

126
+
The visibility of the Form Designer toolbar is controlled by the [isFormDesignerToolbarVisible()](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#isformdesignertoolbarvisible) method. This method enables the application to display or hide the Form Designer tools based on requirements. Refer to the code example [here](../toolbar-customization/form-designer-toolbar#2-show-or-hide-form-designer-toolbar-at-runtime).
129
127
130
-
Use the following code snippet to show or hide the Form Designer by injecting the Form Designer module.
128
+
- The Form Designer toolbar is shown when form design is required.
129
+
- The toolbar can be hidden to provide a cleaner viewing experience.
131
130
132
-
{% tabs %}
133
-
{% highlight ts tabtitle="Standalone" %}
134
-
import { Component, OnInit } from '@angular/core';
The Form Designer toolbar can be customized by specifying the tools to display and arranging them in the required order using the [FormDesignerToolbarItems](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/formdesignertoolbaritem) property.
178
134
179
-
ngOnInit(): void {}
180
-
}
135
+
This customization helps limit the available tools and simplify the user interface. A code example is available [here](../toolbar-customization/form-designer-toolbar#3-show-or-hide-form-designer-toolbar-items).
181
136
182
-
{% endhighlight %}
183
-
{% endtabs %}
184
-
185
-
For more information about creating and editing form fields in the PDF Viewer, refer to the [Form Creation in Angular PDF Viewer documentation](./manage-form-fields/create-form-fields).
186
-
187
-
## Show or Hide the Built-in Form Designer Toolbar
188
-
189
-
You can control the visibility of the Form Designer toolbar using the [isFormDesignerToolbarVisible()](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/index-default#isformdesignertoolbarvisible) property. This allows the application to display or hide the Form Designer tools in the PDF Viewer based on user or workflow requirements.
190
-
191
-
**Use this property to:**
192
-
- Show the Form Designer toolbar when form design is required
193
-
- Hide the toolbar to provide a cleaner viewing experience
194
-
195
-
{% tabs %}
196
-
{% highlight ts tabtitle="Standalone" %}
197
-
import { Component, ViewChild } from '@angular/core';
198
-
import { PdfViewerComponent, PdfViewerModule, ToolbarService, FormDesignerService, FormFieldsService } from '@syncfusion/ej2-angular-pdfviewer';
199
-
200
-
@Component({
201
-
selector: 'app-root',
202
-
standalone: true,
203
-
imports: [PdfViewerModule],
204
-
template: `
205
-
<button (click)="showDesigner()">Show Form Designer Toolbar</button>
206
-
<button (click)="hideDesigner()">Hide Form Designer Toolbar</button>
@ViewChild('pdfViewer') public pdfviewer!: PdfViewerComponent;
219
-
public document: string = 'https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf';
220
-
public resourceUrl: string = 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib';
221
-
222
-
showDesigner(): void {
223
-
if (this.pdfviewer) { this.pdfviewer.isFormDesignerToolbarVisible = true; }
224
-
}
225
-
hideDesigner(): void {
226
-
if (this.pdfviewer) { this.pdfviewer.isFormDesignerToolbarVisible = false; }
227
-
}
228
-
}
229
-
230
-
{% endhighlight %}
231
-
{% endtabs %}
137
+
**Key Points**
138
+
- Only the toolbar items listed are included, in the exact order specified.
139
+
- Any toolbar items not listed remain hidden, resulting in a cleaner and more focused UI.
232
140
233
-
##Customize the Built-in Form Designer Toolbar
141
+
### Adding Form Fields
234
142
235
-
You can customize the Form Designer toolbar by specifying the tools to display and arranging them in the required order using the [FormDesignerToolbarItems](https://ej2.syncfusion.com/angular/documentation/api/pdfviewer/formdesignertoolbaritem) property.
143
+
Each toolbar item in form designer toolbar allows users to place the corresponding form field by selecting the tool and clicking on the desired location in the PDF document.
236
144
237
-
This customization helps you limit the available tools and simplify the user interface.
145
+

238
146
239
-
**Key Points**
240
-
- Include only the toolbar items you need, in the exact order you specify.
241
-
- Any toolbar items not listed remain hidden, resulting in a cleaner and more focused UI.
147
+
For more information about creating form fields in the PDF Viewer, refer to the [Form Creation in Angular PDF Viewer documentation](./manage-form-fields/create-form-fields#create-form-fields-using-the-form-designer-ui).
242
148
243
-
{% tabs %}
244
-
{% highlight ts tabtitle="Standalone" %}
245
-
import { Component } from '@angular/core';
246
-
import { PdfViewerModule, ToolbarService, FormFieldsService, FormDesignerService } from '@syncfusion/ej2-angular-pdfviewer';
public document: string = 'https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf';
265
-
public resourceUrl: string = 'https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib';
266
-
public toolbarSettings: object = {
267
-
formDesignerToolbarItems: [
268
-
'TextboxTool',
269
-
'PasswordTool',
270
-
'CheckBoxTool',
271
-
'RadioButtonTool',
272
-
'DropdownTool',
273
-
'ListboxTool',
274
-
'DrawSignatureTool',
275
-
'DeleteTool',
276
-
],
277
-
};
278
-
}
151
+
Fields can be moved, resized, and edited directly in the PDF Viewer using the Form Designer.
279
152
280
-
{% endhighlight %}
281
-
{% endtabs %}
153
+
- A field is moved by selecting it and dragging it to the required position.
282
154
283
-
## Move, Resize, and Edit Form Fields
155
+
- Fields are resized using the handles displayed on the field boundary.
284
156
285
-
You can move, resize, and edit an existing form field directly in the PDF Viewer using the Form Designer.
157
+

286
158
287
-
- Move a field by selecting it and dragging it to the required position.
159
+
- Selecting a field opens the Form Field Properties popover, which allows modification of the form field and widget annotation properties. Changes are reflected immediately in the viewer and are saved when the properties popover is closed.
160
+
For more information, see Editing Form Fields
288
161
289
-
- Resize a field using the handles displayed on the field boundary.
162
+
### Edit Form Field properties
290
163
291
-

164
+
The **Properties** panel lets you customize the styles of form fields. Open the panel by selecting the **Properties** option in a field's context menu.
292
165
293
-
- Edit a field by selecting it to open the Form Field Properties popover. The popover allows modification of the form field and widget annotation properties. Changes are reflected immediately in the viewer and are saved when the properties popover is closed.
294
-
For more information, see Editing Form Fields.
166
+

295
167
296
-
## Deleting Form Fields
168
+
###Deleting Form Fields
297
169
298
-
You can remove a form field from the PDF document by selecting the field and using one of the following methods:
299
-
- Click the `Delete option` in the Form Designer UI.
300
-
- Press the `Delete key` on the keyboard after selecting the form field.
170
+
A form field is removed by selecting it and either clicking the `Delete` option in the Form Designer UI or pressing the `Delete` key on the keyboard. The selected form field and its associated widget annotation are permanently removed from the page.
301
171
302
-
The selected form field and its associated widget annotation are permanently removed from the page.
303
172
For more information, see [Deleting Form Fields](./manage-form-fields/remove-form-fields)
0 commit comments