Skip to content

Commit 352a433

Browse files
1012852: Addressed the review changes
1 parent 6a54ccd commit 352a433

2 files changed

Lines changed: 17 additions & 94 deletions

File tree

Document-Processing/PDF/PDF-Viewer/react/annotation/flatten-annotation.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
---
22
layout: post
3-
title: Flatten Annotations Before Saving the PDF | Syncfusion
3+
title: Flatten Annotations in the Syncfusion React PDF Viewer
44
description: Learn how all about how to flatten annotations and formfields before saving a PDF in the Syncfusion React PDF Viewer.
55
platform: document-processing
66
control: PDF Viewer
77
documentation: ug
88
domainurl: ##DomainURL##
99
---
1010

11-
# Flatten Annotations Before Saving the PDF in React
11+
# Flatten Annotations in the Syncfusion React PDF Viewer
12+
13+
Flattening takes the visual appearance of annotations and embeds them into each page's content stream. The visual result remains visible, but the annotation objects and interactive form field structures are removed or converted so they can no longer be selected, edited, or filled.
14+
1215
Flattening annotations permanently merges them into the PDF content. Once flattened:
1316
- Annotations are **no longer editable** in any PDF viewer.
1417
- Useful for **secure sharing**, preventing modifications.
1518
- Ideal when **finalizing markup** before distribution.
1619

1720
## How to Flatten Annotations
1821

19-
To flatten documents when they are uploaded/loaded into the viewer, see [Flatten on Load](../document-handling/preprocess-pdf#flatten-on-load).
22+
You can flatten annotations either when a document is loaded (preprocessing) or when exporting/saving the file. Flattening on load makes the viewer display a flattened version immediately; flattening on export preserves the original viewer session while producing a flattened output file.
23+
24+
Typical export-time steps:
25+
- Save the viewer contents to a Blob.
26+
- Create a `PdfDocument` from the saved bytes.
27+
- Enable `document.flatten = true` to merge annotations and form field appearances.
28+
- Save the resulting PDF.
2029

2130
Use the example below to flatten at export time (on download).
2231

@@ -57,7 +66,8 @@ function Default() {
5766
const arrayBuffer = reader.result;
5867
const byteArray = new Uint8Array(arrayBuffer);
5968
const document = new PdfDocument(byteArray);
60-
// Flatten all annotations and form fields
69+
// Flatten all annotations and form fields: this embeds appearances
70+
// into the page content so annotations are no longer interactive.
6171
document.flatten = true;
6272
document.save('flattened.pdf');
6373
};
@@ -107,6 +117,8 @@ root.render(<Default />);
107117
{% endhighlight %}
108118
{% endtabs %}
109119

120+
N> To flatten documents when they are uploaded/loaded into the viewer, see [Flatten on Load](../document-handling/preprocess-pdf#flatten-on-load).
121+
110122

111123
## Notes
112124

Document-Processing/PDF/PDF-Viewer/react/document-handling/preprocess-pdf.md

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -197,96 +197,7 @@ root.render(<Default />);
197197
{% endhighlight %}
198198
{% endtabs %}
199199

200-
### Flatten on Download
201-
202-
Use the following code-snippet to flatten all annotations and form fields at export time, then download the flattened PDF.
203-
204-
{% tabs %}
205-
{% highlight js tabtitle="Standalone" %}
206-
{% raw %}
207-
import { createRoot } from 'react-dom/client';
208-
import './index.css';
209-
import * as React from 'react';
210-
import {
211-
PdfViewerComponent,
212-
Toolbar,
213-
Magnification,
214-
Navigation,
215-
LinkAnnotation,
216-
BookmarkView,
217-
ThumbnailView,
218-
Print,
219-
TextSelection,
220-
TextSearch,
221-
Annotation,
222-
FormFields,
223-
FormDesigner,
224-
PageOrganizer,
225-
Inject,
226-
} from '@syncfusion/ej2-react-pdfviewer';
227-
import {
228-
PdfDocument
229-
} from '@syncfusion/ej2-pdf';
230-
231-
function Default() {
232-
let viewer;
233-
234-
const flattenPdf = () => {
235-
viewer.saveAsBlob().then((value) => {
236-
const reader = new FileReader();
237-
reader.onloadend = function () {
238-
const arrayBuffer = reader.result;
239-
const byteArray = new Uint8Array(arrayBuffer);
240-
const document = new PdfDocument(byteArray);
241-
// Flatten all annotations and form fields
242-
document.flatten = true;
243-
document.save('flattened.pdf');
244-
};
245-
reader.readAsArrayBuffer(value);
246-
});
247-
};
248-
249-
return (
250-
<div>
251-
<div className="control-section">
252-
<button onClick={flattenPdf}>Flatten and download PDF</button>
253-
254-
<PdfViewerComponent
255-
ref={(scope) => { viewer = scope; }}
256-
id="container"
257-
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
258-
resourceUrl="https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib"
259-
style={{ height: '640px' }}
260-
>
261-
<Inject
262-
services={[
263-
Toolbar,
264-
Magnification,
265-
Navigation,
266-
LinkAnnotation,
267-
BookmarkView,
268-
ThumbnailView,
269-
Print,
270-
TextSelection,
271-
TextSearch,
272-
Annotation,
273-
FormFields,
274-
FormDesigner,
275-
PageOrganizer,
276-
]}
277-
/>
278-
</PdfViewerComponent>
279-
</div>
280-
</div>
281-
);
282-
}
283-
export default Default;
284-
285-
const root = createRoot(document.getElementById('sample'));
286-
root.render(<Default />);
287-
{% endraw %}
288-
{% endhighlight %}
289-
{% endtabs %}
200+
N> Refer to the [Flatten on Download](../annotation/flatten-annotation#how-to-flatten-annotations) section for more information about flattening documents on download.
290201

291202
## Add Watermark or Stamp
292203
### UI-Level Stamps

0 commit comments

Comments
 (0)