How to set annotation id

I'm using the JavaScript PDF library to generate xfdf annotation on Nodejs, here is the code. How can I set the id of the annotation so it appear in the XFDF output? also is there API page of the JavaScript PDF library?

<freetext id="my-annotation-id" page="0" opacity="1" rect="456,272,479,282" justification="0" subject="Text Box">

import {

PdfDocument,
PdfPage,
PdfPopupAnnotation,
PdfPopupIcon,
PdfAnnotationBorder,
PdfAnnotationExportSettings,
DataFormat,
} from "@syncfusion/ej2-pdf";
import * as fs from "fs";

// Creates a new PDF document
let document: PdfDocument = new PdfDocument();
// Adds a new page to the PDF
let page: PdfPage = document.addPage();
// Creates a new popup annotation
let popup: PdfPopupAnnotation = new PdfPopupAnnotation(
"Test popup annotation",
{ x: 10, y: 40, width: 30, height: 30 },
{
author: "Syncfusion",
subject: "General",
color: { r: 255, g: 255, b: 0 },
icon: PdfPopupIcon.newParagraph,
open: true,
},
);
popup.border = new PdfAnnotationBorder({ width: 4, hRadius: 20, vRadius: 30 });
// Adds annotation to the page
page.annotations.add(popup);

let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings();
settings.dataFormat = DataFormat.xfdf;

// Saves and download the PDF document
// const data = document.save();
// fs.writeFileSync("PopupAnnotation.pdf", data);
const xfdfData = document.exportAnnotations(settings);
fs.writeFileSync("PopupAnnotation.xml", xfdfData);

// Destroy the document
document.destroy();


1 Reply 1 reply marked as answer

MV Manikandan Vellaisamy Syncfusion Team March 27, 2026 01:16 PM UTC

Hi Jackson Tong,

 

In ej2‑pdf, we can export annotations with custom entries by using the setValues(key, value) method. Any custom key–value pair added using this method will be included in the exported XFDF output.

 

For example: popup.setValues( 'id', '6f1a2c9e_3a41_4b59_8a2d_01a7e9f3c812');

 

In the exported XFDF, this custom entry (id) will appear as part of the annotation data. You can refer to the sample for a complete working example.

 

Please refer to the following links for more information:

ej2-pdf API documentation: https://ej2.syncfusion.com/documentation/api/pdf/overview

ej2-pdf-data-extract API documentation: https://ej2.syncfusion.com/documentation/api/pdf-data-extract/overview

 

Please find our Syncfusion help documentation at the following link: https://help.syncfusion.com/document-processing/pdf/pdf-library/javascript/annotations

 

Note: Although custom entries can be exported successfully, they are not supported during the annotation import process.

 

regards,

Manikandan V



Marked as answer
Loader.
Up arrow icon