-
Notifications
You must be signed in to change notification settings - Fork 13
1012852: Updated flatten annotation UG #2344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
643408c
1012852: Updated flatten and control annotation visibility UG
SF4524LogeshKumar 1d8129f
1012852: Resolved CI failures
SF4524LogeshKumar 6a6bc94
1012852: Removed toggle-annotation-visibility
SF4524LogeshKumar 9848ade
1012852: Resolved CI failure
SF4524LogeshKumar 6a54ccd
1012852: Updated the Review Changes for Flatten and preprocess-pdf
SF4524LogeshKumar 352a433
1012852: Addressed the review changes
SF4524LogeshKumar b8e58c5
1012852: Resolved CI Failure
SF4524LogeshKumar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
Document-Processing/PDF/PDF-Viewer/react/annotation/flatten-annotation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| --- | ||
| layout: post | ||
| title: Flatten Annotations in the Syncfusion React PDF Viewer | ||
| description: Learn how all about how to flatten annotations and formfields before saving a PDF in the Syncfusion React PDF Viewer. | ||
| platform: document-processing | ||
| control: PDF Viewer | ||
| documentation: ug | ||
| domainurl: ##DomainURL## | ||
| --- | ||
|
|
||
| # Flatten Annotations in React PDF Viewer | ||
|
|
||
| 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. | ||
|
|
||
| Flattening annotations permanently merges them into the PDF content. Once flattened: | ||
| - Annotations are **no longer editable** in any PDF viewer. | ||
| - Useful for **secure sharing**, preventing modifications. | ||
| - Ideal when **finalizing markup** before distribution. | ||
|
|
||
| ## How to Flatten Annotations | ||
|
|
||
| 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. | ||
|
|
||
| Typical export-time steps: | ||
| - Save the viewer contents to a Blob. | ||
| - Create a `PdfDocument` from the saved bytes. | ||
| - Enable `document.flatten = true` to merge annotations and form field appearances. | ||
| - Save the resulting PDF. | ||
|
|
||
| Use the example below to flatten at export time (on download). | ||
|
|
||
| {% tabs %} | ||
| {% highlight js tabtitle="Standalone" %} | ||
| {% raw %} | ||
| import { createRoot } from 'react-dom/client'; | ||
| import './index.css'; | ||
| import * as React from 'react'; | ||
| import { | ||
| PdfViewerComponent, | ||
| Toolbar, | ||
| Magnification, | ||
| Navigation, | ||
| LinkAnnotation, | ||
| BookmarkView, | ||
| ThumbnailView, | ||
| Print, | ||
| TextSelection, | ||
| TextSearch, | ||
| Annotation, | ||
| FormFields, | ||
| FormDesigner, | ||
| PageOrganizer, | ||
| Inject, | ||
| } from '@syncfusion/ej2-react-pdfviewer'; | ||
| import { | ||
| PdfDocument | ||
| } from '@syncfusion/ej2-pdf'; | ||
|
|
||
| function Default() { | ||
| let viewer; | ||
|
|
||
| const flattenPdf = () => { | ||
| viewer.saveAsBlob().then((value) => { | ||
| const reader = new FileReader(); | ||
| reader.onloadend = function () { | ||
| const arrayBuffer = reader.result; | ||
| const byteArray = new Uint8Array(arrayBuffer); | ||
| const document = new PdfDocument(byteArray); | ||
| // Flatten all annotations and form fields: this embeds appearances | ||
| // into the page content so annotations are no longer interactive. | ||
| document.flatten = true; | ||
| document.save('flattened.pdf'); | ||
| }; | ||
| reader.readAsArrayBuffer(value); | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="control-section"> | ||
| <button onClick={flattenPdf}>Flatten and download PDF</button> | ||
|
|
||
| <PdfViewerComponent | ||
| ref={(scope) => { viewer = scope; }} | ||
| id="container" | ||
| documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf" | ||
| resourceUrl="https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib" | ||
| style={{ height: '640px' }} | ||
| > | ||
| <Inject | ||
| services={[ | ||
| Toolbar, | ||
| Magnification, | ||
| Navigation, | ||
| LinkAnnotation, | ||
| BookmarkView, | ||
| ThumbnailView, | ||
| Print, | ||
| TextSelection, | ||
| TextSearch, | ||
| Annotation, | ||
| FormFields, | ||
| FormDesigner, | ||
| PageOrganizer, | ||
| ]} | ||
| /> | ||
| </PdfViewerComponent> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| export default Default; | ||
|
|
||
| const root = createRoot(document.getElementById('sample')); | ||
| root.render(<Default />); | ||
| {% endraw %} | ||
| {% endhighlight %} | ||
| {% endtabs %} | ||
|
|
||
| N> To flatten documents when they are uploaded/loaded into the viewer, see [Flatten on Load](../document-handling/preprocess-pdf#flatten-on-load). | ||
|
|
||
|
|
||
| ## Notes | ||
|
|
||
| - Flattening applies to **all annotation types**: text markup, shapes, stamps, notes, ink, and form fields. | ||
| - Once flattened, annotations **cannot be edited or removed**. | ||
| - Use flattening **only at export time**, not during regular document interactions. | ||
|
|
||
| ## See also | ||
|
|
||
| - [Annotation Overview](../overview) | ||
| - [Annotation Types](../annotation/annotation-types/area-annotation) | ||
| - [Annotation Toolbar](../toolbar-customization/annotation-toolbar) | ||
| - [Create and Modify Annotation](../annotation/create-modify-annotation) | ||
| - [Customize Annotation](../annotation/customize-annotation) | ||
| - [Handwritten Signature](../annotation/signature-annotation) | ||
| - [Export and Import Annotation](../annotation/export-import/export-annotation) | ||
| - [Annotation Permission](../annotation/annotation-permission) | ||
| - [Annotation in Mobile View](../annotation/annotations-in-mobile-view) | ||
| - [Annotation Events](../annotation/annotation-event) | ||
| - [Annotation API](../annotation/annotations-api) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.