|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Export form data in the ASP.NET Core PDF Viewer component | Syncfusion |
| 4 | +description: Learn how to export PDF form field data (FDF, XFDF, JSON, and as an object) using the Syncfusion ASP.NET Core PDF Viewer component. |
| 5 | +platform: document-processing |
| 6 | +control: PDF Viewer |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# Export PDF Form Data from ASP.NET Core PDF Viewer |
| 11 | + |
| 12 | +The PDF Viewer allows you to export form field data in multiple formats for easy storage or integration. Supported formats: |
| 13 | + |
| 14 | +- [FDF](#export-as-fdf) |
| 15 | +- [XFDF](#export-as-xfdf) |
| 16 | +- [JSON](#export-as-json) |
| 17 | +- [JavaScript Object](#export-as-object) (for custom persistence) |
| 18 | + |
| 19 | +## Available methods |
| 20 | + |
| 21 | +- [exportFormFields](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#exportformfields)(destination?, format) — Exports data to a file in the specified format. |
| 22 | +- [exportFormFieldsAsObject](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#exportformfieldsasobject)(format) — Exports data as a JavaScript object for custom handling. |
| 23 | +- [importFormFields](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#importformfields)(sourceOrObject, format) — Import data back into the PDF. |
| 24 | + |
| 25 | +## How to export |
| 26 | + |
| 27 | +Use [exportFormFields()](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#exportformfields) with an optional destination path and the format type. |
| 28 | + |
| 29 | +### Export as FDF |
| 30 | +The following example exports form field data as FDF. |
| 31 | + |
| 32 | +{% tabs %} |
| 33 | +{% highlight cshtml tabtitle="Standalone" %} |
| 34 | +<button id="exportFdf">Export FDF</button> |
| 35 | +<div class="text-center"> |
| 36 | + <ejs-pdfviewer id="pdfviewer" style="height:640px; width:100%" resourceUrl="https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib" documentPath="https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf"> |
| 37 | + </ejs-pdfviewer> |
| 38 | +</div> |
| 39 | + |
| 40 | +<script type="text/javascript"> |
| 41 | +document.addEventListener('DOMContentLoaded', function () { |
| 42 | + var pdfviewer = document.getElementById('pdfviewer').ej2_instances[0]; |
| 43 | + document.getElementById('exportFdf').addEventListener('click', function () { |
| 44 | + if (!pdfviewer) { console.warn('PDF Viewer not ready'); return; } |
| 45 | + // Destination is optional; if omitted the browser will prompt. |
| 46 | + pdfviewer.exportFormFields('FormData', 'Fdf'); |
| 47 | + }); |
| 48 | +}); |
| 49 | +</script> |
| 50 | +{% endhighlight %} |
| 51 | +{% endtabs %} |
| 52 | + |
| 53 | +### Export as XFDF |
| 54 | +The following example exports form field data as XFDF. |
| 55 | + |
| 56 | +{% tabs %} |
| 57 | +{% highlight cshtml tabtitle="Standalone" %} |
| 58 | +<div class="text-center"> |
| 59 | + <ejs-pdfviewer id="pdfviewer" style="height:640px; width:100%" resourceUrl="https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib" documentPath="https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf"> |
| 60 | + </ejs-pdfviewer> |
| 61 | +</div> |
| 62 | + |
| 63 | +<button id="exportXfdf">Export XFDF</button> |
| 64 | + |
| 65 | +<script type="text/javascript"> |
| 66 | +document.addEventListener('DOMContentLoaded', function () { |
| 67 | + var pdfviewer = document.getElementById('pdfviewer').ej2_instances[0]; |
| 68 | + document.getElementById('exportXfdf').addEventListener('click', function () { |
| 69 | + if (!pdfviewer) { console.warn('PDF Viewer not ready'); return; } |
| 70 | + pdfviewer.exportFormFields('FormData', 'Xfdf'); |
| 71 | + }); |
| 72 | +}); |
| 73 | +</script> |
| 74 | +{% endhighlight %} |
| 75 | +{% endtabs %} |
| 76 | + |
| 77 | +### Export as JSON |
| 78 | +The following example exports form field data as JSON. |
| 79 | + |
| 80 | +{% tabs %} |
| 81 | +{% highlight cshtml tabtitle="Standalone" %} |
| 82 | +<div class="text-center"> |
| 83 | + <ejs-pdfviewer id="pdfviewer" style="height:640px; width:100%" resourceUrl="https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib" documentPath="https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf"> |
| 84 | + </ejs-pdfviewer> |
| 85 | +</div> |
| 86 | + |
| 87 | +<button id="exportJson">Export JSON</button> |
| 88 | + |
| 89 | +<script type="text/javascript"> |
| 90 | +document.addEventListener('DOMContentLoaded', function () { |
| 91 | + var pdfviewer = document.getElementById('pdfviewer').ej2_instances[0]; |
| 92 | + document.getElementById('exportJson').addEventListener('click', function () { |
| 93 | + if (!pdfviewer) { console.warn('PDF Viewer not ready'); return; } |
| 94 | + pdfviewer.exportFormFields('FormData', 'Json'); |
| 95 | + }); |
| 96 | +}); |
| 97 | +</script> |
| 98 | +{% endhighlight %} |
| 99 | +{% endtabs %} |
| 100 | + |
| 101 | +### Export as Object |
| 102 | + |
| 103 | +Use [exportFormFieldsAsObject()](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#exportformfieldsasobject) to obtain form data as a JavaScript object for database or API integration. |
| 104 | + |
| 105 | +{% tabs %} |
| 106 | +{% highlight cshtml tabtitle="Standalone" %} |
| 107 | +<div class="text-center"> |
| 108 | + <ejs-pdfviewer id="pdfviewer" style="height:640px; width:100%" resourceUrl="https://cdn.syncfusion.com/ej2/31.1.23/dist/ej2-pdfviewer-lib" documentPath="https://cdn.syncfusion.com/content/pdf/form-filling-document.pdf"> |
| 109 | + </ejs-pdfviewer> |
| 110 | +</div> |
| 111 | + |
| 112 | +<button id="exportObj">Export Object</button> |
| 113 | + |
| 114 | +<script type="text/javascript"> |
| 115 | +document.addEventListener('DOMContentLoaded', function () { |
| 116 | + var pdfviewer = document.getElementById('pdfviewer').ej2_instances[0]; |
| 117 | + var exportedData; |
| 118 | + document.getElementById('exportObj').addEventListener('click', function () { |
| 119 | + if (!pdfviewer) { console.warn('PDF Viewer not ready'); return; } |
| 120 | + pdfviewer.exportFormFieldsAsObject('Fdf').then(function (data) { |
| 121 | + exportedData = data; // Persist or send to server |
| 122 | + console.log('Exported object:', exportedData); |
| 123 | + }); |
| 124 | + // Alternatives: |
| 125 | + // pdfviewer.exportFormFieldsAsObject('Xfdf').then(...) |
| 126 | + // pdfviewer.exportFormFieldsAsObject('Json').then(...) |
| 127 | + }); |
| 128 | +}); |
| 129 | +</script> |
| 130 | +{% endhighlight %} |
| 131 | +{% endtabs %} |
| 132 | + |
| 133 | +## Common Use Cases |
| 134 | + |
| 135 | +- Save user-entered data to your server without altering the original PDF. |
| 136 | +- Export as JSON for REST API integration. |
| 137 | +- Export as FDF/XFDF for compatibility with other PDF tools. |
| 138 | +- Export as Object to merge with app state or store securely. |
| 139 | +- Automate exports after [validation](../form-validation) using [validateFormFields()](https://ej2.syncfusion.com/documentation/api/pdfviewer/index-default#validateformfields) |
| 140 | + |
| 141 | +[View Sample on GitHub](https://github.com/SyncfusionExamples/asp-core-pdf-viewer-examples) |
| 142 | + |
| 143 | +## See also |
| 144 | + |
| 145 | +- [Form Designer overview](../overview) |
| 146 | +- [Form Designer Toolbar](../../toolbar-customization/form-designer-toolbar) |
| 147 | +- [Import form fields](./import-form-fields) |
| 148 | +- [Import Export Events](./import-export-events) |
| 149 | +- [Create form fields](../overview-create-forms) |
| 150 | +- [Group form fields](../group-form-fields) |
| 151 | +- [Form validation](../form-validation) |
| 152 | +- [Add custom data to form fields](../custom-data) |
| 153 | +- [Form fields API](../form-fields-api) |
0 commit comments