# Selectively Flattening Fields w/ getFileData()

**URL:** <https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624>\
**Category:** WebViewer\
**Tags:** annotations, html, flatten, api, text\
**Created:** [September 30, 2021, 9:27am UTC](https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624 "2021-09-30T09:27:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim.fisher](https://community.apryse.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tim.fisher](https://community.apryse.com/u/tim.fisher)\
**Post date:** [September 30, 2021, 9:27am UTC](https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624/1 "2021-09-30T09:27:26Z")

</div>

**WebViewer Version:** 7.3.0

**Do you have an issue with a specific file(s)?** No.  
**Can you reproduce using one of our samples or online demos?** No.  
**Are you using the WebViewer server?** No.  
**Does the issue only happen on certain browsers?** No.  
**Is your issue related to a front-end framework?** No.  
**Is your issue related to annotations?** Yes.

**Please give a brief summary of your issue:**  
I’m unable to download a PDF file that both (1) selectively disables annotations (flattens, sets ReadOnly, etc), while (2) continuing to allow users to select the annotation text in the downloaded document.

**Please describe your issue and provide steps to reproduce it:**  
I’ve tried three approaches to this problem, with mixed success:

- [Not Successful] Using `getFileData()` per the docs [here](https://www.pdftron.com/documentation/web/guides/annotation/flatten-annotations/). While `getFileData()` has a flatten option, I don’t see any options to specify that only _some_ fields should be flattened.
- [Not Successful] Setting the `LockedContents` flag [here](https://www.pdftron.com/api/web/Core.Annotations.Annotation.html) on the desired annotations to `true`, then calling `getFileData()`. However, annotations in the downloaded file are still editable.
- [Partial Success] Setting the `ReadOnly` flag on the desired annotations to `true`, then calling getFileData(). This method successfully disabled editing the annotations in the downloaded document, but also prevents users from selecting text in the downloaded document. This is problematic for users who need to copy-paste information out of the PDF.

Any advice on how to achieve this goal?

---

<div class="post-metadata">

**Author:** ![system](https://community.apryse.com/uploads/default/original/2X/3/3f9668f121fd55acf05a2c6e06c1f927d332653a.png) [@system](https://community.apryse.com/u/system)\
**Post date:** [September 30, 2021, 9:27am UTC](https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624/2 "2021-09-30T09:27:32Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:
- [Get file data with a viewer](https://www.pdftron.com/documentation/web/guides/get-file-data-with-viewer)
- [Import/export annotations - Importing and exporting annotations using the document](https://www.pdftron.com/documentation/web/guides/annotation/import-export/document#importing-and-exporting-annotations-using-the-document)
- [Serialization / Saving PDFs using JavaScript - About saving a document](https://www.pdftron.com/documentation/web/guides/features/basics/save#about-saving-a-document)
- [Open a PDF using JavaScript - About opening a document](https://www.pdftron.com/documentation/web/guides/features/basics/open#about-opening-a-document)

APIs:
- [UI - options](https://www.pdftron.com/api/web/UI.html#options)
- [EnableAnnotations](https://www.pdftron.com/api/web/global.html#enableAnnotations)
- [Core.Tools. TextAnnotationCreateTool - Opacity](https://www.pdftron.com/api/web/Core.Tools.TextAnnotationCreateTool.html#Opacity)

Forums:
- [Error on document.getFileData](https://community.pdftron.com/t/error-on-document-getfiledata/4067/6)
- [FreeTextAnnotation crate by code when export to xfdf then reimport with getFileData got errorTypeError: Cannot convert undefined or null to object](https://community.pdftron.com/t/freetextannotation-crate-by-code-when-export-to-xfdf-then-reimport-with-getfiledata-got-errortypeerror-cannot-convert-undefined-or-null-to-object/3924/2)
- [Downloading multiple documents](https://community.pdftron.com/t/downloading-multiple-documents/3666/1)

---

<div class="post-metadata">

**Author:** ![tgordon](https://community.apryse.com/user_avatar/community.apryse.com/tgordon/32/4840_2.png) [@tgordon](https://community.apryse.com/u/tgordon)\
**Post date:** [October 1, 2021, 10:10pm UTC](https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624/3 "2021-10-01T22:10:34Z")

</div>

Hello Tim,

Welcome to the PDFTron community forum!

Have you tried the _.Locked_ property? It prevents editing and deleting but you can still select the annotation and text under the annotation.  
[https://www.pdftron.com/api/web/Core.Annotations.FreeHandAnnotation.html#Locked\_\_anchor](https://www.pdftron.com/api/web/Core.Annotations.FreeHandAnnotation.html#Locked__anchor)

Best Regards,  
Tyler Gordon  
Web Development Support Engineer  
PDFTron Systems, Inc.  
[www.pdftron.com](http://www.pdftron.com/)

---

<div class="post-metadata">

**Author:** ![tim.fisher](https://community.apryse.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tim.fisher](https://community.apryse.com/u/tim.fisher)\
**Post date:** [October 7, 2021, 9:25am UTC](https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624/4 "2021-10-07T09:25:02Z")

</div>

Hi Tyler,

I have tried the ‘Locked’ and ‘LockedContent’ flags, but the annotations are still editable in both the WebViewer and downloaded PDF File. I think I’m calling the flag setting function correctly, but perhaps you can tell me if this is wrong:

Note, this successfully sets the ReadOnly flag:  
`annotation.fieldFlags.set('ReadOnly', true)`

However, this is not causing the annotation to be locked:  
`annotation.fieldFlags.set('Locked', true);`  
`annotation.fieldFlags.set('LockedContents', true);`

Thanks!

---

<div class="post-metadata">

**Author:** ![tgordon](https://community.apryse.com/user_avatar/community.apryse.com/tgordon/32/4840_2.png) [@tgordon](https://community.apryse.com/u/tgordon)\
**Post date:** [October 7, 2021, 4:37pm UTC](https://community.apryse.com/t/selectively-flattening-fields-w-getfiledata/4624/5 "2021-10-07T16:37:37Z")

</div>

Hi Tim,

_.fieldFlags.set()_ only supports these flags (which is why only _ReadOnly_ worked): [PDFTron WebViewer Class: WidgetFlags](https://www.pdftron.com/api/web/Core.Annotations.WidgetFlags.html)

You can directly set the Locked and LockedContents property of an annotation by doing:

```auto
annotation.Locked = true;
annotation.LockedContents = true;

```

Best Regards,  
Tyler Gordon  
Web Development Support Engineer  
PDFTron Systems, Inc.  
[www.pdftron.com](http://www.pdftron.com/)
