Skip to content

Commit b3b218e

Browse files
994681: Updated Import Export Form Fields
1 parent 5724ef3 commit b3b218e

File tree

2 files changed

+95
-44
lines changed

2 files changed

+95
-44
lines changed

Document-Processing/PDF/PDF-Viewer/javascript-es6/form-designer/import-export-formfields/export-formfields.md

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ documentation: ug
99

1010
# Export form data from PDF
1111

12-
The PDF Viewer provides APIs to export the values of interactive form fields from the loaded PDF. You can export to FDF, XFDF, JSON, or as a JavaScript object for custom processing.
12+
The PDF Viewer component supports exporting and importing form field data using the importFormFields, exportFormFields, and exportFormFieldsAsObject methods in the following formats:
1313

14-
Supported APIs:
15-
- exportFormFields(pathOrFileName, format)
16-
- exportFormFieldsAsObject(format) → Promise<object>
17-
18-
Note: When using the server-backed viewer, set serviceUrl before exporting.
14+
- FDF
15+
- XFDF
16+
- JSON
1917

2018
## Export as FDF
2119

20+
Using the `exportFormFields` method, the form field data can be exported in the specified data format. This method accepts two parameters:
21+
22+
* The first one must be the destination path for the exported data. If the path is not specified, it will ask for the location while exporting.
23+
* The second parameter should be the format type of the form data.
24+
25+
The following example exports and imports form field data as FDF.
26+
2227
```html
2328
<button id="exportFdf">Export FDF</button>
2429
```
@@ -32,7 +37,7 @@ const viewer = new PdfViewer({
3237
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
3338
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
3439
});
35-
viewer.appendTo('#PdfViewer');
40+
viewer.appendTo('#pdfViewer');
3641

