How to programmatically flatten specific annotations while preserving custom metadata?

PDF-XChange Editor SDK for Developers

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Holly22
User
Posts: 1
Joined: Thu Jun 25, 2026 4:46 pm

How to programmatically flatten specific annotations while preserving custom metadata?

Post by Holly22 »

Hello everyone,

I'm currently working on a feature using PDF-XChange Editor SDK v10.x (C#/.NET) and have a couple of questions regarding annotation flattening.

Background

Our application allows users to create various markup annotations (such as Line, Square, and Sticky Note annotations) as well as digital signatures. In addition to the standard annotation properties, we also store some application-specific information inside each annotation by adding custom dictionary entries through the Core API.

When the document reaches a certain workflow stage, we'd like to flatten only the visual markup annotations while keeping signatures and form fields interactive.

urrent implementation

At the moment we're using:

Code: Select all

// Flatten all annotations on the specified pages
INumArray pagesToFlatten = ...;

pEditorDoc.CoreDoc.FlattenPagesAnnotations(pagesToFlatten, null, 0);
As expected, this flattens every annotation on the page.

Is there a supported way to flatten only selected annotation types (for example, Line, Square, and Text/Sticky Note) while leaving Digital Signature and Widget/Form Field annotations untouched?
If selective flattening isn't supported directly, is the recommended approach to enumerate the annotations first, remove or temporarily exclude the ones that shouldn't be flattened, and then restore them afterward?
Since the original annotation objects are removed during the flattening process, any custom dictionary entries attached to those annotations are lost as well. Is there any recommended way to preserve this custom metadata? For example:
copying it to another PDF object before flattening,
storing it at the page or document level,
or using another mechanism provided by the SDK?

I checked the API reference but couldn't find any callback or overload that allows filtering annotations during the flatten operation.

If anyone has experience with this workflow or could point me toward the recommended approach (either C# or C++ examples are welcome), I'd really appreciate it.
User avatar
MishaH
User
Posts: 32
Joined: Wed Sep 11, 2024 1:43 pm

Re: How to programmatically flatten specific annotations while preserving custom metadata?

Post by MishaH »

Hi Holly22,

Welcome to our forums!

Flattening only specific annotations
There are two possible approaches:
1) Core APIIPXC_Document::FlattenAnnotations
More details: https://sdkhelp.pdf-xchange.com/view/PX ... nnotations
It seems that the method you mentioned in your example doesn’t exist, and you probably meant this one.
Passing a page number will flatten all annotations on that page, but you can use the second parameter to provide an exact list of annotations pre‑filtered according to your criteria.
2) Editor API — operation op.annots.flatten
More details: https://sdkhelp.pdf-xchange.com/view/PX ... ts_flatten
The page contains C# usage examples, which should make it easier to achieve the desired result.
Personal recommendation: the second option is simpler. The Editor‑level operation automatically handles required updates and events that you would otherwise need to manage manually when using the Core API.

Custom data stored inside annotations
Since flattening an annotation results in adding a new XForm content item to the end of the page’s content, you could theoretically read your custom data from the annotation before flattening and then apply it to the resulting XForm afterward.
This is just a general idea — to confirm whether it will work, could you provide an example of what data you store in the annotation and how you attach it? With that, I can check whether transferring this data into the page content is feasible.

Kind regards,
Misha