3742
document.getElementById('exportFdf')!.addEventListener('click', () => {
3843
// Data must be the desired path or file name for the exported document.
@@ -42,53 +47,75 @@ document.getElementById('exportFdf')!.addEventListener('click', () => {
4247

4348
## Export as XFDF
4449

45-
```ts
50+
The following example exports form field data as XFDF.
51+
52+
```html
4653
<button id="exportXfdf">Export XFDF</button>
47-
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
54+
```
4855

49-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
56+
```ts
57+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
5058

51-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
59+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
5260

53-
const viewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
61+
const viewer = new PdfViewer({
62+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
63+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
64+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
65+
});
5466
viewer.appendTo('#pdfViewer');
5567

5668
document.getElementById('exportXfdf')!.addEventListener('click', () => {
69+
// Data must be the desired path or file name for the exported document.
5770
viewer.exportFormFields('FormData', FormFieldDataFormat.Xfdf);
5871
});
5972
```
6073

6174
## Export as JSON
6275

63-
```ts
76+
The following example exports form field data as JSON.
77+
78+
```html
6479
<button id="exportJson">Export JSON</button>
65-
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
80+
```
6681

67-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
82+
```ts
83+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
6884

69-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
85+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
7086

71-
const viewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
87+
const viewer = new PdfViewer({
88+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
89+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
90+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
91+
});
7292
viewer.appendTo('#pdfViewer');
7393

7494
document.getElementById('exportJson')!.addEventListener('click', () => {
95+
// Data must be the desired path or file name for the exported document.
7596
viewer.exportFormFields('FormData', FormFieldDataFormat.Json);
7697
});
7798
```
7899

79100
## Export as Object
80101

81-
Export the form data to a JavaScript object for custom persistence (database, API, or client storage).
102+
Export the form data to a JavaScript object for custom persistence (database, API, or client storage).
103+
The following example exports and imports form field data as Object.
82104

83-
```ts
105+
```html
84106
<button id="exportObj">Export Object</button>
85-
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
107+
```
86108

87-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
109+
```ts
110+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
88111

89-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
112+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
90113

91-
const viewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
114+
const viewer = new PdfViewer({
115+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
116+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
117+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
118+
});
92119
viewer.appendTo('#pdfViewer');
93120

94121
let exportedData: object | undefined;

Document-Processing/PDF/PDF-Viewer/javascript-es6/form-designer/import-export-formfields/import-formfields.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ documentation: ug
99

1010
# Import form data into PDF
1111

12-
The PDF Viewer provides APIs to import interactive form field values into the currently loaded PDF. You can import from FDF, XFDF, JSON, or a JavaScript object exported earlier.
12+
The PDF Viewer provides APIs to import interactive form field values into the currently loaded PDF. You can import from the following formats:
13+
14+
- FDF
15+
- XFDF
16+
- JSON
1317

1418
Supported API:
1519
- importFormFields(sourceOrObject, format)
@@ -18,17 +22,19 @@ Note: When using the server-backed viewer, set serviceUrl before importing.
1822

1923
## Import as FDF
2024

21-
```ts
25+
```html
2226
<button id="importFdf">Import FDF</button>
2327
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
28+
```
29+
```ts
30+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
2431

25-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
26-
27-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
32+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
2833

2934
const viewer = new PdfViewer({
30-
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf'
35+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
3136
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
37+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
3238
});
3339
viewer.appendTo('#pdfViewer');
3440

@@ -40,36 +46,48 @@ document.getElementById('importFdf')!.addEventListener('click', () => {
4046

4147
## Import as XFDF
4248

43-
```ts
49+
```html
4450
<button id="importXfdf">Import XFDF</button>
4551
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
52+
```
53+
```ts
54+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
4655

47-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
48-
49-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
56+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
5057

51-
const viewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
58+
const viewer = new PdfViewer({
59+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
60+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
61+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
62+
});
5263
viewer.appendTo('#pdfViewer');
5364

5465
document.getElementById('importXfdf')!.addEventListener('click', () => {
66+
// The file for importing should be accessible at the given path or as a file stream depending on your integration
5567
viewer.importFormFields('File', FormFieldDataFormat.Xfdf);
5668
});
5769
```
5870

5971
## Import as JSON
6072

61-
```ts
73+
```html
6274
<button id="importJson">Import JSON</button>
6375
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
76+
```
77+
```ts
78+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
6479

65-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
66-
67-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
80+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
6881

69-
const viewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
82+
const viewer = new PdfViewer({
83+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
84+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
85+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
86+
});
7087
viewer.appendTo('#pdfViewer');
7188

7289
document.getElementById('importJson')!.addEventListener('click', () => {
90+
// The file for importing should be accessible at the given path or as a file stream depending on your integration
7391
viewer.importFormFields('File', FormFieldDataFormat.Json);
7492
});
7593
```
@@ -78,16 +96,21 @@ document.getElementById('importJson')!.addEventListener('click', () => {
7896

7997
Import data previously exported with exportFormFieldsAsObject. Useful for client-side roundtrips without writing a file.
8098

81-
```ts
99+
```html
82100
<button id="exportDataAsObject">Export Object</button>
83101
<button id="importData">Import Data</button>
84102
<div id="pdfViewer" style="height: 640px; width: 100%"></div>
103+
```
104+
```ts
105+
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner } from '@syncfusion/ej2-pdfviewer';
85106

86-
import { PdfViewer, FormFieldDataFormat, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection } from '@syncfusion/ej2-pdfviewer';
87-
88-
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection);
107+
PdfViewer.Inject(Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, ThumbnailView, BookmarkView, TextSelection, FormFields, FormDesigner);
89108

90-
const viewer = new PdfViewer({ documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf' });
109+
const viewer = new PdfViewer({
110+
documentPath: 'https://cdn.syncfusion.com/content/pdf/form-designer.pdf',
111+
// serviceUrl: 'https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer/' // Server-backed
112+
resourceUrl: "https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib"
113+
});
91114
viewer.appendTo('#pdfViewer');
92115

93116
let exportedData: object | undefined;
@@ -100,6 +123,7 @@ document.getElementById('exportDataAsObject')!.addEventListener('click', () => {
100123

101124
document.getElementById('importData')!.addEventListener('click', () => {
102125
if (exportedData) {
126+
// Import the previously exported object data
103127
viewer.importFormFields(exportedData, FormFieldDataFormat.Fdf);
104128
}
105129
// Alternatives:

0 commit comments

Comments
 (0)