{"version":3,"file":"engine-D4kRyIQz.cjs","sources":["../src/lib/pdfium/helper.ts","../src/lib/pdfium/cache.ts","../src/lib/pdfium/types/branded.ts","../src/lib/pdfium/constants/limits.ts","../src/lib/pdfium/core/memory-manager.ts","../src/lib/pdfium/engine.ts"],"sourcesContent":["import { Matrix, Rotation, Rect, Size } from '@elhalawany/models';\r\nimport { PdfiumRuntimeMethods, PdfiumModule } from '@elhalawany/pdfium';\r\n\r\n/**\r\n * Read string from WASM heap\r\n * @param wasmModule - pdfium wasm module instance\r\n * @param readChars - function to read chars\r\n * @param parseChars - function to parse chars\r\n * @param defaultLength - default length of chars that needs to read\r\n * @returns string from the heap\r\n *\r\n * @public\r\n */\r\nexport function readString(\r\n  wasmModule: PdfiumRuntimeMethods & PdfiumModule,\r\n  readChars: (buffer: number, bufferLength: number) => number,\r\n  parseChars: (buffer: number) => string,\r\n  defaultLength: number = 100,\r\n): string {\r\n  let buffer = wasmModule.wasmExports.malloc(defaultLength);\r\n  for (let i = 0; i < defaultLength; i++) {\r\n    wasmModule.HEAP8[buffer + i] = 0;\r\n  }\r\n  const actualLength = readChars(buffer, defaultLength);\r\n  let str: string;\r\n  if (actualLength > defaultLength) {\r\n    wasmModule.wasmExports.free(buffer);\r\n    buffer = wasmModule.wasmExports.malloc(actualLength);\r\n    for (let i = 0; i < actualLength; i++) {\r\n      wasmModule.HEAP8[buffer + i] = 0;\r\n    }\r\n    readChars(buffer, actualLength);\r\n    str = parseChars(buffer);\r\n  } else {\r\n    str = parseChars(buffer);\r\n  }\r\n  wasmModule.wasmExports.free(buffer);\r\n\r\n  return str;\r\n}\r\n/**\r\n * Read arraybyffer from WASM heap\r\n * @param wasmModule - pdfium wasm module instance\r\n * @param readChars - function to read chars\r\n * @returns arraybuffer from the heap\r\n *\r\n * @public\r\n */\r\nexport function readArrayBuffer(\r\n  wasmModule: PdfiumRuntimeMethods & PdfiumModule,\r\n  readChars: (buffer: number, bufferLength: number) => number,\r\n): ArrayBuffer {\r\n  const bufferSize = readChars(0, 0);\r\n\r\n  const bufferPtr = wasmModule.wasmExports.malloc(bufferSize);\r\n\r\n  readChars(bufferPtr, bufferSize);\r\n\r\n  const arrayBuffer = new ArrayBuffer(bufferSize);\r\n  const view = new DataView(arrayBuffer);\r\n\r\n  for (let i = 0; i < bufferSize; i++) {\r\n    view.setInt8(i, wasmModule.getValue(bufferPtr + i, 'i8'));\r\n  }\r\n\r\n  wasmModule.wasmExports.free(bufferPtr);\r\n\r\n  return arrayBuffer;\r\n}\r\n\r\nconst RESERVED_INFO_KEYS = new Set([\r\n  'Title',\r\n  'Author',\r\n  'Subject',\r\n  'Keywords',\r\n  'Producer',\r\n  'Creator',\r\n  'CreationDate',\r\n  'ModDate',\r\n  'Trapped',\r\n]);\r\n\r\nexport function isValidCustomKey(key: string): boolean {\r\n  // PDF Name object rules are looser than strings here, but keep it sane:\r\n  // - non-empty ASCII, no embedded NULs, avoid leading slash\r\n  if (!key || key.length > 127) return false;\r\n  if (RESERVED_INFO_KEYS.has(key)) return false;\r\n  if (key[0] === '/') return false;\r\n  // Keep ASCII-ish to avoid surprises; relax if you need.\r\n  for (let i = 0; i < key.length; i++) {\r\n    const c = key.charCodeAt(i);\r\n    if (c < 0x20 || c > 0x7e) return false;\r\n  }\r\n  return true;\r\n}\r\n\r\ninterface FormDrawParams {\r\n  startX: number;\r\n  startY: number;\r\n  formsWidth: number;\r\n  formsHeight: number;\r\n  scaleX: number;\r\n  scaleY: number;\r\n}\r\n\r\nexport function computeFormDrawParams(\r\n  matrix: Matrix,\r\n  rect: Rect,\r\n  pageSize: Size,\r\n  rotation: Rotation,\r\n): FormDrawParams {\r\n  const rectLeft = rect.origin.x;\r\n  const rectBottom = rect.origin.y;\r\n  const rectRight = rectLeft + rect.size.width;\r\n  const rectTop = rectBottom + rect.size.height;\r\n  const pageWidth = pageSize.width;\r\n  const pageHeight = pageSize.height;\r\n\r\n  // Extract the per-axis scale that the render matrix applies.\r\n  const scaleX = Math.hypot(matrix.a, matrix.b);\r\n  const scaleY = Math.hypot(matrix.c, matrix.d);\r\n  const swap = (rotation & 1) === 1;\r\n\r\n  const formsWidth = swap\r\n    ? Math.max(1, Math.round(pageHeight * scaleX))\r\n    : Math.max(1, Math.round(pageWidth * scaleX));\r\n  const formsHeight = swap\r\n    ? Math.max(1, Math.round(pageWidth * scaleY))\r\n    : Math.max(1, Math.round(pageHeight * scaleY));\r\n\r\n  let startX: number;\r\n  let startY: number;\r\n  switch (rotation) {\r\n    case Rotation.Degree0:\r\n      startX = -Math.round(rectLeft * scaleX);\r\n      startY = -Math.round(rectBottom * scaleY);\r\n      break;\r\n    case Rotation.Degree90:\r\n      startX = Math.round((rectTop - pageHeight) * scaleX);\r\n      startY = -Math.round(rectLeft * scaleY);\r\n      break;\r\n    case Rotation.Degree180:\r\n      startX = Math.round((rectRight - pageWidth) * scaleX);\r\n      startY = Math.round((rectTop - pageHeight) * scaleY);\r\n      break;\r\n    case Rotation.Degree270:\r\n      startX = -Math.round(rectBottom * scaleX);\r\n      startY = Math.round((rectRight - pageWidth) * scaleY);\r\n      break;\r\n    default:\r\n      startX = -Math.round(rectLeft * scaleX);\r\n      startY = -Math.round(rectBottom * scaleY);\r\n      break;\r\n  }\r\n\r\n  return { startX, startY, formsWidth, formsHeight, scaleX, scaleY };\r\n}\r\n","import { WrappedPdfiumModule } from '@elhalawany/pdfium';\r\n\r\nexport interface CacheConfig {\r\n  /** Time-to-live for pages in milliseconds (default: 5000ms) */\r\n  pageTtl?: number;\r\n  /** Maximum number of pages to keep in cache per document (default: 50) */\r\n  maxPagesPerDocument?: number;\r\n}\r\n\r\nconst DEFAULT_CONFIG: Required<CacheConfig> = {\r\n  pageTtl: 5000, // 5 seconds\r\n  maxPagesPerDocument: 10,\r\n};\r\n\r\nexport class PdfCache {\r\n  private readonly docs = new Map<string, DocumentContext>();\r\n  private readonly config: Required<CacheConfig>;\r\n\r\n  constructor(\r\n    private readonly pdfium: WrappedPdfiumModule,\r\n    config: CacheConfig = {},\r\n  ) {\r\n    this.config = { ...DEFAULT_CONFIG, ...config };\r\n  }\r\n\r\n  /** Open (or re-use) a document */\r\n  setDocument(id: string, filePtr: number, docPtr: number) {\r\n    let ctx = this.docs.get(id);\r\n    if (!ctx) {\r\n      ctx = new DocumentContext(filePtr, docPtr, this.pdfium, this.config);\r\n      this.docs.set(id, ctx);\r\n    }\r\n  }\r\n\r\n  /** Retrieve the DocumentContext for a given PdfDocumentObject */\r\n  getContext(docId: string): DocumentContext | undefined {\r\n    return this.docs.get(docId);\r\n  }\r\n\r\n  /** Close & fully release a document and all its pages */\r\n  closeDocument(docId: string): boolean {\r\n    const ctx = this.docs.get(docId);\r\n    if (!ctx) return false;\r\n    ctx.dispose(); // tears down pages first, then FPDF_CloseDocument, free()\r\n    this.docs.delete(docId);\r\n    return true;\r\n  }\r\n\r\n  /** Close all documents */\r\n  closeAllDocuments(): void {\r\n    for (const ctx of this.docs.values()) {\r\n      ctx.dispose();\r\n    }\r\n    this.docs.clear();\r\n  }\r\n\r\n  /** Update cache configuration for all existing documents */\r\n  updateConfig(newConfig: CacheConfig): void {\r\n    Object.assign(this.config, newConfig);\r\n    // Update config for all existing document contexts\r\n    for (const ctx of this.docs.values()) {\r\n      ctx.updateConfig(this.config);\r\n    }\r\n  }\r\n\r\n  /** Get current cache statistics */\r\n  getCacheStats(): {\r\n    documents: number;\r\n    totalPages: number;\r\n    pagesByDocument: Record<string, number>;\r\n  } {\r\n    const pagesByDocument: Record<string, number> = {};\r\n    let totalPages = 0;\r\n\r\n    for (const [docId, ctx] of this.docs.entries()) {\r\n      const pageCount = ctx.getCacheSize();\r\n      pagesByDocument[docId] = pageCount;\r\n      totalPages += pageCount;\r\n    }\r\n\r\n    return {\r\n      documents: this.docs.size,\r\n      totalPages,\r\n      pagesByDocument,\r\n    };\r\n  }\r\n}\r\n\r\nexport class DocumentContext {\r\n  private readonly pageCache: PageCache;\r\n\r\n  constructor(\r\n    public readonly filePtr: number,\r\n    public readonly docPtr: number,\r\n    pdfium: WrappedPdfiumModule,\r\n    config: Required<CacheConfig>,\r\n  ) {\r\n    this.pageCache = new PageCache(pdfium, docPtr, config);\r\n  }\r\n\r\n  /** Main accessor for pages */\r\n  acquirePage(pageIdx: number): PageContext {\r\n    return this.pageCache.acquire(pageIdx);\r\n  }\r\n\r\n  /** Scoped accessor for one-off / bulk operations */\r\n  borrowPage<T>(pageIdx: number, fn: (ctx: PageContext) => T): T {\r\n    return this.pageCache.borrowPage(pageIdx, fn);\r\n  }\r\n\r\n  /** Update cache configuration */\r\n  updateConfig(config: Required<CacheConfig>): void {\r\n    this.pageCache.updateConfig(config);\r\n  }\r\n\r\n  /** Get number of pages currently in cache */\r\n  getCacheSize(): number {\r\n    return this.pageCache.size();\r\n  }\r\n\r\n  /** Tear down all pages + this document */\r\n  dispose(): void {\r\n    // 1️⃣ release all pages (with their TTL or immediate)\r\n    this.pageCache.forceReleaseAll();\r\n\r\n    // 2️⃣ close the PDFium document\r\n    this.pageCache.pdf.FPDF_CloseDocument(this.docPtr);\r\n\r\n    // 3️⃣ free the file handle\r\n    this.pageCache.pdf.pdfium.wasmExports.free(this.filePtr);\r\n  }\r\n}\r\n\r\nexport class PageCache {\r\n  private readonly cache = new Map<number, PageContext>();\r\n  private readonly accessOrder: number[] = []; // LRU tracking\r\n  private config: Required<CacheConfig>;\r\n\r\n  constructor(\r\n    public readonly pdf: WrappedPdfiumModule,\r\n    private readonly docPtr: number,\r\n    config: Required<CacheConfig>,\r\n  ) {\r\n    this.config = config;\r\n  }\r\n\r\n  acquire(pageIdx: number): PageContext {\r\n    let ctx = this.cache.get(pageIdx);\r\n\r\n    if (!ctx) {\r\n      // Ensure we don't exceed max cache size\r\n      this.evictIfNeeded();\r\n\r\n      const pagePtr = this.pdf.FPDF_LoadPage(this.docPtr, pageIdx);\r\n      ctx = new PageContext(this.pdf, this.docPtr, pageIdx, pagePtr, this.config.pageTtl, () => {\r\n        this.cache.delete(pageIdx);\r\n        this.removeFromAccessOrder(pageIdx);\r\n      });\r\n      this.cache.set(pageIdx, ctx);\r\n    }\r\n\r\n    // Update LRU order\r\n    this.updateAccessOrder(pageIdx);\r\n\r\n    ctx.clearExpiryTimer(); // cancel any pending teardown\r\n    ctx.bumpRefCount(); // bump ref‐count\r\n    return ctx;\r\n  }\r\n\r\n  /** Helper: run a function \"scoped\" to a page.\r\n   *    – if the page was already cached  → .release() (keeps TTL logic)\r\n   *    – if the page was loaded just now → .disposeImmediate() (free right away)\r\n   */\r\n  borrowPage<T>(pageIdx: number, fn: (ctx: PageContext) => T): T {\r\n    const existed = this.cache.has(pageIdx);\r\n    const ctx = this.acquire(pageIdx);\r\n    try {\r\n      return fn(ctx);\r\n    } finally {\r\n      existed ? ctx.release() : ctx.disposeImmediate();\r\n    }\r\n  }\r\n\r\n  forceReleaseAll(): void {\r\n    for (const ctx of this.cache.values()) {\r\n      ctx.disposeImmediate();\r\n    }\r\n    this.cache.clear();\r\n    this.accessOrder.length = 0;\r\n  }\r\n\r\n  /** Update cache configuration */\r\n  updateConfig(config: Required<CacheConfig>): void {\r\n    this.config = config;\r\n\r\n    // Update TTL for all existing pages\r\n    for (const ctx of this.cache.values()) {\r\n      ctx.updateTtl(config.pageTtl);\r\n    }\r\n\r\n    // Evict pages if new max size is smaller\r\n    this.evictIfNeeded();\r\n  }\r\n\r\n  /** Get current cache size */\r\n  size(): number {\r\n    return this.cache.size;\r\n  }\r\n\r\n  /** Evict least recently used pages if cache exceeds max size */\r\n  private evictIfNeeded(): void {\r\n    while (this.cache.size >= this.config.maxPagesPerDocument) {\r\n      const lruPageIdx = this.accessOrder[0];\r\n      if (lruPageIdx !== undefined) {\r\n        const ctx = this.cache.get(lruPageIdx);\r\n        if (ctx) {\r\n          // Only evict if not currently in use (refCount === 0)\r\n          if (ctx.getRefCount() === 0) {\r\n            ctx.disposeImmediate();\r\n            // onFinalDispose callback will remove from cache and accessOrder\r\n          } else {\r\n            // If the LRU page is in use, we can't evict it\r\n            // Move to a different strategy or break to avoid infinite loop\r\n            break;\r\n          }\r\n        } else {\r\n          // Page not in cache but in access order - clean up\r\n          this.removeFromAccessOrder(lruPageIdx);\r\n        }\r\n      } else {\r\n        break;\r\n      }\r\n    }\r\n  }\r\n\r\n  /** Update the access order for LRU tracking */\r\n  private updateAccessOrder(pageIdx: number): void {\r\n    // Remove from current position\r\n    this.removeFromAccessOrder(pageIdx);\r\n    // Add to end (most recently used)\r\n    this.accessOrder.push(pageIdx);\r\n  }\r\n\r\n  /** Remove a page from the access order array */\r\n  private removeFromAccessOrder(pageIdx: number): void {\r\n    const index = this.accessOrder.indexOf(pageIdx);\r\n    if (index > -1) {\r\n      this.accessOrder.splice(index, 1);\r\n    }\r\n  }\r\n}\r\n\r\nexport class PageContext {\r\n  private refCount = 0;\r\n  private expiryTimer?: ReturnType<typeof setTimeout>;\r\n  private disposed = false;\r\n  private ttl: number;\r\n\r\n  // lazy helpers\r\n  private textPagePtr?: number;\r\n  private formInfoPtr?: number;\r\n  private formHandle?: number;\r\n\r\n  constructor(\r\n    private readonly pdf: WrappedPdfiumModule,\r\n    public readonly docPtr: number,\r\n    public readonly pageIdx: number,\r\n    public readonly pagePtr: number,\r\n    ttl: number,\r\n    private readonly onFinalDispose: () => void,\r\n  ) {\r\n    this.ttl = ttl;\r\n  }\r\n\r\n  /** Called by PageCache.acquire() */\r\n  bumpRefCount() {\r\n    if (this.disposed) throw new Error('Context already disposed');\r\n    this.refCount++;\r\n  }\r\n\r\n  /** Get current reference count */\r\n  getRefCount(): number {\r\n    return this.refCount;\r\n  }\r\n\r\n  /** Called by PageCache.acquire() */\r\n  clearExpiryTimer() {\r\n    if (this.expiryTimer) {\r\n      clearTimeout(this.expiryTimer);\r\n      this.expiryTimer = undefined;\r\n    }\r\n  }\r\n\r\n  /** Update TTL configuration */\r\n  updateTtl(newTtl: number): void {\r\n    this.ttl = newTtl;\r\n    // If there's an active timer and ref count is 0, restart with new TTL\r\n    if (this.expiryTimer && this.refCount === 0) {\r\n      this.clearExpiryTimer();\r\n      this.expiryTimer = setTimeout(() => this.disposeImmediate(), this.ttl);\r\n    }\r\n  }\r\n\r\n  /** Called by PageCache.release() internally */\r\n  release() {\r\n    if (this.disposed) return;\r\n    this.refCount--;\r\n    if (this.refCount === 0) {\r\n      // schedule the one-and-only timer for the page\r\n      this.expiryTimer = setTimeout(() => this.disposeImmediate(), this.ttl);\r\n    }\r\n  }\r\n\r\n  /** Tear down _all_ sub-pointers & the page. */\r\n  disposeImmediate() {\r\n    if (this.disposed) return;\r\n    this.disposed = true;\r\n\r\n    // Clear any pending timer\r\n    this.clearExpiryTimer();\r\n\r\n    // 2️⃣ close text-page if opened\r\n    if (this.textPagePtr !== undefined) {\r\n      this.pdf.FPDFText_ClosePage(this.textPagePtr);\r\n    }\r\n\r\n    // 3️⃣ close form-fill if opened\r\n    if (this.formHandle !== undefined) {\r\n      this.pdf.FORM_OnBeforeClosePage(this.pagePtr, this.formHandle);\r\n      this.pdf.PDFiumExt_ExitFormFillEnvironment(this.formHandle);\r\n    }\r\n    if (this.formInfoPtr !== undefined) {\r\n      this.pdf.PDFiumExt_CloseFormFillInfo(this.formInfoPtr);\r\n    }\r\n\r\n    // 4️⃣ finally close the page itself\r\n    this.pdf.FPDF_ClosePage(this.pagePtr);\r\n\r\n    // 5️⃣ remove from the cache\r\n    this.onFinalDispose();\r\n  }\r\n\r\n  // ── public helpers ──\r\n\r\n  /** Always safe: opens (once) and returns the text-page ptr. */\r\n  getTextPage(): number {\r\n    this.ensureAlive();\r\n    if (this.textPagePtr === undefined) {\r\n      this.textPagePtr = this.pdf.FPDFText_LoadPage(this.pagePtr);\r\n    }\r\n    return this.textPagePtr;\r\n  }\r\n\r\n  /** Always safe: opens (once) and returns the form-fill handle. */\r\n  getFormHandle(): number {\r\n    this.ensureAlive();\r\n    if (this.formHandle === undefined) {\r\n      this.formInfoPtr = this.pdf.PDFiumExt_OpenFormFillInfo();\r\n      this.formHandle = this.pdf.PDFiumExt_InitFormFillEnvironment(this.docPtr, this.formInfoPtr);\r\n      this.pdf.FORM_OnAfterLoadPage(this.pagePtr, this.formHandle);\r\n    }\r\n    return this.formHandle;\r\n  }\r\n\r\n  /**\r\n   * Safely execute `fn` with an annotation pointer.\r\n   * Pointer is ALWAYS closed afterwards.\r\n   */\r\n  withAnnotation<T>(annotIdx: number, fn: (annotPtr: number) => T): T {\r\n    this.ensureAlive();\r\n    const annotPtr = this.pdf.FPDFPage_GetAnnot(this.pagePtr, annotIdx);\r\n    try {\r\n      return fn(annotPtr);\r\n    } finally {\r\n      this.pdf.FPDFPage_CloseAnnot(annotPtr);\r\n    }\r\n  }\r\n\r\n  private ensureAlive() {\r\n    if (this.disposed) throw new Error('PageContext already disposed');\r\n  }\r\n}\r\n","/**\r\n * Branded types for better type safety\r\n * @public\r\n */\r\n\r\ndeclare const PointerBrand: unique symbol;\r\n\r\nexport type WasmPointer = number & { [PointerBrand]: never };\r\n\r\n// Helper functions to create branded types\r\nexport const WasmPointer = (ptr: number): WasmPointer => ptr as WasmPointer;\r\n","/**\r\n * System limits and safety thresholds for PDFium engine operations\r\n *\r\n * These limits are designed to prevent:\r\n * - Memory exhaustion\r\n * - Browser crashes\r\n * - DoS attacks\r\n * - WASM heap overflow\r\n * - Unreasonable resource usage\r\n *\r\n * @module constants/limits\r\n */\r\n\r\n/**\r\n * Memory allocation limits\r\n */\r\nexport const MEMORY_LIMITS = {\r\n  /** Maximum total memory that can be allocated (2GB) */\r\n  MAX_TOTAL_MEMORY: 2 * 1024 * 1024 * 1024,\r\n} as const;\r\n\r\n/**\r\n * All limits combined for easy access\r\n */\r\nexport const LIMITS = {\r\n  MEMORY: MEMORY_LIMITS,\r\n} as const;\r\n\r\nexport type Limits = typeof LIMITS;\r\n","import { WasmPointer } from '../types/branded';\r\nimport { LIMITS } from '../constants/limits';\r\nimport type { WrappedPdfiumModule } from '@elhalawany/pdfium';\r\nimport { Logger } from '@elhalawany/models';\r\n\r\nconst LOG_SOURCE = 'PDFiumEngine';\r\nconst LOG_CATEGORY = 'MemoryManager';\r\n\r\ninterface Allocation {\r\n  ptr: WasmPointer;\r\n  size: number;\r\n  timestamp: number;\r\n  stack?: string;\r\n}\r\n\r\nexport class MemoryManager {\r\n  private allocations = new Map<number, Allocation>();\r\n  private totalAllocated = 0;\r\n\r\n  constructor(\r\n    private pdfiumModule: WrappedPdfiumModule,\r\n    private logger: Logger,\r\n  ) {}\r\n\r\n  /**\r\n   * Allocate memory with tracking and validation\r\n   */\r\n  malloc(size: number): WasmPointer {\r\n    // Check total memory usage\r\n    if (this.totalAllocated + size > LIMITS.MEMORY.MAX_TOTAL_MEMORY) {\r\n      throw new Error(\r\n        `Total memory usage would exceed limit: ` +\r\n          `${this.totalAllocated + size} > ${LIMITS.MEMORY.MAX_TOTAL_MEMORY}`,\r\n      );\r\n    }\r\n\r\n    const ptr = this.pdfiumModule.pdfium.wasmExports.malloc(size);\r\n\r\n    if (!ptr) {\r\n      throw new Error(`Failed to allocate ${size} bytes`);\r\n    }\r\n\r\n    // Track allocation\r\n    const allocation: Allocation = {\r\n      ptr: WasmPointer(ptr),\r\n      size,\r\n      timestamp: Date.now(),\r\n      stack: this.logger.isEnabled('debug') ? new Error().stack : undefined,\r\n    };\r\n\r\n    this.allocations.set(ptr, allocation);\r\n    this.totalAllocated += size;\r\n\r\n    return WasmPointer(ptr);\r\n  }\r\n\r\n  /**\r\n   * Free memory with validation\r\n   */\r\n  free(ptr: WasmPointer): void {\r\n    const allocation = this.allocations.get(ptr);\r\n    if (!allocation) {\r\n      this.logger.warn(LOG_SOURCE, LOG_CATEGORY, `Freeing untracked pointer: ${ptr}`);\r\n    } else {\r\n      this.totalAllocated -= allocation.size;\r\n      this.allocations.delete(ptr);\r\n    }\r\n\r\n    this.pdfiumModule.pdfium.wasmExports.free(ptr);\r\n  }\r\n\r\n  /**\r\n   * Get memory statistics\r\n   */\r\n  getStats() {\r\n    return {\r\n      totalAllocated: this.totalAllocated,\r\n      allocationCount: this.allocations.size,\r\n      allocations: this.logger.isEnabled('debug') ? Array.from(this.allocations.values()) : [],\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Check for memory leaks\r\n   */\r\n  checkLeaks(): void {\r\n    if (this.allocations.size > 0) {\r\n      this.logger.warn(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `Potential memory leak: ${this.allocations.size} unfreed allocations`,\r\n      );\r\n\r\n      for (const [ptr, alloc] of this.allocations) {\r\n        this.logger.warn(LOG_SOURCE, LOG_CATEGORY, `  - ${ptr}: ${alloc.size} bytes`, alloc.stack);\r\n      }\r\n    }\r\n  }\r\n}\r\n","import {\r\n  PdfActionObject,\r\n  PdfAnnotationObject,\r\n  PdfTextRectObject,\r\n  PdfAnnotationSubtype,\r\n  PdfLinkAnnoObject,\r\n  PdfWidgetAnnoObject,\r\n  PdfLinkTarget,\r\n  PdfZoomMode,\r\n  Logger,\r\n  NoopLogger,\r\n  SearchResult,\r\n  SearchTarget,\r\n  MatchFlag,\r\n  PdfDestinationObject,\r\n  PdfBookmarkObject,\r\n  PdfDocumentObject,\r\n  PdfEngine,\r\n  PdfPageObject,\r\n  PdfActionType,\r\n  Rotation,\r\n  PDF_FORM_FIELD_FLAG,\r\n  PDF_FORM_FIELD_TYPE,\r\n  PdfWidgetAnnoOption,\r\n  PdfFileAttachmentAnnoObject,\r\n  Rect,\r\n  Size,\r\n  PdfAttachmentObject,\r\n  PdfUnsupportedAnnoObject,\r\n  PdfTextAnnoObject,\r\n  PdfSignatureObject,\r\n  PdfInkAnnoObject,\r\n  PdfInkListObject,\r\n  Position,\r\n  PdfStampAnnoObject,\r\n  PdfCircleAnnoObject,\r\n  PdfSquareAnnoObject,\r\n  PdfFreeTextAnnoObject,\r\n  PdfCaretAnnoObject,\r\n  PdfSquigglyAnnoObject,\r\n  PdfStrikeOutAnnoObject,\r\n  PdfUnderlineAnnoObject,\r\n  PdfFile,\r\n  PdfSegmentObject,\r\n  AppearanceMode,\r\n  PdfImageObject,\r\n  PdfPageObjectType,\r\n  PdfPathObject,\r\n  PdfFormObject,\r\n  PdfPolygonAnnoObject,\r\n  PdfPolylineAnnoObject,\r\n  PdfLineAnnoObject,\r\n  PdfHighlightAnnoObject,\r\n  PdfStampAnnoObjectContents,\r\n  PdfWidgetAnnoField,\r\n  PdfTransformMatrix,\r\n  FormFieldValue,\r\n  PdfErrorCode,\r\n  PdfTaskHelper,\r\n  PdfPageFlattenFlag,\r\n  PdfPageFlattenResult,\r\n  PdfTask,\r\n  PdfFileLoader,\r\n  transformRect,\r\n  SearchAllPagesResult,\r\n  PdfOpenDocumentUrlOptions,\r\n  PdfOpenDocumentBufferOptions,\r\n  PdfFileUrl,\r\n  Task,\r\n  PdfErrorReason,\r\n  TextContext,\r\n  PdfGlyphObject,\r\n  PdfPageGeometry,\r\n  PdfRun,\r\n  toIntRect,\r\n  Quad,\r\n  PdfAnnotationState,\r\n  PdfAnnotationStateModel,\r\n  quadToRect,\r\n  ImageConversionTypes,\r\n  PageTextSlice,\r\n  stripPdfUnwantedMarkers,\r\n  rectToQuad,\r\n  dateToPdfDate,\r\n  pdfDateToDate,\r\n  PdfAnnotationColorType,\r\n  PdfAnnotationBorderStyle,\r\n  flagsToNames,\r\n  PdfAnnotationFlagName,\r\n  namesToFlags,\r\n  PdfAnnotationLineEnding,\r\n  LinePoints,\r\n  LineEndings,\r\n  WebColor,\r\n  webColorToPdfColor,\r\n  PdfColor,\r\n  pdfColorToWebColor,\r\n  pdfAlphaToWebOpacity,\r\n  webOpacityToPdfAlpha,\r\n  PdfStandardFont,\r\n  PdfTextAlignment,\r\n  PdfVerticalAlignment,\r\n  AnnotationCreateContext,\r\n  ignore,\r\n  isUuidV4,\r\n  uuidV4,\r\n  PdfAnnotationIcon,\r\n  PdfPageSearchProgress,\r\n  PdfSearchAllPagesOptions,\r\n  PdfRenderPageAnnotationOptions,\r\n  PdfRedactTextOptions,\r\n  PdfFlattenPageOptions,\r\n  PdfRenderThumbnailOptions,\r\n  PdfRenderPageOptions,\r\n  PdfAnnotationsProgress,\r\n  ConvertToBlobOptions,\r\n  buildUserToDeviceMatrix,\r\n  Matrix,\r\n  PdfMetadataObject,\r\n  PdfPrintOptions,\r\n  PdfTrappedStatus,\r\n  PdfStampFit,\r\n  PdfAddAttachmentParams,\r\n} from '@elhalawany/models';\r\nimport { computeFormDrawParams, isValidCustomKey, readArrayBuffer, readString } from './helper';\r\nimport { WrappedPdfiumModule } from '@elhalawany/pdfium';\r\nimport { DocumentContext, PageContext, PdfCache } from './cache';\r\nimport { ImageDataConverter, LazyImageData } from '../converters/types';\r\nimport { MemoryManager } from './core/memory-manager';\r\nimport { WasmPointer } from './types/branded';\r\n\r\n/**\r\n * Format of bitmap\r\n */\r\nexport enum BitmapFormat {\r\n  Bitmap_Gray = 1,\r\n  Bitmap_BGR = 2,\r\n  Bitmap_BGRx = 3,\r\n  Bitmap_BGRA = 4,\r\n}\r\n\r\n/**\r\n * Pdf rendering flag\r\n */\r\nexport enum RenderFlag {\r\n  ANNOT = 0x01, // Set if annotations are to be rendered.\r\n  LCD_TEXT = 0x02, // Set if using text rendering optimized for LCD display.\r\n  NO_NATIVETEXT = 0x04, // Don't use the native text output available on some platforms\r\n  GRAYSCALE = 0x08, // Grayscale output.\r\n  DEBUG_INFO = 0x80, // Set if you want to get some debug info. Please discuss with Foxit first if you need to collect debug info.\r\n  NO_CATCH = 0x100, // Set if you don't want to catch exception.\r\n  RENDER_LIMITEDIMAGECACHE = 0x200, // Limit image cache size.\r\n  RENDER_FORCEHALFTONE = 0x400, // Always use halftone for image stretching.\r\n  PRINTING = 0x800, // Render for printing.\r\n  REVERSE_BYTE_ORDER = 0x10, // Set whether render in a reverse Byte order, this flag only.\r\n}\r\n\r\nconst LOG_SOURCE = 'PDFiumEngine';\r\nconst LOG_CATEGORY = 'Engine';\r\n\r\n/**\r\n * Context used for searching\r\n */\r\nexport interface SearchContext {\r\n  /**\r\n   * search target\r\n   */\r\n  target: SearchTarget;\r\n  /**\r\n   * current page index\r\n   */\r\n  currPageIndex: number;\r\n  /**\r\n   * index of text in the current pdf page,  -1 means reach the end\r\n   */\r\n  startIndex: number;\r\n}\r\n\r\n/**\r\n * Error code of pdfium library\r\n */\r\nexport enum PdfiumErrorCode {\r\n  Success = 0,\r\n  Unknown = 1,\r\n  File = 2,\r\n  Format = 3,\r\n  Password = 4,\r\n  Security = 5,\r\n  Page = 6,\r\n  XFALoad = 7,\r\n  XFALayout = 8,\r\n}\r\n\r\ninterface PdfiumEngineOptions<T> {\r\n  logger?: Logger;\r\n  imageDataConverter?: ImageDataConverter<T>;\r\n}\r\n\r\nexport class OffscreenCanvasError extends Error {\r\n  constructor(message: string) {\r\n    super(message);\r\n    this.name = 'OffscreenCanvasError';\r\n  }\r\n}\r\n\r\nexport const browserImageDataToBlobConverter: ImageDataConverter<Blob> = (\r\n  getImageData: LazyImageData,\r\n  imageType: ImageConversionTypes = 'image/webp',\r\n  quality?: number,\r\n): Promise<Blob> => {\r\n  // Check if we're in a browser environment\r\n  if (typeof OffscreenCanvas === 'undefined') {\r\n    return Promise.reject(\r\n      new OffscreenCanvasError(\r\n        'OffscreenCanvas is not available in this environment. ' +\r\n          'This converter is intended for browser use only. ' +\r\n          'Falling back to WASM-based image encoding.',\r\n      ),\r\n    );\r\n  }\r\n\r\n  const pdfImage = getImageData();\r\n  const imageData = new ImageData(pdfImage.data, pdfImage.width, pdfImage.height);\r\n  const off = new OffscreenCanvas(imageData.width, imageData.height);\r\n  off.getContext('2d')!.putImageData(imageData, 0, 0);\r\n  return off.convertToBlob({ type: imageType, quality });\r\n};\r\n\r\n/**\r\n * Pdf engine that based on pdfium wasm\r\n */\r\nexport class PdfiumEngine<T = Blob> implements PdfEngine<T> {\r\n  /**\r\n   * pdf documents that opened\r\n   */\r\n  private readonly cache: PdfCache;\r\n\r\n  /**\r\n   * memory manager instance\r\n   */\r\n  private readonly memoryManager: MemoryManager;\r\n\r\n  /**\r\n   * interval to check memory leaks\r\n   */\r\n  private memoryLeakCheckInterval: number | null = null;\r\n\r\n  /**\r\n   * logger instance\r\n   */\r\n  private logger: Logger;\r\n\r\n  /**\r\n   * function to convert ImageData to Blob\r\n   */\r\n  private readonly imageDataConverter: ImageDataConverter<T>;\r\n\r\n  /**\r\n   * Create an instance of PdfiumEngine\r\n   * @param wasmModule - pdfium wasm module\r\n   * @param logger - logger instance\r\n   * @param imageDataToBlobConverter - function to convert ImageData to Blob\r\n   */\r\n  constructor(\r\n    private pdfiumModule: WrappedPdfiumModule,\r\n    options: PdfiumEngineOptions<T> = {},\r\n  ) {\r\n    const {\r\n      logger = new NoopLogger(),\r\n      imageDataConverter = browserImageDataToBlobConverter as ImageDataConverter<T>,\r\n    } = options;\r\n\r\n    this.cache = new PdfCache(this.pdfiumModule);\r\n    this.logger = logger;\r\n    this.imageDataConverter = imageDataConverter;\r\n    this.memoryManager = new MemoryManager(this.pdfiumModule, this.logger);\r\n\r\n    if (this.logger.isEnabled('debug')) {\r\n      this.memoryLeakCheckInterval = setInterval(() => {\r\n        this.memoryManager.checkLeaks();\r\n      }, 10000) as unknown as number;\r\n    }\r\n  }\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.initialize}\r\n   *\r\n   * @public\r\n   */\r\n  initialize() {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'initialize');\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Initialize`, 'Begin', 'General');\r\n    this.pdfiumModule.PDFiumExt_Init();\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Initialize`, 'End', 'General');\r\n    return PdfTaskHelper.resolve(true);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.destroy}\r\n   *\r\n   * @public\r\n   */\r\n  destroy() {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'destroy');\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Destroy`, 'Begin', 'General');\r\n    this.pdfiumModule.FPDF_DestroyLibrary();\r\n    if (this.memoryLeakCheckInterval) {\r\n      clearInterval(this.memoryLeakCheckInterval);\r\n      this.memoryLeakCheckInterval = null;\r\n    }\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Destroy`, 'End', 'General');\r\n    return PdfTaskHelper.resolve(true);\r\n  }\r\n\r\n  /** Write a UTF-16LE (WIDESTRING) to wasm, call `fn(ptr)`, then free. */\r\n  private withWString<T>(value: string, fn: (ptr: number) => T): T {\r\n    // bytes = (len + 1) * 2\r\n    const length = (value.length + 1) * 2;\r\n    const ptr = this.memoryManager.malloc(length);\r\n    try {\r\n      // emscripten runtime exposes stringToUTF16\r\n      this.pdfiumModule.pdfium.stringToUTF16(value, ptr, length);\r\n      return fn(ptr);\r\n    } finally {\r\n      this.memoryManager.free(ptr);\r\n    }\r\n  }\r\n\r\n  /** Write a float[] to wasm, call `fn(ptr, count)`, then free. */\r\n  private withFloatArray<T>(\r\n    values: number[] | undefined,\r\n    fn: (ptr: number, count: number) => T,\r\n  ): T {\r\n    const arr = values ?? [];\r\n    const bytes = arr.length * 4;\r\n    const ptr = bytes ? this.memoryManager.malloc(bytes) : WasmPointer(0);\r\n    try {\r\n      if (bytes) {\r\n        for (let i = 0; i < arr.length; i++) {\r\n          this.pdfiumModule.pdfium.setValue(ptr + i * 4, arr[i], 'float');\r\n        }\r\n      }\r\n      return fn(ptr, arr.length);\r\n    } finally {\r\n      if (bytes) this.memoryManager.free(ptr);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.openDocumentUrl}\r\n   *\r\n   * @public\r\n   */\r\n  public openDocumentUrl(file: PdfFileUrl, options?: PdfOpenDocumentUrlOptions) {\r\n    const mode = options?.mode ?? 'auto';\r\n    const password = options?.password ?? '';\r\n\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentUrl called', file.url, mode);\r\n\r\n    // We'll create a task to wrap asynchronous steps\r\n    const task = PdfTaskHelper.create<PdfDocumentObject>();\r\n\r\n    // Start an async procedure\r\n    (async () => {\r\n      try {\r\n        let loadTask: PdfTask<PdfDocumentObject>;\r\n\r\n        if (mode === 'full') {\r\n          // Explicitly requested full download\r\n          this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Using full download mode');\r\n          loadTask = await this.fetchFullAndOpen(file, password);\r\n        } else if (mode === 'range-request') {\r\n          // Explicitly requested range mode\r\n          this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Using range request mode');\r\n          loadTask = await this.openDocumentWithRangeRequest(file, password);\r\n        } else {\r\n          // Auto mode: check server capability\r\n          this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Auto mode: checking server capability');\r\n          const rangeCheck = await this.checkRangeSupport(file.url);\r\n\r\n          if (rangeCheck.supportsRanges) {\r\n            this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Server supports ranges, using range request mode');\r\n            loadTask = await this.openDocumentWithRangeRequest(\r\n              file,\r\n              password,\r\n              rangeCheck.fileLength,\r\n            );\r\n          } else {\r\n            // Use cached content if available from range check\r\n            this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'Server does not support ranges, falling back to full download');\r\n            if (rangeCheck.content) {\r\n              const pdfFile: PdfFile = {\r\n                id: file.id,\r\n                name: file.name,\r\n                content: rangeCheck.content,\r\n              };\r\n              loadTask = this.openDocumentBuffer(pdfFile, { password });\r\n            } else {\r\n              loadTask = await this.fetchFullAndOpen(file, password);\r\n            }\r\n          }\r\n        }\r\n\r\n        loadTask.wait(\r\n          (doc) => task.resolve(doc),\r\n          (err) => task.reject(err.reason),\r\n        );\r\n      } catch (err) {\r\n        this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'openDocumentUrl error', err);\r\n        task.reject({\r\n          code: PdfErrorCode.Unknown,\r\n          message: String(err),\r\n        });\r\n      }\r\n    })();\r\n\r\n    return task;\r\n  }\r\n\r\n  /**\r\n   * Check if the server supports range requests:\r\n   * Sends a HEAD request and sees if 'Accept-Ranges: bytes'.\r\n   */\r\n  private async checkRangeSupport(\r\n    url: string,\r\n  ): Promise<{ supportsRanges: boolean; fileLength: number; content: ArrayBuffer | null }> {\r\n    try {\r\n      this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'checkRangeSupport', url);\r\n\r\n      // First try HEAD request\r\n      const headResponse = await fetch(url, { method: 'HEAD' });\r\n      const fileLength = headResponse.headers.get('Content-Length');\r\n      const acceptRanges = headResponse.headers.get('Accept-Ranges');\r\n\r\n      // If server explicitly supports ranges, we're done\r\n      if (acceptRanges === 'bytes') {\r\n        return {\r\n          supportsRanges: true,\r\n          fileLength: parseInt(fileLength ?? '0'),\r\n          content: null,\r\n        };\r\n      }\r\n\r\n      // Test actual range request support\r\n      const testResponse = await fetch(url, {\r\n        headers: { Range: 'bytes=0-1' },\r\n      });\r\n\r\n      // If we get 200 instead of 206, server doesn't support ranges\r\n      // Return the full content since we'll need it anyway\r\n      if (testResponse.status === 200) {\r\n        const content = await testResponse.arrayBuffer();\r\n        return {\r\n          supportsRanges: false,\r\n          fileLength: parseInt(fileLength ?? '0'),\r\n          content: content,\r\n        };\r\n      }\r\n\r\n      // 206 Partial Content indicates range support\r\n      return {\r\n        supportsRanges: testResponse.status === 206,\r\n        fileLength: parseInt(fileLength ?? '0'),\r\n        content: null,\r\n      };\r\n    } catch (e) {\r\n      this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'checkRangeSupport failed', e);\r\n      throw new Error('Failed to check range support: ' + e);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Fully fetch the file (using fetch) into an ArrayBuffer,\r\n   * then call openDocumentFromBuffer.\r\n   */\r\n  private async fetchFullAndOpen(file: PdfFileUrl, password: string) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'fetchFullAndOpen', file.url);\r\n\r\n    // 1. fetch entire PDF as array buffer\r\n    const response = await fetch(file.url);\r\n    if (!response.ok) {\r\n      throw new Error(`Could not fetch PDF: ${response.statusText}`);\r\n    }\r\n    const arrayBuf = await response.arrayBuffer();\r\n\r\n    // 2. create a PdfFile object\r\n    const pdfFile: PdfFile = {\r\n      id: file.id,\r\n      name: file.name,\r\n      content: arrayBuf,\r\n    };\r\n\r\n    // 3. call openDocumentFromBuffer (the method you already have)\r\n    //    that returns a PdfTask, but let's wrap it in a Promise\r\n    return this.openDocumentBuffer(pdfFile, { password });\r\n  }\r\n\r\n  /**\r\n   * Use your synchronous partial-loading approach:\r\n   * - In your snippet, it's done via `openDocumentFromLoader`.\r\n   * - We'll do a synchronous XHR read callback that pulls\r\n   *   the desired byte ranges.\r\n   */\r\n  private async openDocumentWithRangeRequest(\r\n    file: PdfFileUrl,\r\n    password: string,\r\n    knownFileLength?: number,\r\n  ) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentWithRangeRequest', file.url);\r\n\r\n    // We first do a HEAD or a partial fetch to get the fileLength:\r\n    const fileLength = knownFileLength ?? (await this.retrieveFileLength(file.url)).fileLength;\r\n\r\n    // 2. define the callback function used by openDocumentFromLoader\r\n    const callback = (offset: number, length: number) => {\r\n      // Perform synchronous XHR:\r\n      const xhr = new XMLHttpRequest();\r\n      xhr.open('GET', file.url, false); // note: block in the Worker\r\n      xhr.overrideMimeType('text/plain; charset=x-user-defined');\r\n      xhr.setRequestHeader('Range', `bytes=${offset}-${offset + length - 1}`);\r\n      xhr.send(null);\r\n\r\n      if (xhr.status === 206 || xhr.status === 200) {\r\n        return this.convertResponseToUint8Array(xhr.responseText);\r\n      }\r\n      throw new Error(`Range request failed with status ${xhr.status}`);\r\n    };\r\n\r\n    // 3. call `openDocumentFromLoader`\r\n    return this.openDocumentFromLoader(\r\n      {\r\n        id: file.id,\r\n        fileLength,\r\n        callback,\r\n      },\r\n      password,\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Helper to do a HEAD request or partial GET to find file length.\r\n   */\r\n  private async retrieveFileLength(url: string): Promise<{ fileLength: number }> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'retrieveFileLength', url);\r\n\r\n    // We'll do a HEAD request to get Content-Length\r\n    const resp = await fetch(url, { method: 'HEAD' });\r\n    if (!resp.ok) {\r\n      throw new Error(`Failed HEAD request for file length: ${resp.statusText}`);\r\n    }\r\n    const lenStr = resp.headers.get('Content-Length') || '0';\r\n    const fileLength = parseInt(lenStr, 10) || 0;\r\n    if (!fileLength) {\r\n      throw new Error(`Content-Length not found or zero.`);\r\n    }\r\n    return { fileLength };\r\n  }\r\n\r\n  /**\r\n   * Convert response text (x-user-defined) to a Uint8Array\r\n   * for partial data.\r\n   */\r\n  private convertResponseToUint8Array(text: string): Uint8Array {\r\n    const array = new Uint8Array(text.length);\r\n    for (let i = 0; i < text.length; i++) {\r\n      // & 0xff ensures we only get the lower 8 bits\r\n      array[i] = text.charCodeAt(i) & 0xff;\r\n    }\r\n    return array;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.openDocument}\r\n   *\r\n   * @public\r\n   */\r\n  openDocumentBuffer(file: PdfFile, options?: PdfOpenDocumentBufferOptions) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentBuffer', file, options);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, 'Begin', file.id);\r\n    const array = new Uint8Array(file.content);\r\n    const length = array.length;\r\n    const filePtr = this.memoryManager.malloc(length);\r\n    this.pdfiumModule.pdfium.HEAPU8.set(array, filePtr);\r\n\r\n    const docPtr = this.pdfiumModule.FPDF_LoadMemDocument(filePtr, length, options?.password ?? '');\r\n\r\n    if (!docPtr) {\r\n      const lastError = this.pdfiumModule.FPDF_GetLastError();\r\n      this.logger.error(LOG_SOURCE, LOG_CATEGORY, `FPDF_LoadMemDocument failed with ${lastError}`);\r\n      this.memoryManager.free(filePtr);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, 'End', file.id);\r\n\r\n      return PdfTaskHelper.reject<PdfDocumentObject>({\r\n        code: lastError,\r\n        message: `FPDF_LoadMemDocument failed`,\r\n      });\r\n    }\r\n\r\n    const pageCount = this.pdfiumModule.FPDF_GetPageCount(docPtr);\r\n\r\n    const pages: PdfPageObject[] = [];\r\n    const sizePtr = this.memoryManager.malloc(8);\r\n    for (let index = 0; index < pageCount; index++) {\r\n      const result = this.pdfiumModule.FPDF_GetPageSizeByIndexF(docPtr, index, sizePtr);\r\n      if (!result) {\r\n        const lastError = this.pdfiumModule.FPDF_GetLastError();\r\n        this.logger.error(\r\n          LOG_SOURCE,\r\n          LOG_CATEGORY,\r\n          `FPDF_GetPageSizeByIndexF failed with ${lastError}`,\r\n        );\r\n        this.memoryManager.free(sizePtr);\r\n        this.pdfiumModule.FPDF_CloseDocument(docPtr);\r\n        this.memoryManager.free(filePtr);\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, 'End', file.id);\r\n        return PdfTaskHelper.reject<PdfDocumentObject>({\r\n          code: lastError,\r\n          message: `FPDF_GetPageSizeByIndexF failed`,\r\n        });\r\n      }\r\n\r\n      const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index) as Rotation;\r\n\r\n      const page = {\r\n        index,\r\n        size: {\r\n          width: this.pdfiumModule.pdfium.getValue(sizePtr, 'float'),\r\n          height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, 'float'),\r\n        },\r\n        rotation,\r\n      };\r\n\r\n      pages.push(page);\r\n    }\r\n    this.memoryManager.free(sizePtr);\r\n\r\n    const pdfDoc: PdfDocumentObject = {\r\n      id: file.id,\r\n      name: file.name,\r\n      pageCount,\r\n      pages,\r\n    };\r\n\r\n    this.cache.setDocument(file.id, filePtr, docPtr);\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, 'End', file.id);\r\n\r\n    return PdfTaskHelper.resolve(pdfDoc);\r\n  }\r\n\r\n  openDocumentFromLoader(fileLoader: PdfFileLoader, password: string = '') {\r\n    const { fileLength, callback, ...file } = fileLoader;\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'openDocumentFromLoader', file, password);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, 'Begin', file.id);\r\n\r\n    const readBlock = (\r\n      _pThis: number, // Pointer to the FPDF_FILEACCESS structure\r\n      offset: number, // Pointer to a buffer to receive the data\r\n      pBuf: number, // Offset position from the beginning of the file\r\n      length: number, // Number of bytes to read\r\n    ): number => {\r\n      try {\r\n        this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'readBlock', offset, length, pBuf);\r\n\r\n        if (offset < 0 || offset >= fileLength) {\r\n          this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'Offset out of bounds:', offset);\r\n          return 0;\r\n        }\r\n\r\n        // Get data chunk using the callback\r\n        const data = callback(offset, length);\r\n\r\n        // Copy the data to PDFium's buffer\r\n        const dest = new Uint8Array(this.pdfiumModule.pdfium.HEAPU8.buffer, pBuf, data.length);\r\n        dest.set(data);\r\n\r\n        return data.length;\r\n      } catch (error) {\r\n        this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'ReadBlock error:', error);\r\n        return 0;\r\n      }\r\n    };\r\n\r\n    const callbackPtr = this.pdfiumModule.pdfium.addFunction(readBlock, 'iiiii');\r\n\r\n    // Create FPDF_FILEACCESS struct\r\n    const structSize = 12;\r\n    const fileAccessPtr = this.memoryManager.malloc(structSize);\r\n\r\n    // Set up struct fields\r\n    this.pdfiumModule.pdfium.setValue(fileAccessPtr, fileLength, 'i32');\r\n    this.pdfiumModule.pdfium.setValue(fileAccessPtr + 4, callbackPtr, 'i32');\r\n    this.pdfiumModule.pdfium.setValue(fileAccessPtr + 8, 0, 'i32');\r\n\r\n    // Load document\r\n    const docPtr = this.pdfiumModule.FPDF_LoadCustomDocument(fileAccessPtr, password);\r\n\r\n    if (!docPtr) {\r\n      const lastError = this.pdfiumModule.FPDF_GetLastError();\r\n      this.logger.error(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `FPDF_LoadCustomDocument failed with ${lastError}`,\r\n      );\r\n      this.memoryManager.free(fileAccessPtr);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, 'End', file.id);\r\n\r\n      return PdfTaskHelper.reject<PdfDocumentObject>({\r\n        code: lastError,\r\n        message: `FPDF_LoadCustomDocument failed`,\r\n      });\r\n    }\r\n\r\n    const pageCount = this.pdfiumModule.FPDF_GetPageCount(docPtr);\r\n\r\n    const pages: PdfPageObject[] = [];\r\n    const sizePtr = this.memoryManager.malloc(8);\r\n    for (let index = 0; index < pageCount; index++) {\r\n      const result = this.pdfiumModule.FPDF_GetPageSizeByIndexF(docPtr, index, sizePtr);\r\n      if (!result) {\r\n        const lastError = this.pdfiumModule.FPDF_GetLastError();\r\n        this.logger.error(\r\n          LOG_SOURCE,\r\n          LOG_CATEGORY,\r\n          `FPDF_GetPageSizeByIndexF failed with ${lastError}`,\r\n        );\r\n        this.memoryManager.free(sizePtr);\r\n        this.pdfiumModule.FPDF_CloseDocument(docPtr);\r\n        this.memoryManager.free(fileAccessPtr);\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, 'End', file.id);\r\n        return PdfTaskHelper.reject<PdfDocumentObject>({\r\n          code: lastError,\r\n          message: `FPDF_GetPageSizeByIndexF failed`,\r\n        });\r\n      }\r\n\r\n      const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index) as Rotation;\r\n\r\n      const page = {\r\n        index,\r\n        size: {\r\n          width: this.pdfiumModule.pdfium.getValue(sizePtr, 'float'),\r\n          height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, 'float'),\r\n        },\r\n        rotation,\r\n      };\r\n\r\n      pages.push(page);\r\n    }\r\n    this.memoryManager.free(sizePtr);\r\n\r\n    const pdfDoc: PdfDocumentObject = {\r\n      id: file.id,\r\n      name: file.name,\r\n      pageCount,\r\n      pages,\r\n    };\r\n    this.cache.setDocument(file.id, fileAccessPtr, docPtr);\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentFromLoader`, 'End', file.id);\r\n\r\n    return PdfTaskHelper.resolve(pdfDoc);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getMetadata}\r\n   *\r\n   * @public\r\n   */\r\n  getMetadata(doc: PdfDocumentObject): PdfTask<PdfMetadataObject, PdfErrorReason> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getMetadata', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetMetadata`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetMetadata`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const creationRaw = this.readMetaText(ctx.docPtr, 'CreationDate');\r\n    const modRaw = this.readMetaText(ctx.docPtr, 'ModDate');\r\n\r\n    const metadata: PdfMetadataObject = {\r\n      title: this.readMetaText(ctx.docPtr, 'Title'),\r\n      author: this.readMetaText(ctx.docPtr, 'Author'),\r\n      subject: this.readMetaText(ctx.docPtr, 'Subject'),\r\n      keywords: this.readMetaText(ctx.docPtr, 'Keywords'),\r\n      producer: this.readMetaText(ctx.docPtr, 'Producer'),\r\n      creator: this.readMetaText(ctx.docPtr, 'Creator'),\r\n      creationDate: creationRaw ? (pdfDateToDate(creationRaw) ?? null) : null,\r\n      modificationDate: modRaw ? (pdfDateToDate(modRaw) ?? null) : null,\r\n      trapped: this.getMetaTrapped(ctx.docPtr),\r\n      custom: this.readAllMeta(ctx.docPtr, true),\r\n    };\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetMetadata`, 'End', doc.id);\r\n\r\n    return PdfTaskHelper.resolve(metadata);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.setMetadata}\r\n   *\r\n   * @public\r\n   */\r\n  setMetadata(doc: PdfDocumentObject, meta: Partial<PdfMetadataObject>) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'setMetadata', doc, meta);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SetMetadata', 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SetMetadata', 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    // Field -> PDF Info key\r\n    const strMap: Array<[keyof PdfMetadataObject, string]> = [\r\n      ['title', 'Title'],\r\n      ['author', 'Author'],\r\n      ['subject', 'Subject'],\r\n      ['keywords', 'Keywords'],\r\n      ['producer', 'Producer'],\r\n      ['creator', 'Creator'],\r\n    ];\r\n\r\n    let ok = true;\r\n\r\n    // Write string fields (string|null|undefined)\r\n    for (const [field, key] of strMap) {\r\n      const v = meta[field];\r\n      if (v === undefined) continue;\r\n      const s = v === null ? null : (v as string);\r\n      if (!this.setMetaText(ctx.docPtr, key, s)) ok = false;\r\n    }\r\n\r\n    // Write date fields (Date|null|undefined)\r\n    const writeDate = (\r\n      field: 'creationDate' | 'modificationDate',\r\n      key: 'CreationDate' | 'ModDate',\r\n    ) => {\r\n      const v = meta[field];\r\n      if (v === undefined) return;\r\n      if (v === null) {\r\n        if (!this.setMetaText(ctx.docPtr, key, null)) ok = false;\r\n        return;\r\n      }\r\n      const d = v as Date;\r\n      const raw = dateToPdfDate(d);\r\n      if (!this.setMetaText(ctx.docPtr, key, raw)) ok = false;\r\n    };\r\n\r\n    writeDate('creationDate', 'CreationDate');\r\n    writeDate('modificationDate', 'ModDate');\r\n\r\n    if (meta.trapped !== undefined) {\r\n      if (!this.setMetaTrapped(ctx.docPtr, meta.trapped ?? null)) ok = false;\r\n    }\r\n\r\n    if (meta.custom !== undefined) {\r\n      for (const [key, value] of Object.entries(meta.custom)) {\r\n        if (!isValidCustomKey(key)) {\r\n          this.logger.warn(LOG_SOURCE, LOG_CATEGORY, 'Invalid custom metadata key skipped', key);\r\n          continue;\r\n        }\r\n        if (!this.setMetaText(ctx.docPtr, key, value ?? null)) ok = false;\r\n      }\r\n    }\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SetMetadata', 'End', doc.id);\r\n\r\n    return ok\r\n      ? PdfTaskHelper.resolve(true)\r\n      : PdfTaskHelper.reject({\r\n          code: PdfErrorCode.Unknown,\r\n          message: 'one or more metadata fields could not be written',\r\n        });\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getDocPermissions}\r\n   *\r\n   * @public\r\n   */\r\n  getDocPermissions(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getDocPermissions', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `getDocPermissions`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `getDocPermissions`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const permissions = this.pdfiumModule.FPDF_GetDocPermissions(ctx.docPtr);\r\n\r\n    return PdfTaskHelper.resolve(permissions);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getDocUserPermissions}\r\n   *\r\n   * @public\r\n   */\r\n  getDocUserPermissions(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getDocUserPermissions', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `getDocUserPermissions`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `getDocUserPermissions`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const permissions = this.pdfiumModule.FPDF_GetDocUserPermissions(ctx.docPtr);\r\n\r\n    return PdfTaskHelper.resolve(permissions);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getSignatures}\r\n   *\r\n   * @public\r\n   */\r\n  getSignatures(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getSignatures', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetSignatures`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetSignatures`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const signatures: PdfSignatureObject[] = [];\r\n\r\n    const count = this.pdfiumModule.FPDF_GetSignatureCount(ctx.docPtr);\r\n    for (let i = 0; i < count; i++) {\r\n      const signatureObjPtr = this.pdfiumModule.FPDF_GetSignatureObject(ctx.docPtr, i);\r\n\r\n      const contents = readArrayBuffer(this.pdfiumModule.pdfium, (buffer, bufferSize) => {\r\n        return this.pdfiumModule.FPDFSignatureObj_GetContents(signatureObjPtr, buffer, bufferSize);\r\n      });\r\n\r\n      const byteRange = readArrayBuffer(this.pdfiumModule.pdfium, (buffer, bufferSize) => {\r\n        return (\r\n          this.pdfiumModule.FPDFSignatureObj_GetByteRange(signatureObjPtr, buffer, bufferSize) * 4\r\n        );\r\n      });\r\n\r\n      const subFilter = readArrayBuffer(this.pdfiumModule.pdfium, (buffer, bufferSize) => {\r\n        return this.pdfiumModule.FPDFSignatureObj_GetSubFilter(signatureObjPtr, buffer, bufferSize);\r\n      });\r\n\r\n      const reason = readString(\r\n        this.pdfiumModule.pdfium,\r\n        (buffer, bufferLength) => {\r\n          return this.pdfiumModule.FPDFSignatureObj_GetReason(\r\n            signatureObjPtr,\r\n            buffer,\r\n            bufferLength,\r\n          );\r\n        },\r\n        this.pdfiumModule.pdfium.UTF16ToString,\r\n      );\r\n\r\n      const time = readString(\r\n        this.pdfiumModule.pdfium,\r\n        (buffer, bufferLength) => {\r\n          return this.pdfiumModule.FPDFSignatureObj_GetTime(signatureObjPtr, buffer, bufferLength);\r\n        },\r\n        this.pdfiumModule.pdfium.UTF8ToString,\r\n      );\r\n\r\n      const docMDP = this.pdfiumModule.FPDFSignatureObj_GetDocMDPPermission(signatureObjPtr);\r\n\r\n      signatures.push({\r\n        contents,\r\n        byteRange,\r\n        subFilter,\r\n        reason,\r\n        time,\r\n        docMDP,\r\n      });\r\n    }\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetSignatures`, 'End', doc.id);\r\n\r\n    return PdfTaskHelper.resolve(signatures);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getBookmarks}\r\n   *\r\n   * @public\r\n   */\r\n  getBookmarks(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getBookmarks', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetBookmarks`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `getBookmarks`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const bookmarks = this.readPdfBookmarks(ctx.docPtr, 0);\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetBookmarks`, 'End', doc.id);\r\n\r\n    return PdfTaskHelper.resolve({\r\n      bookmarks,\r\n    });\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.setBookmarks}\r\n   *\r\n   * @public\r\n   */\r\n  setBookmarks(doc: PdfDocumentObject, list: PdfBookmarkObject[]) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'setBookmarks', doc, list);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SetBookmarks`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SetBookmarks`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    // Clear any existing outlines\r\n    if (!this.pdfiumModule.EPDFBookmark_Clear(ctx.docPtr)) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SetBookmarks`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: 'failed to clear existing bookmarks',\r\n      });\r\n    }\r\n\r\n    // Recursive builder\r\n    const build = (parentPtr: number, items: PdfBookmarkObject[]): boolean => {\r\n      let prevChild = 0;\r\n      for (const item of items) {\r\n        // Create\r\n        const bmPtr = this.withWString(item.title ?? '', (wptr) =>\r\n          this.pdfiumModule.EPDFBookmark_AppendChild(ctx.docPtr, parentPtr, wptr),\r\n        );\r\n        if (!bmPtr) return false;\r\n\r\n        // Target (optional)\r\n        if (item.target) {\r\n          const ok = this.applyBookmarkTarget(ctx.docPtr, bmPtr, item.target);\r\n          if (!ok) return false;\r\n        }\r\n\r\n        // Children\r\n        if (item.children?.length) {\r\n          const ok = build(bmPtr, item.children);\r\n          if (!ok) return false;\r\n        }\r\n\r\n        prevChild = bmPtr;\r\n      }\r\n      return true;\r\n    };\r\n\r\n    const ok = build(/*top-level*/ 0, list);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SetBookmarks`, 'End', doc.id);\r\n\r\n    if (!ok) {\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: 'failed to build bookmark tree',\r\n      });\r\n    }\r\n    return PdfTaskHelper.resolve(true);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.deleteBookmarks}\r\n   *\r\n   * @public\r\n   */\r\n  deleteBookmarks(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'deleteBookmarks', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteBookmarks`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteBookmarks`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const ok = this.pdfiumModule.EPDFBookmark_Clear(ctx.docPtr);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteBookmarks`, 'End', doc.id);\r\n\r\n    return ok\r\n      ? PdfTaskHelper.resolve(true)\r\n      : PdfTaskHelper.reject({\r\n          code: PdfErrorCode.Unknown,\r\n          message: 'failed to clear bookmarks',\r\n        });\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.renderPage}\r\n   *\r\n   * @public\r\n   */\r\n  renderPage(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    options?: PdfRenderPageOptions,\r\n  ): PdfTask<T> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderPage', doc, page, options);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, 'Begin', `${doc.id}-${page.index}`);\r\n\r\n    const rect = { origin: { x: 0, y: 0 }, size: page.size };\r\n    const task = this.renderRectEncoded(doc, page, rect, options);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPage`, 'End', `${doc.id}-${page.index}`);\r\n\r\n    return task;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.renderPageRect}\r\n   *\r\n   * @public\r\n   */\r\n  renderPageRect(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    rect: Rect,\r\n    options?: PdfRenderPageOptions,\r\n  ): PdfTask<T> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderPageRect', doc, page, rect, options);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `RenderPageRect`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const task = this.renderRectEncoded(doc, page, rect, options);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderPageRect`, 'End', `${doc.id}-${page.index}`);\r\n\r\n    return task;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getAllAnnotations}\r\n   *\r\n   * @public\r\n   */\r\n  getAllAnnotations(\r\n    doc: PdfDocumentObject,\r\n  ): PdfTask<Record<number, PdfAnnotationObject[]>, PdfAnnotationsProgress> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getAllAnnotations-with-progress', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetAllAnnotations', 'Begin', doc.id);\r\n\r\n    /* 1 ── create an async task wrapper ─────────────────────────────── */\r\n    const task = PdfTaskHelper.create<\r\n      Record<number, PdfAnnotationObject[]>,\r\n      PdfAnnotationsProgress\r\n    >();\r\n\r\n    let cancelled = false;\r\n    task.wait(ignore, (err) => {\r\n      if (err.type === 'abort') cancelled = true;\r\n    });\r\n\r\n    /* 2 ── sanity-check: document must be open ──────────────────────── */\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetAllAnnotations', 'End', doc.id);\r\n      task.reject({ code: PdfErrorCode.DocNotOpen, message: 'document does not open' });\r\n      return task;\r\n    }\r\n\r\n    /* 3 ── chunked walk so we yield less often, but still breathe ───── */\r\n    const CHUNK_SIZE = 100; // ← tweak here\r\n    const out: Record<number, PdfAnnotationObject[]> = {};\r\n\r\n    const processChunk = (startIdx: number): void => {\r\n      if (cancelled) return;\r\n\r\n      const endIdx = Math.min(startIdx + CHUNK_SIZE, doc.pageCount);\r\n      for (let pageIdx = startIdx; pageIdx < endIdx && !cancelled; ++pageIdx) {\r\n        this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'GetAllAnnotations', 'Begin', doc.id, pageIdx);\r\n\r\n        /* read this page’s annotations */\r\n        const annots = this.readPageAnnotationsRaw(ctx, doc.pages[pageIdx]);\r\n        out[pageIdx] = annots;\r\n\r\n        this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'GetAllAnnotations', 'End', doc.id, pageIdx);\r\n        task.progress({ page: pageIdx, annotations: annots });\r\n      }\r\n\r\n      /* all done? */\r\n      if (cancelled) return;\r\n      if (endIdx >= doc.pageCount) {\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetAllAnnotations', 'End', doc.id);\r\n        task.resolve(out);\r\n        return;\r\n      }\r\n\r\n      /* let the browser breathe, then continue with next chunk */\r\n      setTimeout(() => processChunk(endIdx), 0);\r\n    };\r\n\r\n    /* kick-off */\r\n    processChunk(0);\r\n    return task;\r\n  }\r\n\r\n  private readAllAnnotations(\r\n    doc: PdfDocumentObject,\r\n    ctx: DocumentContext,\r\n  ): Record<number, PdfAnnotationObject[]> {\r\n    const annotationsByPage: Record<number, PdfAnnotationObject[]> = {};\r\n\r\n    for (let i = 0; i < doc.pageCount; i++) {\r\n      const pageAnnotations = this.readPageAnnotations(ctx, doc.pages[i]);\r\n      annotationsByPage[i] = pageAnnotations;\r\n    }\r\n\r\n    return annotationsByPage;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getPageAnnotations}\r\n   *\r\n   * @public\r\n   */\r\n  getPageAnnotations(doc: PdfDocumentObject, page: PdfPageObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageAnnotations', doc, page);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `GetPageAnnotations`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `GetPageAnnotations`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const annotations = this.readPageAnnotations(ctx, page);\r\n\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `GetPageAnnotations`,\r\n      'End',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    this.logger.debug(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `GetPageAnnotations`,\r\n      `${doc.id}-${page.index}`,\r\n      annotations,\r\n    );\r\n\r\n    return PdfTaskHelper.resolve(annotations);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.createPageAnnotation}\r\n   *\r\n   * @public\r\n   */\r\n  createPageAnnotation<A extends PdfAnnotationObject>(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    annotation: A,\r\n    context?: AnnotationCreateContext<A>,\r\n  ): PdfTask<string> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'createPageAnnotation', doc, page, annotation);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `CreatePageAnnotation`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `CreatePageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const annotationPtr = this.pdfiumModule.EPDFPage_CreateAnnot(pageCtx.pagePtr, annotation.type);\r\n    if (!annotationPtr) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `CreatePageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      pageCtx.release();\r\n\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantCreateAnnot,\r\n        message: 'can not create annotation with specified type',\r\n      });\r\n    }\r\n\r\n    if (!isUuidV4(annotation.id)) {\r\n      annotation.id = uuidV4();\r\n    }\r\n\r\n    if (!this.setAnnotString(annotationPtr, 'NM', annotation.id)) {\r\n      this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n      pageCtx.release();\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantSetAnnotString,\r\n        message: 'can not set the name of the annotation',\r\n      });\r\n    }\r\n\r\n    if (!this.setPageAnnoRect(page, annotationPtr, annotation.rect)) {\r\n      this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n      pageCtx.release();\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `CreatePageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantSetAnnotRect,\r\n        message: 'can not set the rect of the annotation',\r\n      });\r\n    }\r\n\r\n    let isSucceed = false;\r\n    switch (annotation.type) {\r\n      case PdfAnnotationSubtype.INK:\r\n        isSucceed = this.addInkStroke(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n      case PdfAnnotationSubtype.STAMP:\r\n        isSucceed = this.addStampContent(\r\n          ctx.docPtr,\r\n          page,\r\n          pageCtx.pagePtr,\r\n          annotationPtr,\r\n          annotation,\r\n          context?.imageData,\r\n        );\r\n        break;\r\n      case PdfAnnotationSubtype.TEXT:\r\n        isSucceed = this.addTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n      case PdfAnnotationSubtype.FREETEXT:\r\n        isSucceed = this.addFreeTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n      case PdfAnnotationSubtype.LINE:\r\n        isSucceed = this.addLineContent(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n      case PdfAnnotationSubtype.POLYLINE:\r\n      case PdfAnnotationSubtype.POLYGON:\r\n        isSucceed = this.addPolyContent(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n      case PdfAnnotationSubtype.CIRCLE:\r\n      case PdfAnnotationSubtype.SQUARE:\r\n        isSucceed = this.addShapeContent(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n      case PdfAnnotationSubtype.UNDERLINE:\r\n      case PdfAnnotationSubtype.STRIKEOUT:\r\n      case PdfAnnotationSubtype.SQUIGGLY:\r\n      case PdfAnnotationSubtype.HIGHLIGHT:\r\n        isSucceed = this.addTextMarkupContent(page, pageCtx.pagePtr, annotationPtr, annotation);\r\n        break;\r\n    }\r\n\r\n    if (!isSucceed) {\r\n      this.pdfiumModule.FPDFPage_RemoveAnnot(pageCtx.pagePtr, annotationPtr);\r\n      pageCtx.release();\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `CreatePageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantSetAnnotContent,\r\n        message: 'can not add content of the annotation',\r\n      });\r\n    }\r\n\r\n    if (annotation.blendMode !== undefined) {\r\n      this.pdfiumModule.EPDFAnnot_GenerateAppearanceWithBlend(annotationPtr, annotation.blendMode);\r\n    } else {\r\n      this.pdfiumModule.EPDFAnnot_GenerateAppearance(annotationPtr);\r\n    }\r\n\r\n    this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);\r\n\r\n    this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n    pageCtx.release();\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `CreatePageAnnotation`,\r\n      'End',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    return PdfTaskHelper.resolve<string>(annotation.id);\r\n  }\r\n\r\n  /**\r\n   * Update an existing page annotation in-place\r\n   *\r\n   *  • Locates the annot by page-local index (`annotation.id`)\r\n   *  • Re-writes its /Rect and type-specific payload\r\n   *  • Calls FPDFPage_GenerateContent so the new appearance is rendered\r\n   *\r\n   * @returns PdfTask<boolean>  –  true on success\r\n   */\r\n  updatePageAnnotation(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    annotation: PdfAnnotationObject,\r\n  ): PdfTask<boolean> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'updatePageAnnotation', doc, page, annotation);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      'UpdatePageAnnotation',\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        'UpdatePageAnnotation',\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);\r\n    if (!annotPtr) {\r\n      pageCtx.release();\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        'UpdatePageAnnotation',\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'annotation not found' });\r\n    }\r\n\r\n    /* 1 ── (re)set bounding-box ────────────────────────────────────────────── */\r\n    if (!this.setPageAnnoRect(page, annotPtr, annotation.rect)) {\r\n      this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);\r\n      pageCtx.release();\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        'UpdatePageAnnotation',\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantSetAnnotRect,\r\n        message: 'failed to move annotation',\r\n      });\r\n    }\r\n\r\n    /* 2 ── wipe previous payload and rebuild fresh one ─────────────────────── */\r\n    let ok = false;\r\n    switch (annotation.type) {\r\n      /* ── Ink ─────────────────────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.INK: {\r\n        /* clear every existing stroke first */\r\n        if (!this.pdfiumModule.FPDFAnnot_RemoveInkList(annotPtr)) break;\r\n        ok = this.addInkStroke(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Stamp ───────────────────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.STAMP: {\r\n        ok = this.addStampContent(ctx.docPtr, page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      case PdfAnnotationSubtype.TEXT: {\r\n        ok = this.addTextContent(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Free text ────────────────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.FREETEXT: {\r\n        ok = this.addFreeTextContent(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Shape ───────────────────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.CIRCLE:\r\n      case PdfAnnotationSubtype.SQUARE: {\r\n        ok = this.addShapeContent(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Line ─────────────────────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.LINE: {\r\n        ok = this.addLineContent(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Polygon / Polyline ───────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.POLYGON:\r\n      case PdfAnnotationSubtype.POLYLINE: {\r\n        ok = this.addPolyContent(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Text-markup family ──────────────────────────────────────────────── */\r\n      case PdfAnnotationSubtype.HIGHLIGHT:\r\n      case PdfAnnotationSubtype.UNDERLINE:\r\n      case PdfAnnotationSubtype.STRIKEOUT:\r\n      case PdfAnnotationSubtype.SQUIGGLY: {\r\n        /* replace quad-points / colour / strings in one go */\r\n        ok = this.addTextMarkupContent(page, pageCtx.pagePtr, annotPtr, annotation);\r\n        break;\r\n      }\r\n\r\n      /* ── Unsupported edits – fall through to error ───────────────────────── */\r\n      default:\r\n        ok = false;\r\n    }\r\n\r\n    /* 3 ── regenerate appearance if payload was changed ───────────────────── */\r\n    if (ok) {\r\n      if (annotation.blendMode !== undefined) {\r\n        this.pdfiumModule.EPDFAnnot_GenerateAppearanceWithBlend(annotPtr, annotation.blendMode);\r\n      } else {\r\n        this.pdfiumModule.EPDFAnnot_GenerateAppearance(annotPtr);\r\n      }\r\n      this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);\r\n    }\r\n\r\n    /* 4 ── tidy-up native handles ──────────────────────────────────────────── */\r\n    this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);\r\n    pageCtx.release();\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      'UpdatePageAnnotation',\r\n      'End',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    return ok\r\n      ? PdfTaskHelper.resolve<boolean>(true)\r\n      : PdfTaskHelper.reject<boolean>({\r\n          code: PdfErrorCode.CantSetAnnotContent,\r\n          message: 'failed to update annotation',\r\n        });\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.removePageAnnotation}\r\n   *\r\n   * @public\r\n   */\r\n  removePageAnnotation(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    annotation: PdfAnnotationObject,\r\n  ) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'removePageAnnotation', doc, page, annotation);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `RemovePageAnnotation`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `RemovePageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    let result = false;\r\n    result = this.removeAnnotationByName(pageCtx.pagePtr, annotation.id);\r\n    if (!result) {\r\n      this.logger.error(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `FPDFPage_RemoveAnnot Failed`,\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n    } else {\r\n      result = this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);\r\n      if (!result) {\r\n        this.logger.error(\r\n          LOG_SOURCE,\r\n          LOG_CATEGORY,\r\n          `FPDFPage_GenerateContent Failed`,\r\n          `${doc.id}-${page.index}`,\r\n        );\r\n      }\r\n    }\r\n\r\n    pageCtx.release();\r\n\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `RemovePageAnnotation`,\r\n      'End',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n    return PdfTaskHelper.resolve(result);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getPageTextRects}\r\n   *\r\n   * @public\r\n   */\r\n  getPageTextRects(doc: PdfDocumentObject, page: PdfPageObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageTextRects', doc, page);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `GetPageTextRects`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `GetPageTextRects`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const textPagePtr = this.pdfiumModule.FPDFText_LoadPage(pageCtx.pagePtr);\r\n\r\n    const textRects = this.readPageTextRects(page, pageCtx.docPtr, pageCtx.pagePtr, textPagePtr);\r\n\r\n    this.pdfiumModule.FPDFText_ClosePage(textPagePtr);\r\n    pageCtx.release();\r\n\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `GetPageTextRects`,\r\n      'End',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n    return PdfTaskHelper.resolve(textRects);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.renderThumbnail}\r\n   *\r\n   * @public\r\n   */\r\n  renderThumbnail(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    options?: PdfRenderThumbnailOptions,\r\n  ): PdfTask<T> {\r\n    const { scaleFactor = 1, ...rest } = options ?? {};\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'renderThumbnail', doc, page, options);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `RenderThumbnail`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `RenderThumbnail`,\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const result = this.renderPage(doc, page, {\r\n      scaleFactor: Math.max(scaleFactor, 0.5),\r\n      ...rest,\r\n    });\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `RenderThumbnail`, 'End', `${doc.id}-${page.index}`);\r\n\r\n    return result;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getAttachments}\r\n   *\r\n   * @public\r\n   */\r\n  getAttachments(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getAttachments', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetAttachments`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetAttachments`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const attachments: PdfAttachmentObject[] = [];\r\n\r\n    const count = this.pdfiumModule.FPDFDoc_GetAttachmentCount(ctx.docPtr);\r\n    for (let i = 0; i < count; i++) {\r\n      const attachment = this.readPdfAttachment(ctx.docPtr, i);\r\n      attachments.push(attachment);\r\n    }\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetAttachments`, 'End', doc.id);\r\n    return PdfTaskHelper.resolve(attachments);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.addAttachment}\r\n   *\r\n   * @public\r\n   */\r\n  addAttachment(doc: PdfDocumentObject, params: PdfAddAttachmentParams): PdfTask<boolean> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'addAttachment', doc, params?.name);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const { name, description, mimeType, data } = params ?? {};\r\n    if (!name) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.NotFound,\r\n        message: 'attachment name is required',\r\n      });\r\n    }\r\n    if (!data || (data instanceof Uint8Array ? data.byteLength === 0 : data.byteLength === 0)) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.NotFound,\r\n        message: 'attachment data is empty',\r\n      });\r\n    }\r\n\r\n    // 1) Create the attachment handle (also inserts into the EmbeddedFiles name tree).\r\n    const attachmentPtr = this.withWString(name, (wNamePtr) =>\r\n      this.pdfiumModule.FPDFDoc_AddAttachment(ctx.docPtr, wNamePtr),\r\n    );\r\n\r\n    if (!attachmentPtr) {\r\n      // Most likely: duplicate name in the name tree.\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: `An attachment named \"${name}\" already exists`,\r\n      });\r\n    }\r\n\r\n    this.withWString(description, (wDescriptionPtr) =>\r\n      this.pdfiumModule.EPDFAttachment_SetDescription(attachmentPtr, wDescriptionPtr),\r\n    );\r\n\r\n    this.pdfiumModule.EPDFAttachment_SetSubtype(attachmentPtr, mimeType);\r\n\r\n    // 3) Copy data into WASM memory and call SetFile (this stores bytes and fills Size/CreationDate/CheckSum)\r\n    const u8 = data instanceof Uint8Array ? data : new Uint8Array(data);\r\n    const len = u8.byteLength;\r\n\r\n    const contentPtr = this.memoryManager.malloc(len);\r\n    try {\r\n      this.pdfiumModule.pdfium.HEAPU8.set(u8, contentPtr);\r\n      const ok = this.pdfiumModule.FPDFAttachment_SetFile(\r\n        attachmentPtr,\r\n        ctx.docPtr,\r\n        contentPtr,\r\n        len,\r\n      );\r\n      if (!ok) {\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'End', doc.id);\r\n        return PdfTaskHelper.reject({\r\n          code: PdfErrorCode.Unknown,\r\n          message: 'failed to write attachment bytes',\r\n        });\r\n      }\r\n    } finally {\r\n      this.memoryManager.free(contentPtr);\r\n    }\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `AddAttachment`, 'End', doc.id);\r\n    return PdfTaskHelper.resolve<boolean>(true);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.removeAttachment}\r\n   *\r\n   * @public\r\n   */\r\n  removeAttachment(doc: PdfDocumentObject, attachment: PdfAttachmentObject): PdfTask<boolean> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'deleteAttachment', doc, attachment);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteAttachment`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteAttachment`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const count = this.pdfiumModule.FPDFDoc_GetAttachmentCount(ctx.docPtr);\r\n    if (attachment.index < 0 || attachment.index >= count) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteAttachment`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: `attachment index ${attachment.index} out of range`,\r\n      });\r\n    }\r\n\r\n    const ok = this.pdfiumModule.FPDFDoc_DeleteAttachment(ctx.docPtr, attachment.index);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `DeleteAttachment`, 'End', doc.id);\r\n\r\n    if (!ok) {\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: 'failed to delete attachment',\r\n      });\r\n    }\r\n    return PdfTaskHelper.resolve<boolean>(true);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.readAttachmentContent}\r\n   *\r\n   * @public\r\n   */\r\n  readAttachmentContent(doc: PdfDocumentObject, attachment: PdfAttachmentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'readAttachmentContent', doc, attachment);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ReadAttachmentContent`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ReadAttachmentContent`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const attachmentPtr = this.pdfiumModule.FPDFDoc_GetAttachment(ctx.docPtr, attachment.index);\r\n    const sizePtr = this.memoryManager.malloc(4);\r\n    if (!this.pdfiumModule.FPDFAttachment_GetFile(attachmentPtr, 0, 0, sizePtr)) {\r\n      this.memoryManager.free(sizePtr);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ReadAttachmentContent`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantReadAttachmentSize,\r\n        message: 'can not read attachment size',\r\n      });\r\n    }\r\n    const size = this.pdfiumModule.pdfium.getValue(sizePtr, 'i32') >>> 0;\r\n\r\n    const contentPtr = this.memoryManager.malloc(size);\r\n    if (!this.pdfiumModule.FPDFAttachment_GetFile(attachmentPtr, contentPtr, size, sizePtr)) {\r\n      this.memoryManager.free(sizePtr);\r\n      this.memoryManager.free(contentPtr);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ReadAttachmentContent`, 'End', doc.id);\r\n\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantReadAttachmentContent,\r\n        message: 'can not read attachment content',\r\n      });\r\n    }\r\n\r\n    const buffer = new ArrayBuffer(size);\r\n    const view = new DataView(buffer);\r\n    for (let i = 0; i < size; i++) {\r\n      view.setInt8(i, this.pdfiumModule.pdfium.getValue(contentPtr + i, 'i8'));\r\n    }\r\n\r\n    this.memoryManager.free(sizePtr);\r\n    this.memoryManager.free(contentPtr);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ReadAttachmentContent`, 'End', doc.id);\r\n\r\n    return PdfTaskHelper.resolve(buffer);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.setFormFieldValue}\r\n   *\r\n   * @public\r\n   */\r\n  setFormFieldValue(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    annotation: PdfWidgetAnnoObject,\r\n    value: FormFieldValue,\r\n  ) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'SetFormFieldValue', doc, annotation, value);\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `SetFormFieldValue`,\r\n      'Begin',\r\n      `${doc.id}-${annotation.id}`,\r\n    );\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'SetFormFieldValue', 'document is not opened');\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `SetFormFieldValue`,\r\n        'End',\r\n        `${doc.id}-${annotation.id}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const formFillInfoPtr = this.pdfiumModule.PDFiumExt_OpenFormFillInfo();\r\n    const formHandle = this.pdfiumModule.PDFiumExt_InitFormFillEnvironment(\r\n      ctx.docPtr,\r\n      formFillInfoPtr,\r\n    );\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n\r\n    this.pdfiumModule.FORM_OnAfterLoadPage(pageCtx.pagePtr, formHandle);\r\n\r\n    const annotationPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);\r\n\r\n    if (!annotationPtr) {\r\n      pageCtx.release();\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        'SetFormFieldValue',\r\n        'End',\r\n        `${doc.id}-${page.index}`,\r\n      );\r\n      return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'annotation not found' });\r\n    }\r\n\r\n    if (!this.pdfiumModule.FORM_SetFocusedAnnot(formHandle, annotationPtr)) {\r\n      this.logger.debug(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        'SetFormFieldValue',\r\n        'failed to set focused annotation',\r\n      );\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `SetFormFieldValue`,\r\n        'End',\r\n        `${doc.id}-${annotation.id}`,\r\n      );\r\n      this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n      this.pdfiumModule.FORM_OnBeforeClosePage(pageCtx.pagePtr, formHandle);\r\n      pageCtx.release();\r\n      this.pdfiumModule.PDFiumExt_ExitFormFillEnvironment(formHandle);\r\n      this.pdfiumModule.PDFiumExt_CloseFormFillInfo(formFillInfoPtr);\r\n\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantFocusAnnot,\r\n        message: 'failed to set focused annotation',\r\n      });\r\n    }\r\n\r\n    switch (value.kind) {\r\n      case 'text':\r\n        {\r\n          if (!this.pdfiumModule.FORM_SelectAllText(formHandle, pageCtx.pagePtr)) {\r\n            this.logger.debug(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              'SetFormFieldValue',\r\n              'failed to select all text',\r\n            );\r\n            this.logger.perf(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              `SetFormFieldValue`,\r\n              'End',\r\n              `${doc.id}-${annotation.id}`,\r\n            );\r\n            this.pdfiumModule.FORM_ForceToKillFocus(formHandle);\r\n            this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n            this.pdfiumModule.FORM_OnBeforeClosePage(pageCtx.pagePtr, formHandle);\r\n            pageCtx.release();\r\n            this.pdfiumModule.PDFiumExt_ExitFormFillEnvironment(formHandle);\r\n            this.pdfiumModule.PDFiumExt_CloseFormFillInfo(formFillInfoPtr);\r\n\r\n            return PdfTaskHelper.reject({\r\n              code: PdfErrorCode.CantSelectText,\r\n              message: 'failed to select all text',\r\n            });\r\n          }\r\n          const length = 2 * (value.text.length + 1);\r\n          const textPtr = this.memoryManager.malloc(length);\r\n          this.pdfiumModule.pdfium.stringToUTF16(value.text, textPtr, length);\r\n          this.pdfiumModule.FORM_ReplaceSelection(formHandle, pageCtx.pagePtr, textPtr);\r\n          this.memoryManager.free(textPtr);\r\n        }\r\n        break;\r\n      case 'selection':\r\n        {\r\n          if (\r\n            !this.pdfiumModule.FORM_SetIndexSelected(\r\n              formHandle,\r\n              pageCtx.pagePtr,\r\n              value.index,\r\n              value.isSelected,\r\n            )\r\n          ) {\r\n            this.logger.debug(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              'SetFormFieldValue',\r\n              'failed to set index selected',\r\n            );\r\n            this.logger.perf(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              `SetFormFieldValue`,\r\n              'End',\r\n              `${doc.id}-${annotation.id}`,\r\n            );\r\n            this.pdfiumModule.FORM_ForceToKillFocus(formHandle);\r\n            this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n            this.pdfiumModule.FORM_OnBeforeClosePage(pageCtx.pagePtr, formHandle);\r\n            pageCtx.release();\r\n            this.pdfiumModule.PDFiumExt_ExitFormFillEnvironment(formHandle);\r\n            this.pdfiumModule.PDFiumExt_CloseFormFillInfo(formFillInfoPtr);\r\n\r\n            return PdfTaskHelper.reject({\r\n              code: PdfErrorCode.CantSelectOption,\r\n              message: 'failed to set index selected',\r\n            });\r\n          }\r\n        }\r\n        break;\r\n      case 'checked':\r\n        {\r\n          const kReturn = 0x0d;\r\n          if (!this.pdfiumModule.FORM_OnChar(formHandle, pageCtx.pagePtr, kReturn, 0)) {\r\n            this.logger.debug(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              'SetFormFieldValue',\r\n              'failed to set field checked',\r\n            );\r\n            this.logger.perf(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              `SetFormFieldValue`,\r\n              'End',\r\n              `${doc.id}-${annotation.id}`,\r\n            );\r\n            this.pdfiumModule.FORM_ForceToKillFocus(formHandle);\r\n            this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n            this.pdfiumModule.FORM_OnBeforeClosePage(pageCtx.pagePtr, formHandle);\r\n            pageCtx.release();\r\n            this.pdfiumModule.PDFiumExt_ExitFormFillEnvironment(formHandle);\r\n            this.pdfiumModule.PDFiumExt_CloseFormFillInfo(formFillInfoPtr);\r\n\r\n            return PdfTaskHelper.reject({\r\n              code: PdfErrorCode.CantCheckField,\r\n              message: 'failed to set field checked',\r\n            });\r\n          }\r\n        }\r\n        break;\r\n    }\r\n\r\n    this.pdfiumModule.FORM_ForceToKillFocus(formHandle);\r\n\r\n    this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);\r\n    this.pdfiumModule.FORM_OnBeforeClosePage(pageCtx.pagePtr, formHandle);\r\n    pageCtx.release();\r\n\r\n    this.pdfiumModule.PDFiumExt_ExitFormFillEnvironment(formHandle);\r\n    this.pdfiumModule.PDFiumExt_CloseFormFillInfo(formFillInfoPtr);\r\n\r\n    return PdfTaskHelper.resolve<boolean>(true);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.flattenPage}\r\n   *\r\n   * @public\r\n   */\r\n  flattenPage(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    options?: PdfFlattenPageOptions,\r\n  ): PdfTask<PdfPageFlattenResult> {\r\n    const { flag = PdfPageFlattenFlag.Display } = options ?? {};\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'flattenPage', doc, page, flag);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `flattenPage`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `flattenPage`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const result = this.pdfiumModule.FPDFPage_Flatten(pageCtx.pagePtr, flag);\r\n    pageCtx.release();\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `flattenPage`, 'End', doc.id);\r\n\r\n    return PdfTaskHelper.resolve(result);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.extractPages}\r\n   *\r\n   * @public\r\n   */\r\n  extractPages(doc: PdfDocumentObject, pageIndexes: number[]) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'extractPages', doc, pageIndexes);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractPages`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractPages`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const newDocPtr = this.pdfiumModule.FPDF_CreateNewDocument();\r\n    if (!newDocPtr) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractPages`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantCreateNewDoc,\r\n        message: 'can not create new document',\r\n      });\r\n    }\r\n\r\n    const pageIndexesPtr = this.memoryManager.malloc(pageIndexes.length * 4);\r\n    for (let i = 0; i < pageIndexes.length; i++) {\r\n      this.pdfiumModule.pdfium.setValue(pageIndexesPtr + i * 4, pageIndexes[i], 'i32');\r\n    }\r\n\r\n    if (\r\n      !this.pdfiumModule.FPDF_ImportPagesByIndex(\r\n        newDocPtr,\r\n        ctx.docPtr,\r\n        pageIndexesPtr,\r\n        pageIndexes.length,\r\n        0,\r\n      )\r\n    ) {\r\n      this.pdfiumModule.FPDF_CloseDocument(newDocPtr);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractPages`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantImportPages,\r\n        message: 'can not import pages to new document',\r\n      });\r\n    }\r\n\r\n    const buffer = this.saveDocument(newDocPtr);\r\n\r\n    this.pdfiumModule.FPDF_CloseDocument(newDocPtr);\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractPages`, 'End', doc.id);\r\n    return PdfTaskHelper.resolve(buffer);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.extractText}\r\n   *\r\n   * @public\r\n   */\r\n  extractText(doc: PdfDocumentObject, pageIndexes: number[]) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'extractText', doc, pageIndexes);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractText`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractText`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const strings: string[] = [];\r\n    for (let i = 0; i < pageIndexes.length; i++) {\r\n      const pageCtx = ctx.acquirePage(pageIndexes[i]);\r\n      const textPagePtr = this.pdfiumModule.FPDFText_LoadPage(pageCtx.pagePtr);\r\n      const charCount = this.pdfiumModule.FPDFText_CountChars(textPagePtr);\r\n      const bufferPtr = this.memoryManager.malloc((charCount + 1) * 2);\r\n      this.pdfiumModule.FPDFText_GetText(textPagePtr, 0, charCount, bufferPtr);\r\n      const text = this.pdfiumModule.pdfium.UTF16ToString(bufferPtr);\r\n      this.memoryManager.free(bufferPtr);\r\n      strings.push(text);\r\n      this.pdfiumModule.FPDFText_ClosePage(textPagePtr);\r\n      pageCtx.release();\r\n    }\r\n\r\n    const text = strings.join('\\n\\n');\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractText`, 'End', doc.id);\r\n    return PdfTaskHelper.resolve(text);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.getTextSlices}\r\n   *\r\n   * @public\r\n   */\r\n  getTextSlices(doc: PdfDocumentObject, slices: PageTextSlice[]): PdfTask<string[]> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getTextSlices', doc, slices);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetTextSlices', 'Begin', doc.id);\r\n\r\n    /* ⚠︎ 1 — trivial case */\r\n    if (slices.length === 0) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetTextSlices', 'End', doc.id);\r\n      return PdfTaskHelper.resolve<string[]>([]);\r\n    }\r\n\r\n    /* ⚠︎ 2 — document must be open */\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetTextSlices', 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    try {\r\n      /* keep caller order */\r\n      const out = new Array<string>(slices.length);\r\n\r\n      /* group → open each page once */\r\n      const byPage = new Map<number, { slice: PageTextSlice; pos: number }[]>();\r\n      slices.forEach((s, i) => {\r\n        (byPage.get(s.pageIndex) ?? byPage.set(s.pageIndex, []).get(s.pageIndex))!.push({\r\n          slice: s,\r\n          pos: i,\r\n        });\r\n      });\r\n\r\n      for (const [pageIdx, list] of byPage) {\r\n        const pageCtx = ctx.acquirePage(pageIdx);\r\n        const textPagePtr = pageCtx.getTextPage();\r\n\r\n        for (const { slice, pos } of list) {\r\n          const bufPtr = this.memoryManager.malloc(2 * (slice.charCount + 1)); // UTF-16 + NIL\r\n          this.pdfiumModule.FPDFText_GetText(textPagePtr, slice.charIndex, slice.charCount, bufPtr);\r\n          out[pos] = stripPdfUnwantedMarkers(this.pdfiumModule.pdfium.UTF16ToString(bufPtr));\r\n          this.memoryManager.free(bufPtr);\r\n        }\r\n        pageCtx.release();\r\n      }\r\n\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetTextSlices', 'End', doc.id);\r\n      return PdfTaskHelper.resolve(out);\r\n    } catch (e) {\r\n      this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'getTextSlices error', e);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'GetTextSlices', 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: String(e),\r\n      });\r\n    }\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.merge}\r\n   *\r\n   * @public\r\n   */\r\n  merge(files: PdfFile[]) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'merge', files);\r\n    const fileIds = files.map((file) => file.id).join('.');\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Merge`, 'Begin', fileIds);\r\n\r\n    const newDocPtr = this.pdfiumModule.FPDF_CreateNewDocument();\r\n    if (!newDocPtr) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Merge`, 'End', fileIds);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantCreateNewDoc,\r\n        message: 'can not create new document',\r\n      });\r\n    }\r\n\r\n    const ptrs: { docPtr: number; filePtr: WasmPointer }[] = [];\r\n    for (const file of files.reverse()) {\r\n      const array = new Uint8Array(file.content);\r\n      const length = array.length;\r\n      const filePtr = this.memoryManager.malloc(length);\r\n      this.pdfiumModule.pdfium.HEAPU8.set(array, filePtr);\r\n\r\n      const docPtr = this.pdfiumModule.FPDF_LoadMemDocument(filePtr, length, '');\r\n      if (!docPtr) {\r\n        const lastError = this.pdfiumModule.FPDF_GetLastError();\r\n        this.logger.error(\r\n          LOG_SOURCE,\r\n          LOG_CATEGORY,\r\n          `FPDF_LoadMemDocument failed with ${lastError}`,\r\n        );\r\n        this.memoryManager.free(filePtr);\r\n\r\n        for (const ptr of ptrs) {\r\n          this.pdfiumModule.FPDF_CloseDocument(ptr.docPtr);\r\n          this.memoryManager.free(ptr.filePtr);\r\n        }\r\n\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Merge`, 'End', fileIds);\r\n        return PdfTaskHelper.reject<PdfFile>({\r\n          code: lastError,\r\n          message: `FPDF_LoadMemDocument failed`,\r\n        });\r\n      }\r\n      ptrs.push({ filePtr, docPtr });\r\n\r\n      if (!this.pdfiumModule.FPDF_ImportPages(newDocPtr, docPtr, '', 0)) {\r\n        this.pdfiumModule.FPDF_CloseDocument(newDocPtr);\r\n\r\n        for (const ptr of ptrs) {\r\n          this.pdfiumModule.FPDF_CloseDocument(ptr.docPtr);\r\n          this.memoryManager.free(ptr.filePtr);\r\n        }\r\n\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Merge`, 'End', fileIds);\r\n        return PdfTaskHelper.reject({\r\n          code: PdfErrorCode.CantImportPages,\r\n          message: 'can not import pages to new document',\r\n        });\r\n      }\r\n    }\r\n    const buffer = this.saveDocument(newDocPtr);\r\n\r\n    this.pdfiumModule.FPDF_CloseDocument(newDocPtr);\r\n\r\n    for (const ptr of ptrs) {\r\n      this.pdfiumModule.FPDF_CloseDocument(ptr.docPtr);\r\n      this.memoryManager.free(ptr.filePtr);\r\n    }\r\n\r\n    const file: PdfFile = {\r\n      id: `${Math.random()}`,\r\n      content: buffer,\r\n    };\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `Merge`, 'End', fileIds);\r\n    return PdfTaskHelper.resolve(file);\r\n  }\r\n\r\n  /**\r\n   * Merges specific pages from multiple PDF documents in a custom order\r\n   *\r\n   * @param mergeConfigs Array of configurations specifying which pages to merge from which documents\r\n   * @returns A PdfTask that resolves with the merged PDF file\r\n   * @public\r\n   */\r\n  mergePages(mergeConfigs: Array<{ docId: string; pageIndices: number[] }>) {\r\n    const configIds = mergeConfigs\r\n      .map((config) => `${config.docId}:${config.pageIndices.join(',')}`)\r\n      .join('|');\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'mergePages', mergeConfigs);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `MergePages`, 'Begin', configIds);\r\n\r\n    // Create a new document to import pages into\r\n    const newDocPtr = this.pdfiumModule.FPDF_CreateNewDocument();\r\n    if (!newDocPtr) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `MergePages`, 'End', configIds);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantCreateNewDoc,\r\n        message: 'Cannot create new document',\r\n      });\r\n    }\r\n\r\n    try {\r\n      // Process each merge configuration in reverse order (since we're inserting at position 0)\r\n      // This ensures the final document has pages in the order specified by the user\r\n      for (const config of [...mergeConfigs].reverse()) {\r\n        // Check if the document is open\r\n        const ctx = this.cache.getContext(config.docId);\r\n\r\n        if (!ctx) {\r\n          this.logger.warn(\r\n            LOG_SOURCE,\r\n            LOG_CATEGORY,\r\n            `Document ${config.docId} is not open, skipping`,\r\n          );\r\n          continue;\r\n        }\r\n\r\n        // Get the page count for this document\r\n        const pageCount = this.pdfiumModule.FPDF_GetPageCount(ctx.docPtr);\r\n\r\n        // Filter out invalid page indices\r\n        const validPageIndices = config.pageIndices.filter(\r\n          (index) => index >= 0 && index < pageCount,\r\n        );\r\n\r\n        if (validPageIndices.length === 0) {\r\n          continue; // No valid pages to import\r\n        }\r\n\r\n        // Convert 0-based indices to 1-based for PDFium and join with commas\r\n        const pageString = validPageIndices.map((index) => index + 1).join(',');\r\n\r\n        try {\r\n          // Import all specified pages at once from this document\r\n          if (\r\n            !this.pdfiumModule.FPDF_ImportPages(\r\n              newDocPtr,\r\n              ctx.docPtr,\r\n              pageString,\r\n              0, // Insert at the beginning\r\n            )\r\n          ) {\r\n            throw new Error(`Failed to import pages ${pageString} from document ${config.docId}`);\r\n          }\r\n        } finally {\r\n        }\r\n      }\r\n\r\n      // Save the new document to buffer\r\n      const buffer = this.saveDocument(newDocPtr);\r\n\r\n      const file: PdfFile = {\r\n        id: `${Math.random()}`,\r\n        content: buffer,\r\n      };\r\n\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `MergePages`, 'End', configIds);\r\n      return PdfTaskHelper.resolve(file);\r\n    } catch (error) {\r\n      this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'mergePages failed', error);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `MergePages`, 'End', configIds);\r\n\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantImportPages,\r\n        message: error instanceof Error ? error.message : 'Failed to merge pages',\r\n      });\r\n    } finally {\r\n      // Clean up the new document\r\n      if (newDocPtr) {\r\n        this.pdfiumModule.FPDF_CloseDocument(newDocPtr);\r\n      }\r\n    }\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.saveAsCopy}\r\n   *\r\n   * @public\r\n   */\r\n  saveAsCopy(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'saveAsCopy', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SaveAsCopy`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SaveAsCopy`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    const buffer = this.saveDocument(ctx.docPtr);\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SaveAsCopy`, 'End', doc.id);\r\n    return PdfTaskHelper.resolve(buffer);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.closeDocument}\r\n   *\r\n   * @public\r\n   */\r\n  closeDocument(doc: PdfDocumentObject) {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'closeDocument', doc);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseDocument`, 'Begin', doc.id);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseDocument`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    ctx.dispose();\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseDocument`, 'End', doc.id);\r\n    return PdfTaskHelper.resolve(true);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.closeAllDocuments}\r\n   *\r\n   * @public\r\n   */\r\n  closeAllDocuments() {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'closeAllDocuments');\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseAllDocuments`, 'Begin');\r\n    this.cache.closeAllDocuments();\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseAllDocuments`, 'End');\r\n    return PdfTaskHelper.resolve(true);\r\n  }\r\n\r\n  /**\r\n   * Add text content to annotation\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to text annotation\r\n   * @param annotation - text annotation\r\n   * @returns whether text content is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  private addTextContent(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfTextAnnoObject,\r\n  ) {\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (\r\n      annotation.inReplyToId &&\r\n      !this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationIcon(annotationPtr, annotation.icon || PdfAnnotationIcon.Comment)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationFlags(annotationPtr, annotation.flags || ['print', 'noZoom', 'noRotate'])\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.state && !this.setAnnotString(annotationPtr, 'State', annotation.state)) {\r\n      return false;\r\n    }\r\n    if (\r\n      annotation.stateModel &&\r\n      !this.setAnnotString(annotationPtr, 'StateModel', annotation.stateModel)\r\n    ) {\r\n      return false;\r\n    }\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add free text content to annotation\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to free text annotation\r\n   * @param annotation - free text annotation\r\n   * @returns whether free text content is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  private addFreeTextContent(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfFreeTextAnnoObject,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationTextAlignment(annotationPtr, annotation.textAlign)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationVerticalAlignment(annotationPtr, annotation.verticalAlign)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationDefaultAppearance(\r\n        annotationPtr,\r\n        annotation.fontFamily,\r\n        annotation.fontSize,\r\n        annotation.fontColor,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {\r\n      return false;\r\n    }\r\n    if (!annotation.backgroundColor || annotation.backgroundColor === 'transparent') {\r\n      if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {\r\n        return false;\r\n      }\r\n    } else if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.backgroundColor ?? '#FFFFFF',\r\n        PdfAnnotationColorType.Color,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Set the rect of specified annotation\r\n   * @param page - page info that the annotation is belonged to\r\n   * @param pagePtr - pointer of page object\r\n   * @param annotationPtr - pointer to annotation object\r\n   * @param inkList - ink lists that added to the annotation\r\n   * @returns whether the ink lists is setted\r\n   *\r\n   * @private\r\n   */\r\n  private addInkStroke(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfInkAnnoObject,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, annotation.strokeWidth)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setInkList(page, annotationPtr, annotation.inkList)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.color ?? '#FFFF00',\r\n        PdfAnnotationColorType.Color,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add line content to annotation\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to line annotation\r\n   * @param annotation - line annotation\r\n   * @returns whether line content is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  private addLineContent(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfLineAnnoObject,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setLinePoints(\r\n        page,\r\n        annotationPtr,\r\n        annotation.linePoints.start,\r\n        annotation.linePoints.end,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setLineEndings(\r\n        annotationPtr,\r\n        annotation.lineEndings?.start ?? PdfAnnotationLineEnding.None,\r\n        annotation.lineEndings?.end ?? PdfAnnotationLineEnding.None,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {\r\n      return false;\r\n    }\r\n    if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {\r\n      return false;\r\n    }\r\n    if (!annotation.color || annotation.color === 'transparent') {\r\n      if (\r\n        !this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)\r\n      ) {\r\n        return false;\r\n      }\r\n    } else if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.color ?? '#FFFF00',\r\n        PdfAnnotationColorType.InteriorColor,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.strokeColor ?? '#FFFF00',\r\n        PdfAnnotationColorType.Color,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add polygon or polyline content to annotation\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to polygon or polyline annotation\r\n   * @param annotation - polygon or polyline annotation\r\n   * @returns whether polygon or polyline content is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  private addPolyContent(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfPolygonAnnoObject | PdfPolylineAnnoObject,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (\r\n      annotation.type === PdfAnnotationSubtype.POLYLINE &&\r\n      !this.setLineEndings(\r\n        annotationPtr,\r\n        annotation.lineEndings?.start ?? PdfAnnotationLineEnding.None,\r\n        annotation.lineEndings?.end ?? PdfAnnotationLineEnding.None,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {\r\n      return false;\r\n    }\r\n    if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {\r\n      return false;\r\n    }\r\n    if (!annotation.color || annotation.color === 'transparent') {\r\n      if (\r\n        !this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)\r\n      ) {\r\n        return false;\r\n      }\r\n    } else if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.color ?? '#FFFF00',\r\n        PdfAnnotationColorType.InteriorColor,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.strokeColor ?? '#FFFF00',\r\n        PdfAnnotationColorType.Color,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add shape content to annotation\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to shape annotation\r\n   * @param annotation - shape annotation\r\n   * @returns whether shape content is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  addShapeContent(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfCircleAnnoObject | PdfSquareAnnoObject,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {\r\n      return false;\r\n    }\r\n    if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (!annotation.color || annotation.color === 'transparent') {\r\n      if (\r\n        !this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)\r\n      ) {\r\n        return false;\r\n      }\r\n    } else if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.color ?? '#FFFF00',\r\n        PdfAnnotationColorType.InteriorColor,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.strokeColor ?? '#FFFF00',\r\n        PdfAnnotationColorType.Color,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add highlight content to annotation\r\n   * @param page - page info\r\n   * @param annotationPtr - pointer to highlight annotation\r\n   * @param annotation - highlight annotation\r\n   * @returns whether highlight content is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  addTextMarkupContent(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation:\r\n      | PdfHighlightAnnoObject\r\n      | PdfUnderlineAnnoObject\r\n      | PdfStrikeOutAnnoObject\r\n      | PdfSquigglyAnnoObject,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {\r\n      return false;\r\n    }\r\n    if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'T', annotation.author || '')) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {\r\n      return false;\r\n    }\r\n    if (\r\n      !this.setAnnotationColor(\r\n        annotationPtr,\r\n        annotation.color ?? '#FFFF00',\r\n        PdfAnnotationColorType.Color,\r\n      )\r\n    ) {\r\n      return false;\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add contents to stamp annotation\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to stamp annotation\r\n   * @param rect - rect of stamp annotation\r\n   * @param contents - contents of stamp annotation\r\n   * @returns whether contents is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  addStampContent(\r\n    docPtr: number,\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    annotation: PdfStampAnnoObject,\r\n    imageData?: ImageData,\r\n  ) {\r\n    if (\r\n      annotation.created &&\r\n      !this.setAnnotationDate(annotationPtr, 'CreationDate', annotation.created)\r\n    ) {\r\n      return false;\r\n    }\r\n    if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {\r\n      return false;\r\n    }\r\n    if (annotation.modified && !this.setAnnotationDate(annotationPtr, 'M', annotation.modified)) {\r\n      return false;\r\n    }\r\n    if (annotation.icon && !this.setAnnotationIcon(annotationPtr, annotation.icon)) {\r\n      return false;\r\n    }\r\n    if (annotation.subject && !this.setAnnotString(annotationPtr, 'Subj', annotation.subject)) {\r\n      return false;\r\n    }\r\n    if (!this.setAnnotString(annotationPtr, 'Contents', annotation.contents ?? '')) {\r\n      return false;\r\n    }\r\n    if (imageData) {\r\n      for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {\r\n        this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);\r\n      }\r\n\r\n      if (!this.addImageObject(docPtr, page, pagePtr, annotationPtr, annotation.rect, imageData)) {\r\n        return false;\r\n      }\r\n    }\r\n    if (!this.pdfiumModule.EPDFAnnot_UpdateAppearanceToRect(annotationPtr, PdfStampFit.Cover)) {\r\n      return false;\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Add image object to annotation\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param page - page info\r\n   * @param pagePtr - pointer to page object\r\n   * @param annotationPtr - pointer to stamp annotation\r\n   * @param position - position of image\r\n   * @param imageData - data of image\r\n   * @returns whether image is added to annotation\r\n   *\r\n   * @private\r\n   */\r\n  addImageObject(\r\n    docPtr: number,\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    annotationPtr: number,\r\n    rect: Rect,\r\n    imageData: ImageData,\r\n  ) {\r\n    const bytesPerPixel = 4;\r\n    const pixelCount = imageData.width * imageData.height;\r\n\r\n    const bitmapBufferPtr = this.memoryManager.malloc(bytesPerPixel * pixelCount);\r\n    if (!bitmapBufferPtr) {\r\n      return false;\r\n    }\r\n\r\n    for (let i = 0; i < pixelCount; i++) {\r\n      const red = imageData.data[i * bytesPerPixel];\r\n      const green = imageData.data[i * bytesPerPixel + 1];\r\n      const blue = imageData.data[i * bytesPerPixel + 2];\r\n      const alpha = imageData.data[i * bytesPerPixel + 3];\r\n\r\n      this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel, blue, 'i8');\r\n      this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel + 1, green, 'i8');\r\n      this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel + 2, red, 'i8');\r\n      this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel + 3, alpha, 'i8');\r\n    }\r\n\r\n    const format = BitmapFormat.Bitmap_BGRA;\r\n    const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(\r\n      imageData.width,\r\n      imageData.height,\r\n      format,\r\n      bitmapBufferPtr,\r\n      0,\r\n    );\r\n    if (!bitmapPtr) {\r\n      this.memoryManager.free(bitmapBufferPtr);\r\n      return false;\r\n    }\r\n\r\n    const imageObjectPtr = this.pdfiumModule.FPDFPageObj_NewImageObj(docPtr);\r\n    if (!imageObjectPtr) {\r\n      this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);\r\n      this.memoryManager.free(bitmapBufferPtr);\r\n      return false;\r\n    }\r\n\r\n    if (!this.pdfiumModule.FPDFImageObj_SetBitmap(pagePtr, 0, imageObjectPtr, bitmapPtr)) {\r\n      this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);\r\n      this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);\r\n      this.memoryManager.free(bitmapBufferPtr);\r\n      return false;\r\n    }\r\n\r\n    const matrixPtr = this.memoryManager.malloc(6 * 4);\r\n    this.pdfiumModule.pdfium.setValue(matrixPtr, imageData.width, 'float');\r\n    this.pdfiumModule.pdfium.setValue(matrixPtr + 4, 0, 'float');\r\n    this.pdfiumModule.pdfium.setValue(matrixPtr + 8, 0, 'float');\r\n    this.pdfiumModule.pdfium.setValue(matrixPtr + 12, imageData.height, 'float');\r\n    this.pdfiumModule.pdfium.setValue(matrixPtr + 16, 0, 'float');\r\n    this.pdfiumModule.pdfium.setValue(matrixPtr + 20, 0, 'float');\r\n    if (!this.pdfiumModule.FPDFPageObj_SetMatrix(imageObjectPtr, matrixPtr)) {\r\n      this.memoryManager.free(matrixPtr);\r\n      this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);\r\n      this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);\r\n      this.memoryManager.free(bitmapBufferPtr);\r\n      return false;\r\n    }\r\n    this.memoryManager.free(matrixPtr);\r\n\r\n    const pagePos = this.convertDevicePointToPagePoint(page, {\r\n      x: rect.origin.x,\r\n      y: rect.origin.y + imageData.height, // shift down by the image height\r\n    });\r\n    this.pdfiumModule.FPDFPageObj_Transform(imageObjectPtr, 1, 0, 0, 1, pagePos.x, pagePos.y);\r\n\r\n    if (!this.pdfiumModule.FPDFAnnot_AppendObject(annotationPtr, imageObjectPtr)) {\r\n      this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);\r\n      this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);\r\n      this.memoryManager.free(bitmapBufferPtr);\r\n      return false;\r\n    }\r\n\r\n    this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);\r\n    this.memoryManager.free(bitmapBufferPtr);\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Save document to array buffer\r\n   * @param docPtr - pointer to pdf document\r\n   * @returns array buffer contains the pdf content\r\n   *\r\n   * @private\r\n   */\r\n  saveDocument(docPtr: number) {\r\n    const writerPtr = this.pdfiumModule.PDFiumExt_OpenFileWriter();\r\n    this.pdfiumModule.PDFiumExt_SaveAsCopy(docPtr, writerPtr);\r\n    const size = this.pdfiumModule.PDFiumExt_GetFileWriterSize(writerPtr);\r\n    const dataPtr = this.memoryManager.malloc(size);\r\n    this.pdfiumModule.PDFiumExt_GetFileWriterData(writerPtr, dataPtr, size);\r\n    const buffer = new ArrayBuffer(size);\r\n    const view = new DataView(buffer);\r\n    for (let i = 0; i < size; i++) {\r\n      view.setInt8(i, this.pdfiumModule.pdfium.getValue(dataPtr + i, 'i8'));\r\n    }\r\n    this.memoryManager.free(dataPtr);\r\n    this.pdfiumModule.PDFiumExt_CloseFileWriter(writerPtr);\r\n\r\n    return buffer;\r\n  }\r\n\r\n  /**\r\n   * Read Catalog /Lang via EPDFCatalog_GetLanguage (UTF-16LE → JS string).\r\n   * Returns:\r\n   *   null  -> /Lang not present (getter returned 0) OR doc not open,\r\n   *   ''    -> /Lang exists but is explicitly empty,\r\n   *   'en', 'en-US', ... -> normal tag.\r\n   *\r\n   * Note: EPDFCatalog_GetLanguage lengths are BYTES (incl. trailing NUL).\r\n   *\r\n   * @private\r\n   */\r\n  private readCatalogLanguage(docPtr: number): string | null {\r\n    // Probe required length in BYTES (includes UTF-16LE trailing NUL).\r\n    const byteLen = this.pdfiumModule.EPDFCatalog_GetLanguage(docPtr, 0, 0) >>> 0;\r\n\r\n    // 0 => /Lang missing (or invalid doc/root) → expose as null\r\n    if (byteLen === 0) return null;\r\n\r\n    // 2 => empty UTF-16LE string (just the NUL) → explicitly empty\r\n    if (byteLen === 2) return '';\r\n\r\n    // Read exact buffer to avoid extra allocs.\r\n    return readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) =>\r\n        this.pdfiumModule.EPDFCatalog_GetLanguage(docPtr, buffer, bufferLength),\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n      byteLen,\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Read metadata from pdf document\r\n   * @param docPtr - pointer to pdf document\r\n   * @param key - key of metadata field\r\n   * @returns metadata value\r\n   *\r\n   * @private\r\n   */\r\n  private readMetaText(docPtr: number, key: string): string | null {\r\n    const exists = !!this.pdfiumModule.EPDF_HasMetaText(docPtr, key);\r\n    if (!exists) return null;\r\n\r\n    const len = this.pdfiumModule.FPDF_GetMetaText(docPtr, key, 0, 0);\r\n    if (len === 2) return '';\r\n\r\n    // Read with an exact buffer to avoid extra allocations.\r\n    return readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) =>\r\n        this.pdfiumModule.FPDF_GetMetaText(docPtr, key, buffer, bufferLength),\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n      len,\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Write metadata into the PDF's Info dictionary.\r\n   * If `value` is null or empty string, the key is removed.\r\n   * @param docPtr - pointer to pdf document\r\n   * @param key - key of metadata field\r\n   * @param value - value of metadata field\r\n   * @returns whether metadata is written to the pdf document\r\n   *\r\n   * @private\r\n   */\r\n  private setMetaText(docPtr: number, key: string, value: string | null | undefined): boolean {\r\n    // Remove key if value is null/undefined/empty\r\n    if (value == null || value.length === 0) {\r\n      // Pass nullptr for value → removal in our C++ implementation\r\n      const ok = this.pdfiumModule.EPDF_SetMetaText(docPtr, key, 0);\r\n      return !!ok;\r\n    }\r\n\r\n    // UTF-16LE buffer (+2 bytes for NUL)\r\n    const bytes = 2 * (value.length + 1);\r\n    const ptr = this.memoryManager.malloc(bytes);\r\n    try {\r\n      this.pdfiumModule.pdfium.stringToUTF16(value, ptr, bytes);\r\n      const ok = this.pdfiumModule.EPDF_SetMetaText(docPtr, key, ptr);\r\n      return !!ok;\r\n    } finally {\r\n      this.memoryManager.free(ptr);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Read the document's trapped status via PDFium.\r\n   * Falls back to `Unknown` on unexpected values.\r\n   *\r\n   * @private\r\n   */\r\n  private getMetaTrapped(docPtr: number): PdfTrappedStatus {\r\n    const raw = Number(this.pdfiumModule.EPDF_GetMetaTrapped(docPtr));\r\n    switch (raw) {\r\n      case PdfTrappedStatus.NotSet:\r\n      case PdfTrappedStatus.True:\r\n      case PdfTrappedStatus.False:\r\n      case PdfTrappedStatus.Unknown:\r\n        return raw;\r\n      default:\r\n        return PdfTrappedStatus.Unknown;\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Write (or clear) the document's trapped status via PDFium.\r\n   * Pass `null`/`undefined` to remove the `/Trapped` key.\r\n   *\r\n   * @private\r\n   */\r\n  private setMetaTrapped(docPtr: number, status: PdfTrappedStatus | null | undefined): boolean {\r\n    // Treat null/undefined as “remove key” — the C++ side handles NotSet by\r\n    // deleting /Trapped from the Info dictionary.\r\n    const toSet = status == null || status === undefined ? PdfTrappedStatus.NotSet : status;\r\n\r\n    // Guard against unexpected values.\r\n    const valid =\r\n      toSet === PdfTrappedStatus.NotSet ||\r\n      toSet === PdfTrappedStatus.True ||\r\n      toSet === PdfTrappedStatus.False ||\r\n      toSet === PdfTrappedStatus.Unknown;\r\n\r\n    if (!valid) return false;\r\n\r\n    return !!this.pdfiumModule.EPDF_SetMetaTrapped(docPtr, toSet);\r\n  }\r\n\r\n  /**\r\n   * Get the number of keys in the document's Info dictionary.\r\n   * @param docPtr - pointer to pdf document\r\n   * @param customOnly - if true, only count non-reserved (custom) keys; if false, count all keys.\r\n   * @returns the number of keys (possibly 0). On error, returns 0.\r\n   *\r\n   * @private\r\n   */\r\n  private getMetaKeyCount(docPtr: number, customOnly: boolean): number {\r\n    return Number(this.pdfiumModule.EPDF_GetMetaKeyCount(docPtr, customOnly)) | 0;\r\n  }\r\n\r\n  /**\r\n   * Get the name of the Info dictionary key at |index|.\r\n   * @param docPtr - pointer to pdf document\r\n   * @param index - 0-based key index in the order returned by PDFium.\r\n   * @param customOnly - if true, indexes only over non-reserved (custom) keys; if false, indexes over all keys.\r\n   * @returns the name of the key, or null if the key is not found.\r\n   *\r\n   * @private\r\n   */\r\n  private getMetaKeyName(docPtr: number, index: number, customOnly: boolean): string | null {\r\n    const len = this.pdfiumModule.EPDF_GetMetaKeyName(docPtr, index, customOnly, 0, 0);\r\n    if (!len) return null;\r\n    return readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, buflen) =>\r\n        this.pdfiumModule.EPDF_GetMetaKeyName(docPtr, index, customOnly, buffer, buflen),\r\n      this.pdfiumModule.pdfium.UTF8ToString,\r\n      len,\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Read all metadata from the document's Info dictionary.\r\n   * @param docPtr - pointer to pdf document\r\n   * @param customOnly - if true, only read non-reserved (custom) keys; if false, read all keys.\r\n   * @returns all metadata\r\n   *\r\n   * @private\r\n   */\r\n  private readAllMeta(docPtr: number, customOnly: boolean = true): Record<string, string | null> {\r\n    const n = this.getMetaKeyCount(docPtr, customOnly);\r\n    const out: Record<string, string | null> = {};\r\n    for (let i = 0; i < n; i++) {\r\n      const key = this.getMetaKeyName(docPtr, i, customOnly);\r\n      if (!key) continue;\r\n      out[key] = this.readMetaText(docPtr, key); // returns null if not present\r\n    }\r\n    return out;\r\n  }\r\n\r\n  /**\r\n   * Read bookmarks in the pdf document\r\n   * @param docPtr - pointer to pdf document\r\n   * @param rootBookmarkPtr - pointer to root bookmark\r\n   * @returns bookmarks in the pdf document\r\n   *\r\n   * @private\r\n   */\r\n  readPdfBookmarks(docPtr: number, rootBookmarkPtr = 0) {\r\n    let bookmarkPtr = this.pdfiumModule.FPDFBookmark_GetFirstChild(docPtr, rootBookmarkPtr);\r\n\r\n    const bookmarks: PdfBookmarkObject[] = [];\r\n    while (bookmarkPtr) {\r\n      const bookmark = this.readPdfBookmark(docPtr, bookmarkPtr);\r\n      bookmarks.push(bookmark);\r\n\r\n      const nextBookmarkPtr = this.pdfiumModule.FPDFBookmark_GetNextSibling(docPtr, bookmarkPtr);\r\n\r\n      bookmarkPtr = nextBookmarkPtr;\r\n    }\r\n\r\n    return bookmarks;\r\n  }\r\n\r\n  /**\r\n   * Read bookmark in the pdf document\r\n   * @param docPtr - pointer to pdf document\r\n   * @param bookmarkPtr - pointer to bookmark object\r\n   * @returns pdf bookmark object\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfBookmark(docPtr: number, bookmarkPtr: number): PdfBookmarkObject {\r\n    const title = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) => {\r\n        return this.pdfiumModule.FPDFBookmark_GetTitle(bookmarkPtr, buffer, bufferLength);\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n\r\n    const bookmarks = this.readPdfBookmarks(docPtr, bookmarkPtr);\r\n\r\n    const target = this.readPdfBookmarkTarget(\r\n      docPtr,\r\n      () => {\r\n        return this.pdfiumModule.FPDFBookmark_GetAction(bookmarkPtr);\r\n      },\r\n      () => {\r\n        return this.pdfiumModule.FPDFBookmark_GetDest(docPtr, bookmarkPtr);\r\n      },\r\n    );\r\n\r\n    return {\r\n      title,\r\n      target,\r\n      children: bookmarks,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read text rects in pdf page\r\n   * @param page - pdf page info\r\n   * @param docPtr - pointer to pdf document\r\n   * @param pagePtr - pointer to pdf page\r\n   * @param textPagePtr - pointer to pdf text page\r\n   * @returns text rects in the pdf page\r\n   *\r\n   * @public\r\n   */\r\n  private readPageTextRects(\r\n    page: PdfPageObject,\r\n    docPtr: number,\r\n    pagePtr: number,\r\n    textPagePtr: number,\r\n  ) {\r\n    const rectsCount = this.pdfiumModule.FPDFText_CountRects(textPagePtr, 0, -1);\r\n\r\n    const textRects: PdfTextRectObject[] = [];\r\n    for (let i = 0; i < rectsCount; i++) {\r\n      const topPtr = this.memoryManager.malloc(8);\r\n      const leftPtr = this.memoryManager.malloc(8);\r\n      const rightPtr = this.memoryManager.malloc(8);\r\n      const bottomPtr = this.memoryManager.malloc(8);\r\n      const isSucceed = this.pdfiumModule.FPDFText_GetRect(\r\n        textPagePtr,\r\n        i,\r\n        leftPtr,\r\n        topPtr,\r\n        rightPtr,\r\n        bottomPtr,\r\n      );\r\n      if (!isSucceed) {\r\n        this.memoryManager.free(leftPtr);\r\n        this.memoryManager.free(topPtr);\r\n        this.memoryManager.free(rightPtr);\r\n        this.memoryManager.free(bottomPtr);\r\n        continue;\r\n      }\r\n\r\n      const left = this.pdfiumModule.pdfium.getValue(leftPtr, 'double');\r\n      const top = this.pdfiumModule.pdfium.getValue(topPtr, 'double');\r\n      const right = this.pdfiumModule.pdfium.getValue(rightPtr, 'double');\r\n      const bottom = this.pdfiumModule.pdfium.getValue(bottomPtr, 'double');\r\n\r\n      this.memoryManager.free(leftPtr);\r\n      this.memoryManager.free(topPtr);\r\n      this.memoryManager.free(rightPtr);\r\n      this.memoryManager.free(bottomPtr);\r\n\r\n      const deviceXPtr = this.memoryManager.malloc(4);\r\n      const deviceYPtr = this.memoryManager.malloc(4);\r\n      this.pdfiumModule.FPDF_PageToDevice(\r\n        pagePtr,\r\n        0,\r\n        0,\r\n        page.size.width,\r\n        page.size.height,\r\n        0,\r\n        left,\r\n        top,\r\n        deviceXPtr,\r\n        deviceYPtr,\r\n      );\r\n      const x = this.pdfiumModule.pdfium.getValue(deviceXPtr, 'i32');\r\n      const y = this.pdfiumModule.pdfium.getValue(deviceYPtr, 'i32');\r\n      this.memoryManager.free(deviceXPtr);\r\n      this.memoryManager.free(deviceYPtr);\r\n\r\n      const rect = {\r\n        origin: {\r\n          x,\r\n          y,\r\n        },\r\n        size: {\r\n          width: Math.ceil(Math.abs(right - left)),\r\n          height: Math.ceil(Math.abs(top - bottom)),\r\n        },\r\n      };\r\n\r\n      const utf16Length = this.pdfiumModule.FPDFText_GetBoundedText(\r\n        textPagePtr,\r\n        left,\r\n        top,\r\n        right,\r\n        bottom,\r\n        0,\r\n        0,\r\n      );\r\n      const bytesCount = (utf16Length + 1) * 2; // include NIL\r\n      const textBuffer = this.memoryManager.malloc(bytesCount);\r\n      this.pdfiumModule.FPDFText_GetBoundedText(\r\n        textPagePtr,\r\n        left,\r\n        top,\r\n        right,\r\n        bottom,\r\n        textBuffer,\r\n        utf16Length,\r\n      );\r\n      const content = this.pdfiumModule.pdfium.UTF16ToString(textBuffer);\r\n      this.memoryManager.free(textBuffer);\r\n\r\n      const charIndex = this.pdfiumModule.FPDFText_GetCharIndexAtPos(textPagePtr, left, top, 2, 2);\r\n      let fontFamily = '';\r\n      let fontSize = rect.size.height;\r\n      if (charIndex >= 0) {\r\n        fontSize = this.pdfiumModule.FPDFText_GetFontSize(textPagePtr, charIndex);\r\n\r\n        const fontNameLength = this.pdfiumModule.FPDFText_GetFontInfo(\r\n          textPagePtr,\r\n          charIndex,\r\n          0,\r\n          0,\r\n          0,\r\n        );\r\n\r\n        const bytesCount = fontNameLength + 1; // include NIL\r\n        const textBufferPtr = this.memoryManager.malloc(bytesCount);\r\n        const flagsPtr = this.memoryManager.malloc(4);\r\n        this.pdfiumModule.FPDFText_GetFontInfo(\r\n          textPagePtr,\r\n          charIndex,\r\n          textBufferPtr,\r\n          bytesCount,\r\n          flagsPtr,\r\n        );\r\n        fontFamily = this.pdfiumModule.pdfium.UTF8ToString(textBufferPtr);\r\n        this.memoryManager.free(textBufferPtr);\r\n        this.memoryManager.free(flagsPtr);\r\n      }\r\n\r\n      const textRect: PdfTextRectObject = {\r\n        content,\r\n        rect,\r\n        font: {\r\n          family: fontFamily,\r\n          size: fontSize,\r\n        },\r\n      };\r\n\r\n      textRects.push(textRect);\r\n    }\r\n\r\n    return textRects;\r\n  }\r\n\r\n  /**\r\n   * Return geometric + logical text layout for one page\r\n   * (glyph-only implementation, no FPDFText_GetRect).\r\n   *\r\n   * @public\r\n   */\r\n  getPageGeometry(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfPageGeometry> {\r\n    const label = 'getPageGeometry';\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, 'Begin', doc.id);\r\n\r\n    /* ── guards ───────────────────────────────────────────── */\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    /* ── native handles ──────────────────────────────────── */\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const textPagePtr = pageCtx.getTextPage();\r\n\r\n    /* ── 1. read ALL glyphs in logical order ─────────────── */\r\n    const glyphCount = this.pdfiumModule.FPDFText_CountChars(textPagePtr);\r\n    const glyphs: PdfGlyphObject[] = [];\r\n\r\n    for (let i = 0; i < glyphCount; i++) {\r\n      const g = this.readGlyphInfo(page, pageCtx.pagePtr, textPagePtr, i);\r\n      glyphs.push(g);\r\n    }\r\n\r\n    /* ── 2. build visual runs from glyph stream ───────────── */\r\n    const runs: PdfRun[] = this.buildRunsFromGlyphs(glyphs, textPagePtr);\r\n\r\n    /* ── 3. cleanup & resolve task ───────────────────────── */\r\n    pageCtx.release();\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, 'End', doc.id);\r\n    return PdfTaskHelper.resolve({ runs });\r\n  }\r\n\r\n  /**\r\n   * Group consecutive glyphs that belong to the same CPDF_TextObject\r\n   * using FPDFText_GetTextObject(), and calculate rotation from glyph positions.\r\n   */\r\n  private buildRunsFromGlyphs(glyphs: PdfGlyphObject[], textPagePtr: number): PdfRun[] {\r\n    const runs: PdfRun[] = [];\r\n    let current: PdfRun | null = null;\r\n    let curObjPtr: number | null = null;\r\n    let bounds: { minX: number; minY: number; maxX: number; maxY: number } | null = null;\r\n\r\n    /** ── main loop ──────────────────────────────────────────── */\r\n    for (let i = 0; i < glyphs.length; i++) {\r\n      const g = glyphs[i];\r\n\r\n      /* 1 — find the CPDF_TextObject this glyph belongs to */\r\n      const objPtr = this.pdfiumModule.FPDFText_GetTextObject(textPagePtr, i) as number;\r\n\r\n      /* 2 — start a new run when the text object changes */\r\n      if (objPtr !== curObjPtr) {\r\n        curObjPtr = objPtr;\r\n        current = {\r\n          rect: {\r\n            x: g.origin.x,\r\n            y: g.origin.y,\r\n            width: g.size.width,\r\n            height: g.size.height,\r\n          },\r\n          charStart: i,\r\n          glyphs: [],\r\n        };\r\n        bounds = {\r\n          minX: g.origin.x,\r\n          minY: g.origin.y,\r\n          maxX: g.origin.x + g.size.width,\r\n          maxY: g.origin.y + g.size.height,\r\n        };\r\n        runs.push(current);\r\n      }\r\n\r\n      /* 3 — append the slim glyph record */\r\n      current!.glyphs.push({\r\n        x: g.origin.x,\r\n        y: g.origin.y,\r\n        width: g.size.width,\r\n        height: g.size.height,\r\n        flags: g.isEmpty ? 2 : g.isSpace ? 1 : 0,\r\n      });\r\n\r\n      /* 4 — expand the run's bounding rect */\r\n      if (g.isEmpty) {\r\n        continue;\r\n      }\r\n\r\n      const right = g.origin.x + g.size.width;\r\n      const bottom = g.origin.y + g.size.height;\r\n\r\n      // Update bounds\r\n      bounds!.minX = Math.min(bounds!.minX, g.origin.x);\r\n      bounds!.minY = Math.min(bounds!.minY, g.origin.y);\r\n      bounds!.maxX = Math.max(bounds!.maxX, right);\r\n      bounds!.maxY = Math.max(bounds!.maxY, bottom);\r\n\r\n      // Calculate final rect from bounds\r\n      current!.rect.x = bounds!.minX;\r\n      current!.rect.y = bounds!.minY;\r\n      current!.rect.width = bounds!.maxX - bounds!.minX;\r\n      current!.rect.height = bounds!.maxY - bounds!.minY;\r\n    }\r\n\r\n    return runs;\r\n  }\r\n\r\n  /**\r\n   * Extract glyph geometry + metadata for `charIndex`\r\n   *\r\n   * Returns device–space coordinates:\r\n   *   x,y  → **top-left** corner (integer-pixels)\r\n   *   w,h  → width / height (integer-pixels, ≥ 1)\r\n   *\r\n   * And two flags:\r\n   *   isSpace → true if the glyph's Unicode code-point is U+0020\r\n   */\r\n  private readGlyphInfo(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    textPagePtr: number,\r\n    charIndex: number,\r\n  ): PdfGlyphObject {\r\n    // ── native stack temp pointers ──────────────────────────────\r\n    const dx1Ptr = this.memoryManager.malloc(4);\r\n    const dy1Ptr = this.memoryManager.malloc(4);\r\n    const dx2Ptr = this.memoryManager.malloc(4);\r\n    const dy2Ptr = this.memoryManager.malloc(4);\r\n    const rectPtr = this.memoryManager.malloc(16); // 4 floats = 16 bytes\r\n\r\n    let x = 0,\r\n      y = 0,\r\n      width = 0,\r\n      height = 0,\r\n      isSpace = false;\r\n\r\n    // ── 1) raw glyph bbox in                      page-user-space\r\n    if (this.pdfiumModule.FPDFText_GetLooseCharBox(textPagePtr, charIndex, rectPtr)) {\r\n      const left = this.pdfiumModule.pdfium.getValue(rectPtr, 'float');\r\n      const top = this.pdfiumModule.pdfium.getValue(rectPtr + 4, 'float');\r\n      const right = this.pdfiumModule.pdfium.getValue(rectPtr + 8, 'float');\r\n      const bottom = this.pdfiumModule.pdfium.getValue(rectPtr + 12, 'float');\r\n\r\n      if (left === right || top === bottom) {\r\n        [rectPtr, dx1Ptr, dy1Ptr, dx2Ptr, dy2Ptr].forEach((p) => this.memoryManager.free(p));\r\n\r\n        return {\r\n          origin: { x: 0, y: 0 },\r\n          size: { width: 0, height: 0 },\r\n          isEmpty: true,\r\n        };\r\n      }\r\n\r\n      // ── 2) map 2 opposite corners to            device-space\r\n      this.pdfiumModule.FPDF_PageToDevice(\r\n        pagePtr,\r\n        0,\r\n        0,\r\n        page.size.width,\r\n        page.size.height,\r\n        /*rotate=*/ 0,\r\n        left,\r\n        top,\r\n        dx1Ptr,\r\n        dy1Ptr,\r\n      );\r\n      this.pdfiumModule.FPDF_PageToDevice(\r\n        pagePtr,\r\n        0,\r\n        0,\r\n        page.size.width,\r\n        page.size.height,\r\n        /*rotate=*/ 0,\r\n        right,\r\n        bottom,\r\n        dx2Ptr,\r\n        dy2Ptr,\r\n      );\r\n\r\n      const x1 = this.pdfiumModule.pdfium.getValue(dx1Ptr, 'i32');\r\n      const y1 = this.pdfiumModule.pdfium.getValue(dy1Ptr, 'i32');\r\n      const x2 = this.pdfiumModule.pdfium.getValue(dx2Ptr, 'i32');\r\n      const y2 = this.pdfiumModule.pdfium.getValue(dy2Ptr, 'i32');\r\n\r\n      x = Math.min(x1, x2);\r\n      y = Math.min(y1, y2);\r\n      width = Math.max(1, Math.abs(x2 - x1));\r\n      height = Math.max(1, Math.abs(y2 - y1));\r\n\r\n      // ── 3) extra flags ───────────────────────────────────────\r\n      const uc = this.pdfiumModule.FPDFText_GetUnicode(textPagePtr, charIndex);\r\n      isSpace = uc === 32;\r\n    }\r\n\r\n    // ── free tmps ───────────────────────────────────────────────\r\n    [rectPtr, dx1Ptr, dy1Ptr, dx2Ptr, dy2Ptr].forEach((p) => this.memoryManager.free(p));\r\n\r\n    return {\r\n      origin: { x, y },\r\n      size: { width, height },\r\n      ...(isSpace && { isSpace }),\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Geometry-only text extraction\r\n   * ------------------------------------------\r\n   * Returns every glyph on the requested page\r\n   * in the logical order delivered by PDFium.\r\n   *\r\n   * The promise resolves to an array of objects:\r\n   *   {\r\n   *     idx:     number;            // glyph index on the page (0…n-1)\r\n   *     origin:  { x: number; y: number };\r\n   *     size:    { width: number;  height: number };\r\n   *     angle:   number;            // degrees, counter-clock-wise\r\n   *     isSpace: boolean;           // true  → U+0020\r\n   *   }\r\n   *\r\n   * No Unicode is included; front-end decides whether to hydrate it.\r\n   */\r\n  public getPageGlyphs(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfGlyphObject[]> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'getPageGlyphs', doc, page);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'getPageGlyphs', 'Begin', doc.id);\r\n\r\n    // ── 1) safety: document handle must be alive ───────────────\r\n    const ctx = this.cache.getContext(doc.id);\r\n\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'getPageGlyphs', 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    // ── 2) load page + text page handles ───────────────────────\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const textPagePtr = pageCtx.getTextPage();\r\n\r\n    // ── 3) iterate all glyphs in logical order ─────────────────\r\n    const total = this.pdfiumModule.FPDFText_CountChars(textPagePtr);\r\n    const glyphs = new Array(total);\r\n\r\n    for (let i = 0; i < total; i++) {\r\n      const g = this.readGlyphInfo(page, pageCtx.pagePtr, textPagePtr, i);\r\n\r\n      if (g.isEmpty) {\r\n        continue;\r\n      }\r\n\r\n      glyphs[i] = { ...g };\r\n    }\r\n\r\n    // ── 4) clean-up native handles ─────────────────────────────\r\n    pageCtx.release();\r\n\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'getPageGlyphs', 'End', doc.id);\r\n\r\n    return PdfTaskHelper.resolve(glyphs);\r\n  }\r\n\r\n  private readCharBox(\r\n    page: PdfPageObject,\r\n    pagePtr: number,\r\n    textPagePtr: number,\r\n    charIndex: number,\r\n  ): Rect {\r\n    const topPtr = this.memoryManager.malloc(8);\r\n    const leftPtr = this.memoryManager.malloc(8);\r\n    const bottomPtr = this.memoryManager.malloc(8);\r\n    const rightPtr = this.memoryManager.malloc(8);\r\n    let x = 0;\r\n    let y = 0;\r\n    let width = 0;\r\n    let height = 0;\r\n    if (\r\n      this.pdfiumModule.FPDFText_GetCharBox(\r\n        textPagePtr,\r\n        charIndex,\r\n        leftPtr,\r\n        rightPtr,\r\n        bottomPtr,\r\n        topPtr,\r\n      )\r\n    ) {\r\n      const top = this.pdfiumModule.pdfium.getValue(topPtr, 'double');\r\n      const left = this.pdfiumModule.pdfium.getValue(leftPtr, 'double');\r\n      const bottom = this.pdfiumModule.pdfium.getValue(bottomPtr, 'double');\r\n      const right = this.pdfiumModule.pdfium.getValue(rightPtr, 'double');\r\n\r\n      const deviceXPtr = this.memoryManager.malloc(4);\r\n      const deviceYPtr = this.memoryManager.malloc(4);\r\n      this.pdfiumModule.FPDF_PageToDevice(\r\n        pagePtr,\r\n        0,\r\n        0,\r\n        page.size.width,\r\n        page.size.height,\r\n        0,\r\n        left,\r\n        top,\r\n        deviceXPtr,\r\n        deviceYPtr,\r\n      );\r\n      x = this.pdfiumModule.pdfium.getValue(deviceXPtr, 'i32');\r\n      y = this.pdfiumModule.pdfium.getValue(deviceYPtr, 'i32');\r\n      this.memoryManager.free(deviceXPtr);\r\n      this.memoryManager.free(deviceYPtr);\r\n\r\n      width = Math.ceil(Math.abs(right - left));\r\n      height = Math.ceil(Math.abs(top - bottom));\r\n    }\r\n    this.memoryManager.free(topPtr);\r\n    this.memoryManager.free(leftPtr);\r\n    this.memoryManager.free(bottomPtr);\r\n    this.memoryManager.free(rightPtr);\r\n\r\n    return {\r\n      origin: {\r\n        x,\r\n        y,\r\n      },\r\n      size: {\r\n        width,\r\n        height,\r\n      },\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read page annotations\r\n   *\r\n   * @param ctx - document context\r\n   * @param page - page info\r\n   * @returns annotations on the pdf page\r\n   *\r\n   * @private\r\n   */\r\n  private readPageAnnotations(ctx: DocumentContext, page: PdfPageObject) {\r\n    return ctx.borrowPage(page.index, (pageCtx) => {\r\n      const annotationCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);\r\n\r\n      const annotations: PdfAnnotationObject[] = [];\r\n      for (let i = 0; i < annotationCount; i++) {\r\n        pageCtx.withAnnotation(i, (annotPtr) => {\r\n          const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr, pageCtx);\r\n          if (anno) annotations.push(anno);\r\n        });\r\n      }\r\n      return annotations;\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Read page annotations\r\n   *\r\n   * @param ctx - document context\r\n   * @param page - page info\r\n   * @returns annotations on the pdf page\r\n   *\r\n   * @private\r\n   */\r\n  private readPageAnnotationsRaw(ctx: DocumentContext, page: PdfPageObject): PdfAnnotationObject[] {\r\n    const count = this.pdfiumModule.EPDFPage_GetAnnotCountRaw(ctx.docPtr, page.index);\r\n    if (count <= 0) return [];\r\n\r\n    const out: PdfAnnotationObject[] = [];\r\n\r\n    for (let i = 0; i < count; ++i) {\r\n      const annotPtr = this.pdfiumModule.EPDFPage_GetAnnotRaw(ctx.docPtr, page.index, i);\r\n      if (!annotPtr) continue;\r\n\r\n      try {\r\n        const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr);\r\n        if (anno) out.push(anno);\r\n      } finally {\r\n        this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);\r\n      }\r\n    }\r\n    return out;\r\n  }\r\n\r\n  /**\r\n   * Read pdf annotation from pdf document\r\n   *\r\n   * @param docPtr - pointer to pdf document\r\n   * @param page - page info\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param pageCtx - page context\r\n   * @returns pdf annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPageAnnotation(\r\n    docPtr: number,\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    pageCtx?: PageContext,\r\n  ) {\r\n    let index = this.getAnnotString(annotationPtr, 'NM');\r\n    if (!index || !isUuidV4(index)) {\r\n      index = uuidV4();\r\n      this.setAnnotString(annotationPtr, 'NM', index);\r\n    }\r\n    const subType = this.pdfiumModule.FPDFAnnot_GetSubtype(\r\n      annotationPtr,\r\n    ) as PdfAnnotationObject['type'];\r\n    let annotation: PdfAnnotationObject | undefined;\r\n    switch (subType) {\r\n      case PdfAnnotationSubtype.TEXT:\r\n        {\r\n          annotation = this.readPdfTextAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.FREETEXT:\r\n        {\r\n          annotation = this.readPdfFreeTextAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.LINK:\r\n        {\r\n          annotation = this.readPdfLinkAnno(page, docPtr, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.WIDGET:\r\n        if (pageCtx) {\r\n          return this.readPdfWidgetAnno(page, annotationPtr, pageCtx.getFormHandle(), index);\r\n        }\r\n      case PdfAnnotationSubtype.FILEATTACHMENT:\r\n        {\r\n          annotation = this.readPdfFileAttachmentAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.INK:\r\n        {\r\n          annotation = this.readPdfInkAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.POLYGON:\r\n        {\r\n          annotation = this.readPdfPolygonAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.POLYLINE:\r\n        {\r\n          annotation = this.readPdfPolylineAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.LINE:\r\n        {\r\n          annotation = this.readPdfLineAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.HIGHLIGHT:\r\n        annotation = this.readPdfHighlightAnno(page, annotationPtr, index);\r\n        break;\r\n      case PdfAnnotationSubtype.STAMP:\r\n        {\r\n          annotation = this.readPdfStampAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.SQUARE:\r\n        {\r\n          annotation = this.readPdfSquareAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.CIRCLE:\r\n        {\r\n          annotation = this.readPdfCircleAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.UNDERLINE:\r\n        {\r\n          annotation = this.readPdfUnderlineAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.SQUIGGLY:\r\n        {\r\n          annotation = this.readPdfSquigglyAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.STRIKEOUT:\r\n        {\r\n          annotation = this.readPdfStrikeOutAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      case PdfAnnotationSubtype.CARET:\r\n        {\r\n          annotation = this.readPdfCaretAnno(page, annotationPtr, index);\r\n        }\r\n        break;\r\n      default:\r\n        {\r\n          annotation = this.readPdfAnno(page, subType, annotationPtr, index);\r\n        }\r\n        break;\r\n    }\r\n\r\n    return annotation;\r\n  }\r\n\r\n  /**\r\n   * Return the colour stored directly in the annotation dictionary's `/C` entry.\r\n   *\r\n   * Most PDFs created by Acrobat, Microsoft Office, LaTeX, etc. include this entry.\r\n   * When the key is absent (common in macOS Preview, Chrome, Drawboard) the call\r\n   * fails and the function returns `undefined`.\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @returns An RGBA tuple (0-255 channels) or `undefined` if no `/C` entry exists\r\n   *\r\n   * @private\r\n   */\r\n  private readAnnotationColor(\r\n    annotationPtr: number,\r\n    colorType: PdfAnnotationColorType = PdfAnnotationColorType.Color,\r\n  ): PdfColor | undefined {\r\n    const rPtr = this.memoryManager.malloc(4);\r\n    const gPtr = this.memoryManager.malloc(4);\r\n    const bPtr = this.memoryManager.malloc(4);\r\n\r\n    // colourType 0 = \"colour\" (stroke/fill); other types are interior/border\r\n    const ok = this.pdfiumModule.EPDFAnnot_GetColor(annotationPtr, colorType, rPtr, gPtr, bPtr);\r\n\r\n    let colour: PdfColor | undefined;\r\n\r\n    if (ok) {\r\n      colour = {\r\n        red: this.pdfiumModule.pdfium.getValue(rPtr, 'i32') & 0xff,\r\n        green: this.pdfiumModule.pdfium.getValue(gPtr, 'i32') & 0xff,\r\n        blue: this.pdfiumModule.pdfium.getValue(bPtr, 'i32') & 0xff,\r\n      };\r\n    }\r\n\r\n    this.memoryManager.free(rPtr);\r\n    this.memoryManager.free(gPtr);\r\n    this.memoryManager.free(bPtr);\r\n\r\n    return colour;\r\n  }\r\n\r\n  /**\r\n   * Get the fill/stroke colour annotation.\r\n   *\r\n   * @param annotationPtr - pointer to the annotation whose colour is being set\r\n   * @param colorType - which colour to get (0 = fill, 1 = stroke)\r\n   * @returns WebColor with hex color\r\n   *\r\n   * @private\r\n   */\r\n  private getAnnotationColor(\r\n    annotationPtr: number,\r\n    colorType: PdfAnnotationColorType = PdfAnnotationColorType.Color,\r\n  ): WebColor | undefined {\r\n    const annotationColor = this.readAnnotationColor(annotationPtr, colorType);\r\n\r\n    return annotationColor ? pdfColorToWebColor(annotationColor) : undefined;\r\n  }\r\n\r\n  /**\r\n   * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.\r\n   *\r\n   * @param annotationPtr - pointer to the annotation whose colour is being set\r\n   * @param webAlphaColor - WebAlphaColor with hex color and opacity (0-1)\r\n   * @param shouldClearAP - whether to clear the /AP entry\r\n   * @param which - which colour to set (0 = fill, 1 = stroke)\r\n   * @returns `true` if the operation was successful\r\n   *\r\n   * @private\r\n   */\r\n  private setAnnotationColor(\r\n    annotationPtr: number,\r\n    webColor: WebColor,\r\n    colorType: PdfAnnotationColorType = PdfAnnotationColorType.Color,\r\n  ): boolean {\r\n    const pdfColor = webColorToPdfColor(webColor);\r\n\r\n    return this.pdfiumModule.EPDFAnnot_SetColor(\r\n      annotationPtr,\r\n      colorType,\r\n      pdfColor.red & 0xff,\r\n      pdfColor.green & 0xff,\r\n      pdfColor.blue & 0xff,\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Get the opacity of the annotation.\r\n   *\r\n   * @param annotationPtr - pointer to the annotation whose opacity is being set\r\n   * @returns opacity (0-1)\r\n   *\r\n   * @private\r\n   */\r\n  private getAnnotationOpacity(annotationPtr: number): number {\r\n    const opacityPtr = this.memoryManager.malloc(4);\r\n    const ok = this.pdfiumModule.EPDFAnnot_GetOpacity(annotationPtr, opacityPtr);\r\n    const opacity = ok ? this.pdfiumModule.pdfium.getValue(opacityPtr, 'i32') : 255;\r\n    this.memoryManager.free(opacityPtr);\r\n    return pdfAlphaToWebOpacity(opacity);\r\n  }\r\n\r\n  /**\r\n   * Set the opacity of the annotation.\r\n   *\r\n   * @param annotationPtr - pointer to the annotation whose opacity is being set\r\n   * @param opacity - opacity (0-1)\r\n   * @returns true on success\r\n   *\r\n   * @private\r\n   */\r\n  private setAnnotationOpacity(annotationPtr: number, opacity: number): boolean {\r\n    const pdfOpacity = webOpacityToPdfAlpha(opacity);\r\n    return this.pdfiumModule.EPDFAnnot_SetOpacity(annotationPtr, pdfOpacity & 0xff);\r\n  }\r\n\r\n  /**\r\n   * Fetch the `/Q` text-alignment value from a **FreeText** annotation.\r\n   *\r\n   * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`\r\n   * @returns `PdfTextAlignment`\r\n   */\r\n  private getAnnotationTextAlignment(annotationPtr: number): PdfTextAlignment {\r\n    return this.pdfiumModule.EPDFAnnot_GetTextAlignment(annotationPtr);\r\n  }\r\n\r\n  /**\r\n   * Write the `/Q` text-alignment value into a **FreeText** annotation\r\n   * and clear the existing appearance stream so it can be regenerated.\r\n   *\r\n   * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`\r\n   * @param alignment     `PdfTextAlignment`\r\n   * @returns `true` on success\r\n   */\r\n  private setAnnotationTextAlignment(annotationPtr: number, alignment: PdfTextAlignment): boolean {\r\n    return !!this.pdfiumModule.EPDFAnnot_SetTextAlignment(annotationPtr, alignment);\r\n  }\r\n\r\n  /**\r\n   * Fetch the `/EPDF:VerticalAlignment` vertical-alignment value from a **FreeText** annotation.\r\n   *\r\n   * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`\r\n   * @returns `PdfVerticalAlignment`\r\n   */\r\n  private getAnnotationVerticalAlignment(annotationPtr: number): PdfVerticalAlignment {\r\n    return this.pdfiumModule.EPDFAnnot_GetVerticalAlignment(annotationPtr);\r\n  }\r\n\r\n  /**\r\n   * Write the `/EPDF:VerticalAlignment` vertical-alignment value into a **FreeText** annotation\r\n   * and clear the existing appearance stream so it can be regenerated.\r\n   *\r\n   * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`\r\n   * @param alignment     `PdfVerticalAlignment`\r\n   * @returns `true` on success\r\n   */\r\n  private setAnnotationVerticalAlignment(\r\n    annotationPtr: number,\r\n    alignment: PdfVerticalAlignment,\r\n  ): boolean {\r\n    return !!this.pdfiumModule.EPDFAnnot_SetVerticalAlignment(annotationPtr, alignment);\r\n  }\r\n\r\n  /**\r\n   * Return the **default appearance** (font, size, colour) declared in the\r\n   * `/DA` string of a **FreeText** annotation.\r\n   *\r\n   * @param annotationPtr  pointer to `FPDF_ANNOTATION`\r\n   * @returns `{ font, fontSize, color }` or `undefined` when PDFium returns false\r\n   *\r\n   * NOTE – `font` is the raw `FPDF_STANDARD_FONT` enum value that PDFium uses\r\n   *        (same range as the C API: 0 = Courier, 12 = ZapfDingbats, …).\r\n   */\r\n  private getAnnotationDefaultAppearance(\r\n    annotationPtr: number,\r\n  ): { fontFamily: PdfStandardFont; fontSize: number; fontColor: WebColor } | undefined {\r\n    const fontPtr = this.memoryManager.malloc(4);\r\n    const sizePtr = this.memoryManager.malloc(4);\r\n    const rPtr = this.memoryManager.malloc(4);\r\n    const gPtr = this.memoryManager.malloc(4);\r\n    const bPtr = this.memoryManager.malloc(4);\r\n\r\n    const ok = !!this.pdfiumModule.EPDFAnnot_GetDefaultAppearance(\r\n      annotationPtr,\r\n      fontPtr,\r\n      sizePtr,\r\n      rPtr,\r\n      gPtr,\r\n      bPtr,\r\n    );\r\n\r\n    if (!ok) {\r\n      [fontPtr, sizePtr, rPtr, gPtr, bPtr].forEach((p) => this.memoryManager.free(p));\r\n      return; // undefined – caller decides what to do\r\n    }\r\n\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    const font = pdf.getValue(fontPtr, 'i32');\r\n    const fontSize = pdf.getValue(sizePtr, 'float');\r\n    const red = pdf.getValue(rPtr, 'i32') & 0xff;\r\n    const green = pdf.getValue(gPtr, 'i32') & 0xff;\r\n    const blue = pdf.getValue(bPtr, 'i32') & 0xff;\r\n\r\n    [fontPtr, sizePtr, rPtr, gPtr, bPtr].forEach((p) => this.memoryManager.free(p));\r\n\r\n    return {\r\n      fontFamily: font,\r\n      fontSize,\r\n      fontColor: pdfColorToWebColor({ red, green, blue }),\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Write a **default appearance** (`/DA`) into a FreeText annotation.\r\n   *\r\n   * @param annotationPtr pointer to `FPDF_ANNOTATION`\r\n   * @param font          `FPDF_STANDARD_FONT` enum value\r\n   * @param fontSize      size in points (≥ 0)\r\n   * @param color         CSS-style `#rrggbb` string (alpha ignored)\r\n   * @returns `true` on success\r\n   */\r\n  private setAnnotationDefaultAppearance(\r\n    annotationPtr: number,\r\n    font: PdfStandardFont,\r\n    fontSize: number,\r\n    color: WebColor,\r\n  ): boolean {\r\n    const { red, green, blue } = webColorToPdfColor(color); // 0-255 ints\r\n\r\n    return !!this.pdfiumModule.EPDFAnnot_SetDefaultAppearance(\r\n      annotationPtr,\r\n      font,\r\n      fontSize,\r\n      red & 0xff,\r\n      green & 0xff,\r\n      blue & 0xff,\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Border‐style + width helper\r\n   *\r\n   * Tries the new PDFium helper `EPDFAnnot_GetBorderStyle()` (patch series\r\n   * 9 July 2025).\r\n   *\r\n   * @param  annotationPtr  pointer to an `FPDF_ANNOTATION`\r\n   * @returns `{ ok, style, width }`\r\n   *          • `ok`     – `true` when the call succeeded\r\n   *          • `style`  – `PdfAnnotationBorderStyle` enum\r\n   *          • `width`  – stroke-width in points (defaults to 0 pt)\r\n   */\r\n  private getBorderStyle(annotationPtr: number): {\r\n    ok: boolean;\r\n    style: PdfAnnotationBorderStyle;\r\n    width: number;\r\n  } {\r\n    /* 1 ── allocate tmp storage for the returned width ─────────────── */\r\n    const widthPtr = this.memoryManager.malloc(4);\r\n    let width = 0;\r\n    let style: PdfAnnotationBorderStyle = PdfAnnotationBorderStyle.UNKNOWN;\r\n    let ok = false;\r\n\r\n    style = this.pdfiumModule.EPDFAnnot_GetBorderStyle(annotationPtr, widthPtr);\r\n    width = this.pdfiumModule.pdfium.getValue(widthPtr, 'float');\r\n    ok = style !== PdfAnnotationBorderStyle.UNKNOWN;\r\n    this.memoryManager.free(widthPtr);\r\n    return { ok, style, width };\r\n  }\r\n\r\n  private setBorderStyle(\r\n    annotationPtr: number,\r\n    style: PdfAnnotationBorderStyle,\r\n    width: number,\r\n  ): boolean {\r\n    return this.pdfiumModule.EPDFAnnot_SetBorderStyle(annotationPtr, style, width);\r\n  }\r\n\r\n  /**\r\n   * Get the icon of the annotation\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @returns `PdfAnnotationIcon`\r\n   */\r\n  private getAnnotationIcon(annotationPtr: number): PdfAnnotationIcon {\r\n    return this.pdfiumModule.EPDFAnnot_GetIcon(annotationPtr);\r\n  }\r\n\r\n  /**\r\n   * Set the icon of the annotation\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @param icon - `PdfAnnotationIcon`\r\n   * @returns `true` on success\r\n   */\r\n  private setAnnotationIcon(annotationPtr: number, icon: PdfAnnotationIcon): boolean {\r\n    return this.pdfiumModule.EPDFAnnot_SetIcon(annotationPtr, icon);\r\n  }\r\n\r\n  /**\r\n   * Border-effect (“cloudy”) helper\r\n   *\r\n   * Calls the new PDFium function `EPDFAnnot_GetBorderEffect()` (July 2025).\r\n   *\r\n   * @param  annotationPtr  pointer to an `FPDF_ANNOTATION`\r\n   * @returns `{ ok, intensity }`\r\n   *          • `ok`        – `true` when the annotation *does* have a\r\n   *                          valid cloudy-border effect\r\n   *          • `intensity` – radius/intensity value (0 when `ok` is false)\r\n   */\r\n  private getBorderEffect(annotationPtr: number): { ok: boolean; intensity: number } {\r\n    const intensityPtr = this.memoryManager.malloc(4);\r\n\r\n    const ok = !!this.pdfiumModule.EPDFAnnot_GetBorderEffect(annotationPtr, intensityPtr);\r\n\r\n    const intensity = ok ? this.pdfiumModule.pdfium.getValue(intensityPtr, 'float') : 0;\r\n\r\n    this.memoryManager.free(intensityPtr);\r\n    return { ok, intensity };\r\n  }\r\n\r\n  /**\r\n   * Rectangle-differences helper ( /RD array on Square / Circle annots )\r\n   *\r\n   * Calls `EPDFAnnot_GetRectangleDifferences()` introduced in July 2025.\r\n   *\r\n   * @param  annotationPtr  pointer to an `FPDF_ANNOTATION`\r\n   * @returns `{ ok, left, top, right, bottom }`\r\n   *          • `ok`     – `true` when the annotation *has* an /RD entry\r\n   *          • the four floats are 0 when `ok` is false\r\n   */\r\n  private getRectangleDifferences(annotationPtr: number): {\r\n    ok: boolean;\r\n    left: number;\r\n    top: number;\r\n    right: number;\r\n    bottom: number;\r\n  } {\r\n    /* tmp storage ─────────────────────────────────────────── */\r\n    const lPtr = this.memoryManager.malloc(4);\r\n    const tPtr = this.memoryManager.malloc(4);\r\n    const rPtr = this.memoryManager.malloc(4);\r\n    const bPtr = this.memoryManager.malloc(4);\r\n\r\n    const ok = !!this.pdfiumModule.EPDFAnnot_GetRectangleDifferences(\r\n      annotationPtr,\r\n      lPtr,\r\n      tPtr,\r\n      rPtr,\r\n      bPtr,\r\n    );\r\n\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    const left = pdf.getValue(lPtr, 'float');\r\n    const top = pdf.getValue(tPtr, 'float');\r\n    const right = pdf.getValue(rPtr, 'float');\r\n    const bottom = pdf.getValue(bPtr, 'float');\r\n\r\n    /* cleanup ─────────────────────────────────────────────── */\r\n    this.memoryManager.free(lPtr);\r\n    this.memoryManager.free(tPtr);\r\n    this.memoryManager.free(rPtr);\r\n    this.memoryManager.free(bPtr);\r\n\r\n    return { ok, left, top, right, bottom };\r\n  }\r\n\r\n  /**\r\n   * Get the date of the annotation\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @param key - 'M' for modified date, 'CreationDate' for creation date\r\n   * @returns `Date` or `undefined` when PDFium can't read the date\r\n   */\r\n  private getAnnotationDate(annotationPtr: number, key: 'M' | 'CreationDate'): Date | undefined {\r\n    const raw = this.getAnnotString(annotationPtr, key);\r\n    return raw ? pdfDateToDate(raw) : undefined;\r\n  }\r\n\r\n  /**\r\n   * Set the date of the annotation\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @param key - 'M' for modified date, 'CreationDate' for creation date\r\n   * @param date - `Date` to set\r\n   * @returns `true` on success\r\n   */\r\n  private setAnnotationDate(annotationPtr: number, key: 'M' | 'CreationDate', date: Date): boolean {\r\n    const raw = dateToPdfDate(date);\r\n    return this.setAnnotString(annotationPtr, key, raw);\r\n  }\r\n\r\n  /**\r\n   * Get the date of the attachment\r\n   *\r\n   * @param attachmentPtr - pointer to an `FPDF_ATTACHMENT`\r\n   * @param key - 'ModDate' for modified date, 'CreationDate' for creation date\r\n   * @returns `Date` or `undefined` when PDFium can't read the date\r\n   */\r\n  private getAttachmentDate(\r\n    attachmentPtr: number,\r\n    key: 'ModDate' | 'CreationDate',\r\n  ): Date | undefined {\r\n    const raw = this.getAttachmentString(attachmentPtr, key);\r\n    return raw ? pdfDateToDate(raw) : undefined;\r\n  }\r\n\r\n  /**\r\n   * Set the date of the attachment\r\n   *\r\n   * @param attachmentPtr - pointer to an `FPDF_ATTACHMENT`\r\n   * @param key - 'ModDate' for modified date, 'CreationDate' for creation date\r\n   * @param date - `Date` to set\r\n   * @returns `true` on success\r\n   */\r\n  private setAttachmentDate(\r\n    attachmentPtr: number,\r\n    key: 'ModDate' | 'CreationDate',\r\n    date: Date,\r\n  ): boolean {\r\n    const raw = dateToPdfDate(date);\r\n    return this.setAttachmentString(attachmentPtr, key, raw);\r\n  }\r\n\r\n  /**\r\n   * Dash-pattern helper ( /BS → /D array, dashed borders only )\r\n   *\r\n   * Uses the two new PDFium helpers:\r\n   *   • `EPDFAnnot_GetBorderDashPatternCount`\r\n   *   • `EPDFAnnot_GetBorderDashPattern`\r\n   *\r\n   * @param  annotationPtr  pointer to an `FPDF_ANNOTATION`\r\n   * @returns `{ ok, pattern }`\r\n   *          • `ok`       – `true` when the annot is dashed *and* the array\r\n   *                          was retrieved successfully\r\n   *          • `pattern`  – numeric array of dash/space lengths (empty when `ok` is false)\r\n   */\r\n  private getBorderDashPattern(annotationPtr: number): { ok: boolean; pattern: number[] } {\r\n    const count = this.pdfiumModule.EPDFAnnot_GetBorderDashPatternCount(annotationPtr);\r\n    if (count === 0) {\r\n      return { ok: false, pattern: [] };\r\n    }\r\n\r\n    /* allocate `count` floats on the WASM heap */\r\n    const arrPtr = this.memoryManager.malloc(4 * count);\r\n    const okNative = !!this.pdfiumModule.EPDFAnnot_GetBorderDashPattern(\r\n      annotationPtr,\r\n      arrPtr,\r\n      count,\r\n    );\r\n\r\n    /* copy out */\r\n    const pattern: number[] = [];\r\n    if (okNative) {\r\n      const pdf = this.pdfiumModule.pdfium;\r\n      for (let i = 0; i < count; i++) {\r\n        pattern.push(pdf.getValue(arrPtr + 4 * i, 'float'));\r\n      }\r\n    }\r\n\r\n    this.memoryManager.free(arrPtr);\r\n    return { ok: okNative, pattern };\r\n  }\r\n\r\n  /**\r\n   * Write the /BS /D dash pattern array for an annotation border.\r\n   *\r\n   * @param annotationPtr Pointer to FPDF_ANNOTATION\r\n   * @param pattern       Array of dash/space lengths in *points* (e.g. [3, 2])\r\n   *                      Empty array clears the pattern (solid line).\r\n   * @returns true on success\r\n   *\r\n   * @private\r\n   */\r\n  private setBorderDashPattern(annotationPtr: number, pattern: number[]): boolean {\r\n    // Empty → clear the pattern (PDF spec: no /D = solid)\r\n    if (!pattern || pattern.length === 0) {\r\n      return this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(annotationPtr, 0, 0);\r\n    }\r\n\r\n    // Validate and sanitize numbers (must be positive floats, spec allows 1–8 numbers typically)\r\n    const clean = pattern.map((n) => (Number.isFinite(n) && n > 0 ? n : 0)).filter((n) => n > 0);\r\n    if (clean.length === 0) {\r\n      // nothing valid → treat as clear\r\n      return this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(annotationPtr, 0, 0);\r\n    }\r\n\r\n    const bytes = 4 * clean.length;\r\n    const bufPtr = this.memoryManager.malloc(bytes);\r\n    for (let i = 0; i < clean.length; i++) {\r\n      this.pdfiumModule.pdfium.setValue(bufPtr + 4 * i, clean[i], 'float');\r\n    }\r\n\r\n    const ok = !!this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(\r\n      annotationPtr,\r\n      bufPtr,\r\n      clean.length,\r\n    );\r\n\r\n    this.memoryManager.free(bufPtr);\r\n    return ok;\r\n  }\r\n\r\n  /**\r\n   * Return the `/LE` array (start/end line-ending styles) for a LINE / POLYLINE annot.\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @returns `{ start, end }` or `undefined` when PDFium can't read them\r\n   *\r\n   * @private\r\n   */\r\n  private getLineEndings(annotationPtr: number): LineEndings | undefined {\r\n    const startPtr = this.memoryManager.malloc(4);\r\n    const endPtr = this.memoryManager.malloc(4);\r\n\r\n    const ok = !!this.pdfiumModule.EPDFAnnot_GetLineEndings(annotationPtr, startPtr, endPtr);\r\n    if (!ok) {\r\n      this.memoryManager.free(startPtr);\r\n      this.memoryManager.free(endPtr);\r\n      return undefined;\r\n    }\r\n\r\n    const start = this.pdfiumModule.pdfium.getValue(startPtr, 'i32');\r\n    const end = this.pdfiumModule.pdfium.getValue(endPtr, 'i32');\r\n\r\n    this.memoryManager.free(startPtr);\r\n    this.memoryManager.free(endPtr);\r\n\r\n    return { start, end };\r\n  }\r\n\r\n  /**\r\n   * Write the `/LE` array (start/end line-ending styles) for a LINE / POLYLINE annot.\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @param start - start line ending style\r\n   * @param end - end line ending style\r\n   * @returns `true` on success\r\n   */\r\n  private setLineEndings(\r\n    annotationPtr: number,\r\n    start: PdfAnnotationLineEnding,\r\n    end: PdfAnnotationLineEnding,\r\n  ): boolean {\r\n    return !!this.pdfiumModule.EPDFAnnot_SetLineEndings(annotationPtr, start, end);\r\n  }\r\n\r\n  /**\r\n   * Get the start and end points of a LINE / POLYLINE annot.\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @param page - logical page info object (`PdfPageObject`)\r\n   * @returns `{ start, end }` or `undefined` when PDFium can't read them\r\n   */\r\n  private getLinePoints(page: PdfPageObject, annotationPtr: number): LinePoints | undefined {\r\n    const startPtr = this.memoryManager.malloc(8); // FS_POINTF (x,y floats)\r\n    const endPtr = this.memoryManager.malloc(8);\r\n\r\n    const ok = this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPtr, endPtr);\r\n    if (!ok) {\r\n      this.memoryManager.free(startPtr);\r\n      this.memoryManager.free(endPtr);\r\n      return undefined;\r\n    }\r\n\r\n    const pdf = this.pdfiumModule.pdfium;\r\n\r\n    const sx = pdf.getValue(startPtr + 0, 'float');\r\n    const sy = pdf.getValue(startPtr + 4, 'float');\r\n    const ex = pdf.getValue(endPtr + 0, 'float');\r\n    const ey = pdf.getValue(endPtr + 4, 'float');\r\n\r\n    this.memoryManager.free(startPtr);\r\n    this.memoryManager.free(endPtr);\r\n\r\n    // page -> device using the new helper (handles rotation/scale consistently)\r\n    const start = this.convertPagePointToDevicePoint(page, { x: sx, y: sy });\r\n    const end = this.convertPagePointToDevicePoint(page, { x: ex, y: ey });\r\n\r\n    return { start, end };\r\n  }\r\n\r\n  /**\r\n   * Set the two end‑points of a **Line** annotation\r\n   * by writing a new /L array `[ x1 y1 x2 y2 ]`.\r\n   * @param page - logical page info object (`PdfPageObject`)\r\n   * @param annotPtr - pointer to the annotation whose line points are needed\r\n   * @param start - start point\r\n   * @param end - end point\r\n   * @returns true on success\r\n   */\r\n  private setLinePoints(\r\n    page: PdfPageObject,\r\n    annotPtr: number,\r\n    start: Position,\r\n    end: Position,\r\n  ): boolean {\r\n    const p1 = this.convertDevicePointToPagePoint(page, start);\r\n    const p2 = this.convertDevicePointToPagePoint(page, end);\r\n\r\n    if (!p1 || !p2) return false;\r\n\r\n    // pack as two FS_POINTF (x,y floats)\r\n    const buf = this.memoryManager.malloc(16);\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    pdf.setValue(buf + 0, p1.x, 'float');\r\n    pdf.setValue(buf + 4, p1.y, 'float');\r\n    pdf.setValue(buf + 8, p2.x, 'float');\r\n    pdf.setValue(buf + 12, p2.y, 'float');\r\n\r\n    const ok = this.pdfiumModule.EPDFAnnot_SetLine(annotPtr, buf, buf + 8);\r\n    this.memoryManager.free(buf);\r\n    return !!ok;\r\n  }\r\n\r\n  /**\r\n   * Read `/QuadPoints` from any annotation and convert each quadrilateral to\r\n   * device-space coordinates.\r\n   *\r\n   * The four points are returned in natural reading order:\r\n   *   `p1 → p2` (top edge) and `p4 → p3` (bottom edge).\r\n   * This preserves the true shape for rotated / skewed text, whereas callers\r\n   * that only need axis-aligned boxes can collapse each quad themselves.\r\n   *\r\n   * @param page          - logical page info object (`PdfPageObject`)\r\n   * @param annotationPtr - pointer to the annotation whose quads are needed\r\n   * @returns Array of `Rect` objects (`[]` if the annotation has no quads)\r\n   *\r\n   * @private\r\n   */\r\n  private getQuadPointsAnno(page: PdfPageObject, annotationPtr: number): Rect[] {\r\n    const quadCount = this.pdfiumModule.FPDFAnnot_CountAttachmentPoints(annotationPtr);\r\n    if (quadCount === 0) return [];\r\n\r\n    const FS_QUADPOINTSF_SIZE = 8 * 4; // eight floats, 32 bytes\r\n    const quads: Quad[] = [];\r\n\r\n    for (let qi = 0; qi < quadCount; qi++) {\r\n      const quadPtr = this.memoryManager.malloc(FS_QUADPOINTSF_SIZE);\r\n\r\n      const ok = this.pdfiumModule.FPDFAnnot_GetAttachmentPoints(annotationPtr, qi, quadPtr);\r\n\r\n      if (ok) {\r\n        // read the eight floats\r\n        const xs: number[] = [];\r\n        const ys: number[] = [];\r\n        for (let i = 0; i < 4; i++) {\r\n          const base = quadPtr + i * 8; // 8 bytes per point (x+y)\r\n          xs.push(this.pdfiumModule.pdfium.getValue(base, 'float'));\r\n          ys.push(this.pdfiumModule.pdfium.getValue(base + 4, 'float'));\r\n        }\r\n\r\n        // convert to device-space\r\n        const p1 = this.convertPagePointToDevicePoint(page, { x: xs[0], y: ys[0] });\r\n        const p2 = this.convertPagePointToDevicePoint(page, { x: xs[1], y: ys[1] });\r\n        const p3 = this.convertPagePointToDevicePoint(page, { x: xs[2], y: ys[2] });\r\n        const p4 = this.convertPagePointToDevicePoint(page, { x: xs[3], y: ys[3] });\r\n\r\n        quads.push({ p1, p2, p3, p4 });\r\n      }\r\n\r\n      this.memoryManager.free(quadPtr);\r\n    }\r\n\r\n    return quads.map(quadToRect);\r\n  }\r\n\r\n  /**\r\n   * Set the quadrilaterals for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.\r\n   *\r\n   * @param page          - logical page info object (`PdfPageObject`)\r\n   * @param annotationPtr - pointer to the annotation whose quads are needed\r\n   * @param rects         - array of `Rect` objects (`[]` if the annotation has no quads)\r\n   * @returns `true` if the operation was successful\r\n   *\r\n   * @private\r\n   */\r\n  private syncQuadPointsAnno(page: PdfPageObject, annotPtr: number, rects: Rect[]): boolean {\r\n    const FS_QUADPOINTSF_SIZE = 8 * 4; // eight floats, 32 bytes\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    const count = this.pdfiumModule.FPDFAnnot_CountAttachmentPoints(annotPtr);\r\n    const buf = this.memoryManager.malloc(FS_QUADPOINTSF_SIZE);\r\n\r\n    /** write one quad into `buf` in annotation space */\r\n    const writeQuad = (r: Rect) => {\r\n      const q = rectToQuad(r); // TL, TR, BR, BL\r\n      const p1 = this.convertDevicePointToPagePoint(page, q.p1);\r\n      const p2 = this.convertDevicePointToPagePoint(page, q.p2);\r\n      const p3 = this.convertDevicePointToPagePoint(page, q.p3); // BR\r\n      const p4 = this.convertDevicePointToPagePoint(page, q.p4); // BL\r\n\r\n      // PDF QuadPoints order: BL, BR, TL, TR (bottom-left, bottom-right, top-left, top-right)\r\n      pdf.setValue(buf + 0, p1.x, 'float'); // BL (bottom-left)\r\n      pdf.setValue(buf + 4, p1.y, 'float');\r\n\r\n      pdf.setValue(buf + 8, p2.x, 'float'); // BR (bottom-right)\r\n      pdf.setValue(buf + 12, p2.y, 'float');\r\n\r\n      pdf.setValue(buf + 16, p4.x, 'float'); // TL (top-left)\r\n      pdf.setValue(buf + 20, p4.y, 'float');\r\n\r\n      pdf.setValue(buf + 24, p3.x, 'float'); // TR (top-right)\r\n      pdf.setValue(buf + 28, p3.y, 'float');\r\n    };\r\n\r\n    /* ----------------------------------------------------------------------- */\r\n    /* 1. overwrite the quads that already exist                               */\r\n    const min = Math.min(count, rects.length);\r\n    for (let i = 0; i < min; i++) {\r\n      writeQuad(rects[i]);\r\n      if (!this.pdfiumModule.FPDFAnnot_SetAttachmentPoints(annotPtr, i, buf)) {\r\n        this.memoryManager.free(buf);\r\n        return false;\r\n      }\r\n    }\r\n\r\n    /* 2. append new quads if rects.length > count                             */\r\n    for (let i = count; i < rects.length; i++) {\r\n      writeQuad(rects[i]);\r\n      if (!this.pdfiumModule.FPDFAnnot_AppendAttachmentPoints(annotPtr, buf)) {\r\n        this.memoryManager.free(buf);\r\n        return false;\r\n      }\r\n    }\r\n\r\n    this.memoryManager.free(buf);\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Redact text that intersects ANY of the provided **quads** (device-space).\r\n   * Returns `true` if the page changed. Always regenerates the page stream.\r\n   */\r\n  public redactTextInRects(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    rects: Rect[],\r\n    options?: PdfRedactTextOptions,\r\n  ): Task<boolean, PdfErrorReason> {\r\n    const { recurseForms = true, drawBlackBoxes = false } = options ?? {};\r\n\r\n    this.logger.debug(\r\n      'PDFiumEngine',\r\n      'Engine',\r\n      'redactTextInQuads',\r\n      doc.id,\r\n      page.index,\r\n      rects.length,\r\n    );\r\n    const label = 'RedactTextInQuads';\r\n    this.logger.perf('PDFiumEngine', 'Engine', label, 'Begin', `${doc.id}-${page.index}`);\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf('PDFiumEngine', 'Engine', label, 'End', `${doc.id}-${page.index}`);\r\n      return PdfTaskHelper.reject<boolean>({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    // sanitize inputs\r\n    const clean = (rects ?? []).filter(\r\n      (r) =>\r\n        r &&\r\n        Number.isFinite(r.origin?.x) &&\r\n        Number.isFinite(r.origin?.y) &&\r\n        Number.isFinite(r.size?.width) &&\r\n        Number.isFinite(r.size?.height) &&\r\n        r.size.width > 0 &&\r\n        r.size.height > 0,\r\n    );\r\n\r\n    if (clean.length === 0) {\r\n      this.logger.perf('PDFiumEngine', 'Engine', label, 'End', `${doc.id}-${page.index}`);\r\n      return PdfTaskHelper.resolve<boolean>(false);\r\n    }\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n\r\n    // pack buffer → native call\r\n    const { ptr, count } = this.allocFSQuadsBufferFromRects(page, clean);\r\n    let ok = false;\r\n    try {\r\n      // If your wrapper exposes FPDFText_RedactInQuads, call that instead.\r\n      ok = !!this.pdfiumModule.EPDFText_RedactInQuads(\r\n        pageCtx.pagePtr,\r\n        ptr,\r\n        count,\r\n        recurseForms ? true : false,\r\n        drawBlackBoxes ? true : false,\r\n      );\r\n    } finally {\r\n      this.memoryManager.free(ptr);\r\n    }\r\n\r\n    if (ok) {\r\n      ok = !!this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);\r\n    }\r\n\r\n    pageCtx.disposeImmediate();\r\n    this.logger.perf('PDFiumEngine', 'Engine', label, 'End', `${doc.id}-${page.index}`);\r\n\r\n    return PdfTaskHelper.resolve<boolean>(!!ok);\r\n  }\r\n\r\n  /** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */\r\n  private allocFSQuadsBufferFromRects(page: PdfPageObject, rects: Rect[]) {\r\n    const STRIDE = 32; // 8 floats × 4 bytes\r\n    const count = rects.length;\r\n    const ptr = this.memoryManager.malloc(STRIDE * count);\r\n    const pdf = this.pdfiumModule.pdfium;\r\n\r\n    for (let i = 0; i < count; i++) {\r\n      const r = rects[i];\r\n      const q = rectToQuad(r); // TL, TR, BR, BL (device-space)\r\n\r\n      // Convert into PAGE USER SPACE (native expects page coords)\r\n      const p1 = this.convertDevicePointToPagePoint(page, q.p1); // TL\r\n      const p2 = this.convertDevicePointToPagePoint(page, q.p2); // TR\r\n      const p3 = this.convertDevicePointToPagePoint(page, q.p3); // BR\r\n      const p4 = this.convertDevicePointToPagePoint(page, q.p4); // BL\r\n\r\n      const base = ptr + i * STRIDE;\r\n\r\n      // Keep the exact mapping you used in syncQuadPointsAnno:\r\n      // PDF QuadPoints order comment says BL,BR,TL,TR – and you wrote:\r\n      pdf.setValue(base + 0, p1.x, 'float');\r\n      pdf.setValue(base + 4, p1.y, 'float');\r\n      pdf.setValue(base + 8, p2.x, 'float');\r\n      pdf.setValue(base + 12, p2.y, 'float');\r\n      pdf.setValue(base + 16, p4.x, 'float');\r\n      pdf.setValue(base + 20, p4.y, 'float');\r\n      pdf.setValue(base + 24, p3.x, 'float');\r\n      pdf.setValue(base + 28, p3.y, 'float');\r\n    }\r\n\r\n    return { ptr, count };\r\n  }\r\n\r\n  /**\r\n   * Read ink list from annotation\r\n   * @param page  - logical page info object (`PdfPageObject`)\r\n   * @param pagePtr - pointer to the page\r\n   * @param annotationPtr - pointer to the annotation whose ink list is needed\r\n   * @returns ink list\r\n   */\r\n  private getInkList(page: PdfPageObject, annotationPtr: number): PdfInkListObject[] {\r\n    const inkList: PdfInkListObject[] = [];\r\n    const pathCount = this.pdfiumModule.FPDFAnnot_GetInkListCount(annotationPtr);\r\n    if (pathCount <= 0) return inkList;\r\n\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    const POINT_STRIDE = 8; // FS_POINTF: 2 floats (x,y) => 8 bytes\r\n\r\n    for (let i = 0; i < pathCount; i++) {\r\n      const points: Position[] = [];\r\n\r\n      const n = this.pdfiumModule.FPDFAnnot_GetInkListPath(annotationPtr, i, 0, 0);\r\n      if (n > 0) {\r\n        const buf = this.memoryManager.malloc(n * POINT_STRIDE);\r\n\r\n        // load FS_POINTF array (page-space)\r\n        this.pdfiumModule.FPDFAnnot_GetInkListPath(annotationPtr, i, buf, n);\r\n\r\n        // convert each point to device-space using your helper\r\n        for (let j = 0; j < n; j++) {\r\n          const base = buf + j * POINT_STRIDE;\r\n          const px = pdf.getValue(base + 0, 'float');\r\n          const py = pdf.getValue(base + 4, 'float');\r\n          const d = this.convertPagePointToDevicePoint(page, { x: px, y: py });\r\n          points.push({ x: d.x, y: d.y });\r\n        }\r\n\r\n        this.memoryManager.free(buf);\r\n      }\r\n\r\n      inkList.push({ points });\r\n    }\r\n\r\n    return inkList;\r\n  }\r\n\r\n  /**\r\n   * Add ink list to annotation\r\n   * @param page  - logical page info object (`PdfPageObject`)\r\n   * @param pagePtr - pointer to the page\r\n   * @param annotationPtr - pointer to the annotation whose ink list is needed\r\n   * @param inkList - ink list array of `PdfInkListObject`\r\n   * @returns `true` if the operation was successful\r\n   */\r\n  private setInkList(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    inkList: PdfInkListObject[],\r\n  ): boolean {\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    const POINT_STRIDE = 8; // FS_POINTF: float x, float y\r\n\r\n    for (const stroke of inkList) {\r\n      const n = stroke.points.length;\r\n      if (n === 0) continue;\r\n\r\n      const buf = this.memoryManager.malloc(n * POINT_STRIDE);\r\n\r\n      // device -> page for each vertex\r\n      for (let i = 0; i < n; i++) {\r\n        const pDev = stroke.points[i];\r\n        const pPage = this.convertDevicePointToPagePoint(page, pDev);\r\n\r\n        pdf.setValue(buf + i * POINT_STRIDE + 0, pPage.x, 'float');\r\n        pdf.setValue(buf + i * POINT_STRIDE + 4, pPage.y, 'float');\r\n      }\r\n\r\n      const idx = this.pdfiumModule.FPDFAnnot_AddInkStroke(annotationPtr, buf, n);\r\n      this.memoryManager.free(buf);\r\n\r\n      if (idx === -1) {\r\n        return false;\r\n      }\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Read pdf text annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf text annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfTextAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfTextAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const annoRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, annoRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const state = this.getAnnotString(annotationPtr, 'State') as PdfAnnotationState;\r\n    const stateModel = this.getAnnotString(annotationPtr, 'StateModel') as PdfAnnotationStateModel;\r\n    const color = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const inReplyToId = this.getInReplyToId(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const icon = this.getAnnotationIcon(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.TEXT,\r\n      flags,\r\n      contents,\r\n      color: color ?? '#FFFF00',\r\n      opacity,\r\n      rect,\r\n      inReplyToId,\r\n      author,\r\n      modified,\r\n      created,\r\n      state,\r\n      stateModel,\r\n      icon,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf freetext annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf freetext annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfFreeTextAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfFreeTextAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const annoRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, annoRect);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const defaultStyle = this.getAnnotString(annotationPtr, 'DS');\r\n    const da = this.getAnnotationDefaultAppearance(annotationPtr);\r\n    const backgroundColor = this.getAnnotationColor(annotationPtr);\r\n    const textAlign = this.getAnnotationTextAlignment(annotationPtr);\r\n    const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const richContent = this.getAnnotRichContent(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.FREETEXT,\r\n      fontFamily: da?.fontFamily ?? PdfStandardFont.Unknown,\r\n      fontSize: da?.fontSize ?? 12,\r\n      fontColor: da?.fontColor ?? '#000000',\r\n      verticalAlign,\r\n      backgroundColor,\r\n      flags,\r\n      opacity,\r\n      textAlign,\r\n      defaultStyle,\r\n      richContent,\r\n      contents,\r\n      author,\r\n      modified,\r\n      created,\r\n      rect,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf link annotation from pdf document\r\n   * @param page  - pdf page infor\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf link annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfLinkAnno(\r\n    page: PdfPageObject,\r\n    docPtr: number,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfLinkAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const linkPtr = this.pdfiumModule.FPDFAnnot_GetLink(annotationPtr);\r\n    if (!linkPtr) {\r\n      return;\r\n    }\r\n\r\n    const annoRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, annoRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    const target = this.readPdfLinkAnnoTarget(\r\n      docPtr,\r\n      () => {\r\n        return this.pdfiumModule.FPDFLink_GetAction(linkPtr);\r\n      },\r\n      () => {\r\n        return this.pdfiumModule.FPDFLink_GetDest(docPtr, linkPtr);\r\n      },\r\n    );\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.LINK,\r\n      flags,\r\n      target,\r\n      rect,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf widget annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param formHandle - form handle\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf widget annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfWidgetAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    formHandle: number,\r\n    index: string,\r\n  ): PdfWidgetAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.WIDGET,\r\n      flags,\r\n      rect,\r\n      field,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf file attachment annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf file attachment annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfFileAttachmentAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfFileAttachmentAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.FILEATTACHMENT,\r\n      flags,\r\n      rect,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf ink annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf ink annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfInkAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfInkAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const color = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const { width: strokeWidth } = this.getBorderStyle(annotationPtr);\r\n    const inkList = this.getInkList(page, annotationPtr);\r\n    const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);\r\n    const intent = this.getAnnotIntent(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.INK,\r\n      ...(intent && { intent }),\r\n      contents,\r\n      blendMode,\r\n      flags,\r\n      color: color ?? '#FF0000',\r\n      opacity,\r\n      strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,\r\n      rect,\r\n      inkList,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf polygon annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf polygon annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfPolygonAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfPolygonAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const vertices = this.readPdfAnnoVertices(page, annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const strokeColor = this.getAnnotationColor(annotationPtr);\r\n    const interiorColor = this.getAnnotationColor(\r\n      annotationPtr,\r\n      PdfAnnotationColorType.InteriorColor,\r\n    );\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);\r\n\r\n    let strokeDashArray: number[] | undefined;\r\n    if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {\r\n      const { ok, pattern } = this.getBorderDashPattern(annotationPtr);\r\n      if (ok) {\r\n        strokeDashArray = pattern;\r\n      }\r\n    }\r\n\r\n    // ▼––– Remove redundant closing vertex for polygons ––––––––––––––––––––––\r\n    if (vertices.length > 1) {\r\n      const first = vertices[0];\r\n      const last = vertices[vertices.length - 1];\r\n      if (first.x === last.x && first.y === last.y) {\r\n        vertices.pop();\r\n      }\r\n    }\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.POLYGON,\r\n      contents,\r\n      flags,\r\n      strokeColor: strokeColor ?? '#FF0000',\r\n      color: interiorColor ?? 'transparent',\r\n      opacity,\r\n      strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,\r\n      strokeStyle,\r\n      strokeDashArray,\r\n      rect,\r\n      vertices,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf polyline annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf polyline annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfPolylineAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfPolylineAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const vertices = this.readPdfAnnoVertices(page, annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const strokeColor = this.getAnnotationColor(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const interiorColor = this.getAnnotationColor(\r\n      annotationPtr,\r\n      PdfAnnotationColorType.InteriorColor,\r\n    );\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);\r\n\r\n    let strokeDashArray: number[] | undefined;\r\n    if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {\r\n      const { ok, pattern } = this.getBorderDashPattern(annotationPtr);\r\n      if (ok) {\r\n        strokeDashArray = pattern;\r\n      }\r\n    }\r\n    const lineEndings = this.getLineEndings(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.POLYLINE,\r\n      contents,\r\n      flags,\r\n      strokeColor: strokeColor ?? '#FF0000',\r\n      color: interiorColor ?? 'transparent',\r\n      opacity,\r\n      strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,\r\n      strokeStyle,\r\n      strokeDashArray,\r\n      lineEndings,\r\n      rect,\r\n      vertices,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf line annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf line annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfLineAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfLineAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const linePoints = this.getLinePoints(page, annotationPtr);\r\n    const lineEndings = this.getLineEndings(annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const strokeColor = this.getAnnotationColor(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const interiorColor = this.getAnnotationColor(\r\n      annotationPtr,\r\n      PdfAnnotationColorType.InteriorColor,\r\n    );\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);\r\n\r\n    let strokeDashArray: number[] | undefined;\r\n    if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {\r\n      const { ok, pattern } = this.getBorderDashPattern(annotationPtr);\r\n      if (ok) {\r\n        strokeDashArray = pattern;\r\n      }\r\n    }\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.LINE,\r\n      flags,\r\n      rect,\r\n      contents,\r\n      strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,\r\n      strokeStyle,\r\n      strokeDashArray,\r\n      strokeColor: strokeColor ?? '#FF0000',\r\n      color: interiorColor ?? 'transparent',\r\n      opacity,\r\n      linePoints: linePoints || { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } },\r\n      lineEndings: lineEndings || {\r\n        start: PdfAnnotationLineEnding.None,\r\n        end: PdfAnnotationLineEnding.None,\r\n      },\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf highlight annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf highlight annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfHighlightAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfHighlightAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const segmentRects = this.getQuadPointsAnno(page, annotationPtr);\r\n    const color = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);\r\n\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      blendMode,\r\n      type: PdfAnnotationSubtype.HIGHLIGHT,\r\n      rect,\r\n      flags,\r\n      contents,\r\n      segmentRects,\r\n      color: color ?? '#FFFF00',\r\n      opacity,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf underline annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf underline annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfUnderlineAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfUnderlineAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const segmentRects = this.getQuadPointsAnno(page, annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const color = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      blendMode,\r\n      type: PdfAnnotationSubtype.UNDERLINE,\r\n      rect,\r\n      flags,\r\n      contents,\r\n      segmentRects,\r\n      color: color ?? '#FF0000',\r\n      opacity,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read strikeout annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf strikeout annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfStrikeOutAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfStrikeOutAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const segmentRects = this.getQuadPointsAnno(page, annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const color = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      blendMode,\r\n      type: PdfAnnotationSubtype.STRIKEOUT,\r\n      flags,\r\n      rect,\r\n      contents,\r\n      segmentRects,\r\n      color: color ?? '#FF0000',\r\n      opacity,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf squiggly annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf squiggly annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfSquigglyAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfSquigglyAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const segmentRects = this.getQuadPointsAnno(page, annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const color = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      blendMode,\r\n      type: PdfAnnotationSubtype.SQUIGGLY,\r\n      rect,\r\n      flags,\r\n      contents,\r\n      segmentRects,\r\n      color: color ?? '#FF0000',\r\n      opacity,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf caret annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf caret annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfCaretAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfCaretAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.CARET,\r\n      rect,\r\n      flags,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf stamp annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf stamp annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfStampAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfStampAnnoObject | undefined {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.STAMP,\r\n      contents,\r\n      rect,\r\n      author,\r\n      modified,\r\n      created,\r\n      flags,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf object in pdf page\r\n   * @param pageObjectPtr  - pointer to pdf object in page\r\n   * @returns pdf object in page\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfPageObject(pageObjectPtr: number) {\r\n    const type = this.pdfiumModule.FPDFPageObj_GetType(pageObjectPtr) as PdfPageObjectType;\r\n    switch (type) {\r\n      case PdfPageObjectType.PATH:\r\n        return this.readPathObject(pageObjectPtr);\r\n      case PdfPageObjectType.IMAGE:\r\n        return this.readImageObject(pageObjectPtr);\r\n      case PdfPageObjectType.FORM:\r\n        return this.readFormObject(pageObjectPtr);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Read pdf path object\r\n   * @param pathObjectPtr  - pointer to pdf path object in page\r\n   * @returns pdf path object\r\n   *\r\n   * @private\r\n   */\r\n  private readPathObject(pathObjectPtr: number): PdfPathObject {\r\n    const segmentCount = this.pdfiumModule.FPDFPath_CountSegments(pathObjectPtr);\r\n\r\n    const leftPtr = this.memoryManager.malloc(4);\r\n    const bottomPtr = this.memoryManager.malloc(4);\r\n    const rightPtr = this.memoryManager.malloc(4);\r\n    const topPtr = this.memoryManager.malloc(4);\r\n    this.pdfiumModule.FPDFPageObj_GetBounds(pathObjectPtr, leftPtr, bottomPtr, rightPtr, topPtr);\r\n    const left = this.pdfiumModule.pdfium.getValue(leftPtr, 'float');\r\n    const bottom = this.pdfiumModule.pdfium.getValue(bottomPtr, 'float');\r\n    const right = this.pdfiumModule.pdfium.getValue(rightPtr, 'float');\r\n    const top = this.pdfiumModule.pdfium.getValue(topPtr, 'float');\r\n    const bounds = { left, bottom, right, top };\r\n    this.memoryManager.free(leftPtr);\r\n    this.memoryManager.free(bottomPtr);\r\n    this.memoryManager.free(rightPtr);\r\n    this.memoryManager.free(topPtr);\r\n    const segments: PdfSegmentObject[] = [];\r\n    for (let i = 0; i < segmentCount; i++) {\r\n      const segment = this.readPdfSegment(pathObjectPtr, i);\r\n      segments.push(segment);\r\n    }\r\n\r\n    const matrix = this.readPdfPageObjectTransformMatrix(pathObjectPtr);\r\n\r\n    return {\r\n      type: PdfPageObjectType.PATH,\r\n      bounds,\r\n      segments,\r\n      matrix,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read segment of pdf path object\r\n   * @param annotationObjectPtr - pointer to pdf path object\r\n   * @param segmentIndex - index of segment\r\n   * @returns pdf segment in pdf path\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfSegment(annotationObjectPtr: number, segmentIndex: number): PdfSegmentObject {\r\n    const segmentPtr = this.pdfiumModule.FPDFPath_GetPathSegment(annotationObjectPtr, segmentIndex);\r\n    const segmentType = this.pdfiumModule.FPDFPathSegment_GetType(segmentPtr);\r\n    const isClosed = this.pdfiumModule.FPDFPathSegment_GetClose(segmentPtr);\r\n    const pointXPtr = this.memoryManager.malloc(4);\r\n    const pointYPtr = this.memoryManager.malloc(4);\r\n    this.pdfiumModule.FPDFPathSegment_GetPoint(segmentPtr, pointXPtr, pointYPtr);\r\n    const pointX = this.pdfiumModule.pdfium.getValue(pointXPtr, 'float');\r\n    const pointY = this.pdfiumModule.pdfium.getValue(pointYPtr, 'float');\r\n    this.memoryManager.free(pointXPtr);\r\n    this.memoryManager.free(pointYPtr);\r\n\r\n    return {\r\n      type: segmentType,\r\n      point: { x: pointX, y: pointY },\r\n      isClosed,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf image object from pdf document\r\n   * @param pageObjectPtr  - pointer to pdf image object in page\r\n   * @returns pdf image object\r\n   *\r\n   * @private\r\n   */\r\n  private readImageObject(imageObjectPtr: number): PdfImageObject {\r\n    const bitmapPtr = this.pdfiumModule.FPDFImageObj_GetBitmap(imageObjectPtr);\r\n    const bitmapBufferPtr = this.pdfiumModule.FPDFBitmap_GetBuffer(bitmapPtr);\r\n    const bitmapWidth = this.pdfiumModule.FPDFBitmap_GetWidth(bitmapPtr);\r\n    const bitmapHeight = this.pdfiumModule.FPDFBitmap_GetHeight(bitmapPtr);\r\n    const format = this.pdfiumModule.FPDFBitmap_GetFormat(bitmapPtr) as BitmapFormat;\r\n\r\n    const pixelCount = bitmapWidth * bitmapHeight;\r\n    const bytesPerPixel = 4;\r\n    const array = new Uint8ClampedArray(pixelCount * bytesPerPixel);\r\n    for (let i = 0; i < pixelCount; i++) {\r\n      switch (format) {\r\n        case BitmapFormat.Bitmap_BGR:\r\n          {\r\n            const blue = this.pdfiumModule.pdfium.getValue(bitmapBufferPtr + i * 3, 'i8');\r\n            const green = this.pdfiumModule.pdfium.getValue(bitmapBufferPtr + i * 3 + 1, 'i8');\r\n            const red = this.pdfiumModule.pdfium.getValue(bitmapBufferPtr + i * 3 + 2, 'i8');\r\n            array[i * bytesPerPixel] = red;\r\n            array[i * bytesPerPixel + 1] = green;\r\n            array[i * bytesPerPixel + 2] = blue;\r\n            array[i * bytesPerPixel + 3] = 100;\r\n          }\r\n          break;\r\n      }\r\n    }\r\n\r\n    const imageData = new ImageData(array, bitmapWidth, bitmapHeight);\r\n    const matrix = this.readPdfPageObjectTransformMatrix(imageObjectPtr);\r\n\r\n    return {\r\n      type: PdfPageObjectType.IMAGE,\r\n      imageData,\r\n      matrix,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read form object from pdf document\r\n   * @param formObjectPtr  - pointer to pdf form object in page\r\n   * @returns pdf form object\r\n   *\r\n   * @private\r\n   */\r\n  private readFormObject(formObjectPtr: number): PdfFormObject {\r\n    const objectCount = this.pdfiumModule.FPDFFormObj_CountObjects(formObjectPtr);\r\n    const objects: (PdfFormObject | PdfImageObject | PdfPathObject)[] = [];\r\n    for (let i = 0; i < objectCount; i++) {\r\n      const pageObjectPtr = this.pdfiumModule.FPDFFormObj_GetObject(formObjectPtr, i);\r\n      const pageObj = this.readPdfPageObject(pageObjectPtr);\r\n      if (pageObj) {\r\n        objects.push(pageObj);\r\n      }\r\n    }\r\n    const matrix = this.readPdfPageObjectTransformMatrix(formObjectPtr);\r\n\r\n    return {\r\n      type: PdfPageObjectType.FORM,\r\n      objects,\r\n      matrix,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read pdf object in pdf page\r\n   * @param pageObjectPtr  - pointer to pdf object in page\r\n   * @returns pdf object in page\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfPageObjectTransformMatrix(pageObjectPtr: number): PdfTransformMatrix {\r\n    const matrixPtr = this.memoryManager.malloc(4 * 6);\r\n    if (this.pdfiumModule.FPDFPageObj_GetMatrix(pageObjectPtr, matrixPtr)) {\r\n      const a = this.pdfiumModule.pdfium.getValue(matrixPtr, 'float');\r\n      const b = this.pdfiumModule.pdfium.getValue(matrixPtr + 4, 'float');\r\n      const c = this.pdfiumModule.pdfium.getValue(matrixPtr + 8, 'float');\r\n      const d = this.pdfiumModule.pdfium.getValue(matrixPtr + 12, 'float');\r\n      const e = this.pdfiumModule.pdfium.getValue(matrixPtr + 16, 'float');\r\n      const f = this.pdfiumModule.pdfium.getValue(matrixPtr + 20, 'float');\r\n      this.memoryManager.free(matrixPtr);\r\n\r\n      return { a, b, c, d, e, f };\r\n    }\r\n\r\n    this.memoryManager.free(matrixPtr);\r\n\r\n    return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };\r\n  }\r\n\r\n  /**\r\n   * Read contents of a stamp annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @returns contents of the stamp annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readStampAnnotationContents(annotationPtr: number): PdfStampAnnoObjectContents {\r\n    const contents: PdfStampAnnoObjectContents = [];\r\n\r\n    const objectCount = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr);\r\n    for (let i = 0; i < objectCount; i++) {\r\n      const annotationObjectPtr = this.pdfiumModule.FPDFAnnot_GetObject(annotationPtr, i);\r\n\r\n      const pageObj = this.readPdfPageObject(annotationObjectPtr);\r\n      if (pageObj) {\r\n        contents.push(pageObj);\r\n      }\r\n    }\r\n\r\n    return contents;\r\n  }\r\n\r\n  /**\r\n   * Return the stroke-width declared in the annotation’s /Border or /BS entry.\r\n   * Falls back to 1 pt when nothing is defined.\r\n   *\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @returns stroke-width\r\n   *\r\n   * @private\r\n   */\r\n  private getStrokeWidth(annotationPtr: number): number {\r\n    // FPDFAnnot_GetBorder(annot, &hRadius, &vRadius, &borderWidth)\r\n    const hPtr = this.memoryManager.malloc(4);\r\n    const vPtr = this.memoryManager.malloc(4);\r\n    const wPtr = this.memoryManager.malloc(4);\r\n\r\n    const ok = this.pdfiumModule.FPDFAnnot_GetBorder(annotationPtr, hPtr, vPtr, wPtr);\r\n    const width = ok ? this.pdfiumModule.pdfium.getValue(wPtr, 'float') : 1; // default 1 pt\r\n\r\n    this.memoryManager.free(hPtr);\r\n    this.memoryManager.free(vPtr);\r\n    this.memoryManager.free(wPtr);\r\n\r\n    return width;\r\n  }\r\n\r\n  /**\r\n   * Fetches the `/F` flag bit-field from an annotation.\r\n   *\r\n   * @param annotationPtr pointer to an `FPDF_ANNOTATION`\r\n   * @returns `{ raw, flags }`\r\n   *          • `raw`   – the 32-bit integer returned by PDFium\r\n   *          • `flags` – object with individual booleans\r\n   */\r\n  private getAnnotationFlags(annotationPtr: number): PdfAnnotationFlagName[] {\r\n    const rawFlags = this.pdfiumModule.FPDFAnnot_GetFlags(annotationPtr); // number\r\n\r\n    return flagsToNames(rawFlags);\r\n  }\r\n\r\n  private setAnnotationFlags(annotationPtr: number, flags: PdfAnnotationFlagName[]): boolean {\r\n    const rawFlags = namesToFlags(flags);\r\n    return this.pdfiumModule.FPDFAnnot_SetFlags(annotationPtr, rawFlags);\r\n  }\r\n\r\n  /**\r\n   * Read circle annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf circle annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfCircleAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfCircleAnnoObject {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const interiorColor = this.getAnnotationColor(\r\n      annotationPtr,\r\n      PdfAnnotationColorType.InteriorColor,\r\n    );\r\n    const strokeColor = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);\r\n\r\n    let strokeDashArray: number[] | undefined;\r\n    if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {\r\n      const { ok, pattern } = this.getBorderDashPattern(annotationPtr);\r\n      if (ok) {\r\n        strokeDashArray = pattern;\r\n      }\r\n    }\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.CIRCLE,\r\n      flags,\r\n      color: interiorColor ?? 'transparent',\r\n      opacity,\r\n      contents,\r\n      strokeWidth,\r\n      strokeColor: strokeColor ?? '#FF0000',\r\n      strokeStyle,\r\n      rect,\r\n      author,\r\n      modified,\r\n      created,\r\n      ...(strokeDashArray !== undefined && { strokeDashArray }),\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read square annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf square annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfSquareAnno(\r\n    page: PdfPageObject,\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfSquareAnnoObject {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const contents = this.getAnnotString(annotationPtr, 'Contents') || '';\r\n    const interiorColor = this.getAnnotationColor(\r\n      annotationPtr,\r\n      PdfAnnotationColorType.InteriorColor,\r\n    );\r\n    const strokeColor = this.getAnnotationColor(annotationPtr);\r\n    const opacity = this.getAnnotationOpacity(annotationPtr);\r\n    let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);\r\n\r\n    let strokeDashArray: number[] | undefined;\r\n    if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {\r\n      const { ok, pattern } = this.getBorderDashPattern(annotationPtr);\r\n      if (ok) {\r\n        strokeDashArray = pattern;\r\n      }\r\n    }\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      type: PdfAnnotationSubtype.SQUARE,\r\n      flags,\r\n      color: interiorColor ?? 'transparent',\r\n      opacity,\r\n      contents,\r\n      strokeColor: strokeColor ?? '#FF0000',\r\n      strokeWidth,\r\n      strokeStyle,\r\n      rect,\r\n      author,\r\n      modified,\r\n      created,\r\n      ...(strokeDashArray !== undefined && { strokeDashArray }),\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read basic info of unsupported pdf annotation\r\n   * @param page  - pdf page infor\r\n   * @param type - type of annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param index  - index of annotation in the pdf page\r\n   * @returns pdf annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfAnno(\r\n    page: PdfPageObject,\r\n    type: PdfUnsupportedAnnoObject['type'],\r\n    annotationPtr: number,\r\n    index: string,\r\n  ): PdfUnsupportedAnnoObject {\r\n    const custom = this.getAnnotCustom(annotationPtr);\r\n    const pageRect = this.readPageAnnoRect(annotationPtr);\r\n    const rect = this.convertPageRectToDeviceRect(page, pageRect);\r\n    const author = this.getAnnotString(annotationPtr, 'T');\r\n    const modified = this.getAnnotationDate(annotationPtr, 'M');\r\n    const created = this.getAnnotationDate(annotationPtr, 'CreationDate');\r\n    const flags = this.getAnnotationFlags(annotationPtr);\r\n\r\n    return {\r\n      pageIndex: page.index,\r\n      custom,\r\n      id: index,\r\n      flags,\r\n      type,\r\n      rect,\r\n      author,\r\n      modified,\r\n      created,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Resolve `/IRT` → parent-annotation index on the same page.\r\n   *\r\n   * @param pagePtr        - pointer to FPDF_PAGE\r\n   * @param annotationPtr  - pointer to FPDF_ANNOTATION\r\n   * @returns index (`0…count-1`) or `undefined` when the annotation is *not* a reply\r\n   *\r\n   * @private\r\n   */\r\n  private getInReplyToId(annotationPtr: number): string | undefined {\r\n    const parentPtr = this.pdfiumModule.FPDFAnnot_GetLinkedAnnot(annotationPtr, 'IRT');\r\n    if (!parentPtr) return;\r\n\r\n    return this.getAnnotString(parentPtr, 'NM');\r\n  }\r\n\r\n  /**\r\n   * Set the in reply to id of the annotation\r\n   *\r\n   * @param annotationPtr - pointer to an `FPDF_ANNOTATION`\r\n   * @param id - the id of the parent annotation\r\n   * @returns `true` on success\r\n   */\r\n  private setInReplyToId(pagePtr: number, annotationPtr: number, id: string): boolean {\r\n    const parentPtr = this.getAnnotationByName(pagePtr, id);\r\n    if (!parentPtr) return false;\r\n\r\n    return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, 'IRT', parentPtr);\r\n  }\r\n\r\n  /**\r\n   * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.\r\n   *\r\n   * @returns decoded UTF-8 string or `undefined` when the key is absent\r\n   *\r\n   * @private\r\n   */\r\n  private getAnnotString(annotationPtr: number, key: string): string | undefined {\r\n    const len = this.pdfiumModule.FPDFAnnot_GetStringValue(annotationPtr, key, 0, 0);\r\n    if (len === 0) return;\r\n\r\n    const bytes = (len + 1) * 2;\r\n    const ptr = this.memoryManager.malloc(bytes);\r\n\r\n    this.pdfiumModule.FPDFAnnot_GetStringValue(annotationPtr, key, ptr, bytes);\r\n    const value = this.pdfiumModule.pdfium.UTF16ToString(ptr);\r\n    this.memoryManager.free(ptr);\r\n\r\n    return value || undefined;\r\n  }\r\n\r\n  /**\r\n   * Get a string value (`/T`, `/M`, `/State`, …) from an attachment.\r\n   *\r\n   * @returns decoded UTF-8 string or `undefined` when the key is absent\r\n   *\r\n   * @private\r\n   */\r\n  private getAttachmentString(attachmentPtr: number, key: string): string | undefined {\r\n    const len = this.pdfiumModule.FPDFAttachment_GetStringValue(attachmentPtr, key, 0, 0);\r\n    if (len === 0) return;\r\n\r\n    const bytes = (len + 1) * 2;\r\n    const ptr = this.memoryManager.malloc(bytes);\r\n\r\n    this.pdfiumModule.FPDFAttachment_GetStringValue(attachmentPtr, key, ptr, bytes);\r\n    const value = this.pdfiumModule.pdfium.UTF16ToString(ptr);\r\n    this.memoryManager.free(ptr);\r\n\r\n    return value || undefined;\r\n  }\r\n\r\n  /**\r\n   * Get a number value (`/Size`) from an attachment.\r\n   *\r\n   * @returns number or `null` when the key is absent\r\n   *\r\n   * @private\r\n   */\r\n  private getAttachmentNumber(attachmentPtr: number, key: string): number | undefined {\r\n    const outPtr = this.memoryManager.malloc(4); // int32\r\n    try {\r\n      const ok = this.pdfiumModule.EPDFAttachment_GetIntegerValue(\r\n        attachmentPtr,\r\n        key, // FPDF_BYTESTRING → ASCII JS string is fine in your glue\r\n        outPtr,\r\n      );\r\n      if (!ok) return undefined;\r\n      // Treat as unsigned to avoid negative values if >2GB (rare on wasm, but harmless)\r\n      return this.pdfiumModule.pdfium.getValue(outPtr, 'i32') >>> 0;\r\n    } finally {\r\n      this.memoryManager.free(outPtr);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Get custom data of the annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @returns custom data of the annotation\r\n   *\r\n   * @private\r\n   */\r\n  private getAnnotCustom(annotationPtr: number): any {\r\n    const custom = this.getAnnotString(annotationPtr, 'EPDFCustom');\r\n    if (!custom) return;\r\n\r\n    try {\r\n      return JSON.parse(custom);\r\n    } catch (error) {\r\n      console.warn('Failed to parse annotation custom data as JSON:', error);\r\n      console.warn('Invalid JSON string:', custom);\r\n      return undefined;\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Sets custom data for an annotation by safely stringifying and storing JSON\r\n   * @private\r\n   */\r\n  private setAnnotCustom(annotationPtr: number, data: any): boolean {\r\n    if (data === undefined || data === null) {\r\n      // Clear the custom data by setting empty string\r\n      return this.setAnnotString(annotationPtr, 'EPDFCustom', '');\r\n    }\r\n\r\n    try {\r\n      const jsonString = JSON.stringify(data);\r\n      return this.setAnnotString(annotationPtr, 'EPDFCustom', jsonString);\r\n    } catch (error) {\r\n      console.warn('Failed to stringify annotation custom data as JSON:', error);\r\n      console.warn('Invalid data object:', data);\r\n      return false;\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Fetches the /IT (Intent) name from an annotation as a UTF-8 JS string.\r\n   *\r\n   * Mirrors getAnnotString(): calls EPDFAnnot_GetIntent twice (length probe + copy).\r\n   * Returns `undefined` if no intent present.\r\n   */\r\n  private getAnnotIntent(annotationPtr: number): string | undefined {\r\n    const len = this.pdfiumModule.EPDFAnnot_GetIntent(annotationPtr, 0, 0);\r\n    if (len === 0) return;\r\n\r\n    const codeUnits = len + 1;\r\n    const bytes = codeUnits * 2;\r\n    const ptr = this.memoryManager.malloc(bytes);\r\n\r\n    this.pdfiumModule.EPDFAnnot_GetIntent(annotationPtr, ptr, bytes);\r\n    const value = this.pdfiumModule.pdfium.UTF16ToString(ptr);\r\n\r\n    this.memoryManager.free(ptr);\r\n\r\n    return value && value !== 'undefined' ? value : undefined;\r\n  }\r\n\r\n  /**\r\n   * Write the `/IT` (Intent) name into an annotation dictionary.\r\n   *\r\n   * Mirrors EPDFAnnot_SetIntent in PDFium (expects a UTF‑8 FPDF_BYTESTRING).\r\n   *\r\n   * @param annotationPtr Pointer returned by FPDFPage_GetAnnot\r\n   * @param intent        Name without leading slash, e.g. `\"PolygonCloud\"`\r\n   *                      A leading “/” will be stripped for convenience.\r\n   * @returns             true on success, false otherwise\r\n   */\r\n  private setAnnotIntent(annotationPtr: number, intent: string): boolean {\r\n    return this.pdfiumModule.EPDFAnnot_SetIntent(annotationPtr, intent);\r\n  }\r\n\r\n  /**\r\n   * Returns the rich‑content string stored in the annotation’s `/RC` entry.\r\n   *\r\n   * Works like `getAnnotIntent()`: first probe for length, then copy.\r\n   * `undefined` when the annotation has no rich content.\r\n   */\r\n  private getAnnotRichContent(annotationPtr: number): string | undefined {\r\n    // First call → number of UTF‑16 code units (excluding NUL)\r\n    const len = this.pdfiumModule.EPDFAnnot_GetRichContent(annotationPtr, 0, 0);\r\n    if (len === 0) return;\r\n\r\n    // +1 for the implicit NUL added by PDFium → bytes = 2 × code units\r\n    const codeUnits = len + 1;\r\n    const bytes = codeUnits * 2;\r\n    const ptr = this.memoryManager.malloc(bytes);\r\n\r\n    this.pdfiumModule.EPDFAnnot_GetRichContent(annotationPtr, ptr, bytes);\r\n    const value = this.pdfiumModule.pdfium.UTF16ToString(ptr);\r\n\r\n    this.memoryManager.free(ptr);\r\n\r\n    return value || undefined;\r\n  }\r\n\r\n  /**\r\n   * Get annotation by name\r\n   * @param pagePtr - pointer to pdf page object\r\n   * @param name - name of annotation\r\n   * @returns pointer to pdf annotation\r\n   *\r\n   * @private\r\n   */\r\n  private getAnnotationByName(pagePtr: number, name: string): number | undefined {\r\n    return this.withWString(name, (wNamePtr) => {\r\n      return this.pdfiumModule.EPDFPage_GetAnnotByName(pagePtr, wNamePtr);\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Remove annotation by name\r\n   * @param pagePtr - pointer to pdf page object\r\n   * @param name - name of annotation\r\n   * @returns true on success\r\n   *\r\n   * @private\r\n   */\r\n  private removeAnnotationByName(pagePtr: number, name: string): boolean {\r\n    return this.withWString(name, (wNamePtr) => {\r\n      return this.pdfiumModule.EPDFPage_RemoveAnnotByName(pagePtr, wNamePtr);\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Set a string value (`/T`, `/M`, `/State`, …) to an annotation.\r\n   *\r\n   * @returns `true` if the operation was successful\r\n   *\r\n   * @private\r\n   */\r\n  private setAnnotString(annotationPtr: number, key: string, value: string): boolean {\r\n    return this.withWString(value, (wValPtr) => {\r\n      return this.pdfiumModule.FPDFAnnot_SetStringValue(annotationPtr, key, wValPtr);\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Set a string value (`/T`, `/M`, `/State`, …) to an attachment.\r\n   *\r\n   * @returns `true` if the operation was successful\r\n   *\r\n   * @private\r\n   */\r\n  private setAttachmentString(attachmentPtr: number, key: string, value: string): boolean {\r\n    return this.withWString(value, (wValPtr) => {\r\n      // FPDFAttachment_SetStringValue writes into /Params dictionary\r\n      return this.pdfiumModule.FPDFAttachment_SetStringValue(attachmentPtr, key, wValPtr);\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Read vertices of pdf annotation\r\n   * @param page  - pdf page infor\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @returns vertices of pdf annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfAnnoVertices(page: PdfPageObject, annotationPtr: number): Position[] {\r\n    const vertices: Position[] = [];\r\n    const count = this.pdfiumModule.FPDFAnnot_GetVertices(annotationPtr, 0, 0);\r\n    const pointMemorySize = 8;\r\n    const pointsPtr = this.memoryManager.malloc(count * pointMemorySize);\r\n    this.pdfiumModule.FPDFAnnot_GetVertices(annotationPtr, pointsPtr, count);\r\n    for (let i = 0; i < count; i++) {\r\n      const pointX = this.pdfiumModule.pdfium.getValue(pointsPtr + i * pointMemorySize, 'float');\r\n      const pointY = this.pdfiumModule.pdfium.getValue(\r\n        pointsPtr + i * pointMemorySize + 4,\r\n        'float',\r\n      );\r\n\r\n      const { x, y } = this.convertPagePointToDevicePoint(page, {\r\n        x: pointX,\r\n        y: pointY,\r\n      });\r\n      const last = vertices[vertices.length - 1];\r\n      if (!last || last.x !== x || last.y !== y) {\r\n        vertices.push({ x, y });\r\n      }\r\n    }\r\n    this.memoryManager.free(pointsPtr);\r\n\r\n    return vertices;\r\n  }\r\n\r\n  /**\r\n   * Sync the vertices of a polygon or polyline annotation.\r\n   *\r\n   * @param page  - pdf page infor\r\n   * @param annotPtr - pointer to pdf annotation\r\n   * @param vertices - the vertices to be set\r\n   * @returns true on success\r\n   *\r\n   * @private\r\n   */\r\n  private setPdfAnnoVertices(page: PdfPageObject, annotPtr: number, vertices: Position[]): boolean {\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    const FS_POINTF_SIZE = 8;\r\n\r\n    const buf = this.memoryManager.malloc(FS_POINTF_SIZE * vertices.length);\r\n    vertices.forEach((v, i) => {\r\n      const pagePt = this.convertDevicePointToPagePoint(page, v);\r\n      pdf.setValue(buf + i * FS_POINTF_SIZE + 0, pagePt.x, 'float');\r\n      pdf.setValue(buf + i * FS_POINTF_SIZE + 4, pagePt.y, 'float');\r\n    });\r\n\r\n    const ok = this.pdfiumModule.EPDFAnnot_SetVertices(annotPtr, buf, vertices.length);\r\n    this.memoryManager.free(buf);\r\n    return ok;\r\n  }\r\n\r\n  /**\r\n   * Read the target of pdf bookmark\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param getActionPtr - callback function to retrive the pointer of action\r\n   * @param getDestinationPtr - callback function to retrive the pointer of destination\r\n   * @returns target of pdf bookmark\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfBookmarkTarget(\r\n    docPtr: number,\r\n    getActionPtr: () => number,\r\n    getDestinationPtr: () => number,\r\n  ): PdfLinkTarget | undefined {\r\n    const actionPtr = getActionPtr();\r\n    if (actionPtr) {\r\n      const action = this.readPdfAction(docPtr, actionPtr);\r\n\r\n      return {\r\n        type: 'action',\r\n        action,\r\n      };\r\n    } else {\r\n      const destinationPtr = getDestinationPtr();\r\n      if (destinationPtr) {\r\n        const destination = this.readPdfDestination(docPtr, destinationPtr);\r\n\r\n        return {\r\n          type: 'destination',\r\n          destination,\r\n        };\r\n      }\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Read field of pdf widget annotation\r\n   * @param formHandle - form handle\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @returns field of pdf widget annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfWidgetAnnoField(formHandle: number, annotationPtr: number): PdfWidgetAnnoField {\r\n    const flag = this.pdfiumModule.FPDFAnnot_GetFormFieldFlags(\r\n      formHandle,\r\n      annotationPtr,\r\n    ) as PDF_FORM_FIELD_FLAG;\r\n\r\n    const type = this.pdfiumModule.FPDFAnnot_GetFormFieldType(\r\n      formHandle,\r\n      annotationPtr,\r\n    ) as PDF_FORM_FIELD_TYPE;\r\n\r\n    const name = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer: number, bufferLength) => {\r\n        return this.pdfiumModule.FPDFAnnot_GetFormFieldName(\r\n          formHandle,\r\n          annotationPtr,\r\n          buffer,\r\n          bufferLength,\r\n        );\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n\r\n    const alternateName = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer: number, bufferLength) => {\r\n        return this.pdfiumModule.FPDFAnnot_GetFormFieldAlternateName(\r\n          formHandle,\r\n          annotationPtr,\r\n          buffer,\r\n          bufferLength,\r\n        );\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n\r\n    const value = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer: number, bufferLength) => {\r\n        return this.pdfiumModule.FPDFAnnot_GetFormFieldValue(\r\n          formHandle,\r\n          annotationPtr,\r\n          buffer,\r\n          bufferLength,\r\n        );\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n\r\n    const options: PdfWidgetAnnoOption[] = [];\r\n    if (type === PDF_FORM_FIELD_TYPE.COMBOBOX || type === PDF_FORM_FIELD_TYPE.LISTBOX) {\r\n      const count = this.pdfiumModule.FPDFAnnot_GetOptionCount(formHandle, annotationPtr);\r\n      for (let i = 0; i < count; i++) {\r\n        const label = readString(\r\n          this.pdfiumModule.pdfium,\r\n          (buffer: number, bufferLength) => {\r\n            return this.pdfiumModule.FPDFAnnot_GetOptionLabel(\r\n              formHandle,\r\n              annotationPtr,\r\n              i,\r\n              buffer,\r\n              bufferLength,\r\n            );\r\n          },\r\n          this.pdfiumModule.pdfium.UTF16ToString,\r\n        );\r\n        const isSelected = this.pdfiumModule.FPDFAnnot_IsOptionSelected(\r\n          formHandle,\r\n          annotationPtr,\r\n          i,\r\n        );\r\n        options.push({\r\n          label,\r\n          isSelected,\r\n        });\r\n      }\r\n    }\r\n\r\n    let isChecked = false;\r\n    if (type === PDF_FORM_FIELD_TYPE.CHECKBOX || type === PDF_FORM_FIELD_TYPE.RADIOBUTTON) {\r\n      isChecked = this.pdfiumModule.FPDFAnnot_IsChecked(formHandle, annotationPtr);\r\n    }\r\n\r\n    return {\r\n      flag,\r\n      type,\r\n      name,\r\n      alternateName,\r\n      value,\r\n      isChecked,\r\n      options,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.renderAnnotation}\r\n   *\r\n   * @public\r\n   */\r\n  renderPageAnnotation(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    annotation: PdfAnnotationObject,\r\n    options?: PdfRenderPageAnnotationOptions,\r\n  ): PdfTask<T> {\r\n    const {\r\n      scaleFactor = 1,\r\n      rotation = Rotation.Degree0,\r\n      dpr = 1,\r\n      mode = AppearanceMode.Normal,\r\n      imageType = 'image/webp',\r\n      imageQuality,\r\n    } = options ?? {};\r\n\r\n    this.logger.debug(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      'renderPageAnnotation',\r\n      doc,\r\n      page,\r\n      annotation,\r\n      options,\r\n    );\r\n    this.logger.perf(\r\n      LOG_SOURCE,\r\n      LOG_CATEGORY,\r\n      `RenderPageAnnotation`,\r\n      'Begin',\r\n      `${doc.id}-${page.index}-${annotation.id}`,\r\n    );\r\n\r\n    const task = new Task<T, PdfErrorReason>();\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `RenderPageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}-${annotation.id}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    // 1) native handles\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);\r\n    if (!annotPtr) {\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `RenderPageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}-${annotation.id}`,\r\n      );\r\n      pageCtx.release();\r\n      return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'annotation not found' });\r\n    }\r\n\r\n    // 2) device size (rotation-aware) → integer pixels\r\n    const finalScale = Math.max(0.01, scaleFactor * dpr);\r\n\r\n    const rect = toIntRect(annotation.rect);\r\n    const devRect = toIntRect(transformRect(page.size, rect, rotation, finalScale));\r\n\r\n    const wDev = Math.max(1, devRect.size.width);\r\n    const hDev = Math.max(1, devRect.size.height);\r\n    const stride = wDev * 4;\r\n    const bytes = stride * hDev;\r\n\r\n    // 3) bitmap backing store in WASM\r\n    const heapPtr = this.memoryManager.malloc(bytes);\r\n    const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(\r\n      wDev,\r\n      hDev,\r\n      BitmapFormat.Bitmap_BGRA,\r\n      heapPtr,\r\n      stride,\r\n    );\r\n    this.pdfiumModule.FPDFBitmap_FillRect(bitmapPtr, 0, 0, wDev, hDev, 0x00000000);\r\n\r\n    // 4) user matrix (no Y-flip; includes -origin translate)\r\n    const M = buildUserToDeviceMatrix(\r\n      rect, // {origin:{L,B}, size:{W,H}}\r\n      rotation,\r\n      wDev,\r\n      hDev,\r\n    );\r\n    const mPtr = this.memoryManager.malloc(6 * 4);\r\n    const mView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, mPtr, 6);\r\n    mView.set([M.a, M.b, M.c, M.d, M.e, M.f]);\r\n\r\n    // 5) render (DisplayMatrix is applied inside EPDF_RenderAnnotBitmap)\r\n    const FLAGS = RenderFlag.REVERSE_BYTE_ORDER;\r\n    let ok = false;\r\n    try {\r\n      ok = !!this.pdfiumModule.EPDF_RenderAnnotBitmap(\r\n        bitmapPtr,\r\n        pageCtx.pagePtr,\r\n        annotPtr,\r\n        mode,\r\n        mPtr,\r\n        FLAGS,\r\n      );\r\n    } finally {\r\n      this.memoryManager.free(mPtr);\r\n      this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr); // frees wrapper, not our heapPtr\r\n      this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);\r\n      pageCtx.release();\r\n    }\r\n\r\n    if (!ok) {\r\n      this.memoryManager.free(heapPtr);\r\n      this.logger.perf(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `RenderPageAnnotation`,\r\n        'End',\r\n        `${doc.id}-${page.index}-${annotation.id}`,\r\n      );\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: 'EPDF_RenderAnnotBitmap failed',\r\n      });\r\n    }\r\n\r\n    // 6) encode\r\n    const dispose = () => this.memoryManager.free(heapPtr);\r\n\r\n    this.imageDataConverter(\r\n      () => {\r\n        const rgba = new Uint8ClampedArray(\r\n          this.pdfiumModule.pdfium.HEAPU8.subarray(heapPtr, heapPtr + bytes),\r\n        );\r\n        return {\r\n          width: wDev,\r\n          height: hDev,\r\n          data: rgba,\r\n        };\r\n      },\r\n      imageType,\r\n      imageQuality,\r\n    )\r\n      .then((out) => task.resolve(out))\r\n      .catch((e) => {\r\n        // Check if it's an OffscreenCanvas error and we haven't copied data yet\r\n        if (e instanceof OffscreenCanvasError) {\r\n          // Fallback to WASM encoding without wasting the copy\r\n          try {\r\n            const blob = this.encodeViaWasm(\r\n              { ptr: heapPtr, width: wDev, height: hDev, stride },\r\n              { type: imageType, quality: imageQuality },\r\n            );\r\n            task.resolve(blob as T);\r\n          } catch (wasmError) {\r\n            task.reject({ code: PdfErrorCode.Unknown, message: String(wasmError) });\r\n          }\r\n        } else {\r\n          task.reject({ code: PdfErrorCode.Unknown, message: String(e) });\r\n        }\r\n      })\r\n      .finally(dispose);\r\n\r\n    return task;\r\n  }\r\n\r\n  private encodeViaWasm(\r\n    buf: { ptr: number; width: number; height: number; stride: number },\r\n    opts: ConvertToBlobOptions,\r\n  ): Blob {\r\n    const pdf = this.pdfiumModule.pdfium;\r\n\r\n    // Helper to copy out and free a payload allocated in WASM\r\n    const blobFrom = (outPtr: WasmPointer, size: number, mime: string) => {\r\n      const view = pdf.HEAPU8.subarray(outPtr, outPtr + size);\r\n      const copy = new Uint8Array(view); // detach from WASM before free\r\n      this.memoryManager.free(outPtr);\r\n      return new Blob([copy], { type: mime });\r\n    };\r\n\r\n    // Map OffscreenCanvas \"quality 0..1\" to encoders:\r\n    //  • WebP: 0..100 (float), default ~0.82 → 82\r\n    //  • JPEG: 1..100 (int),   default ~0.92 → 92\r\n    //const q = opts.quality;\r\n    //const webpQ = q == null ? 82 : Math.round(q * 100);\r\n    //const jpegQ = q == null ? 92 : Math.max(1, Math.round(q * 100));\r\n    // PNG ignores quality (same as OffscreenCanvas). Use libpng default (6).\r\n    const pngLevel = 6;\r\n\r\n    const outPtrPtr = this.memoryManager.malloc(4);\r\n    try {\r\n      switch (opts.type) {\r\n        /*\r\n        case 'image/webp': {\r\n          const size = this.pdfiumModule.EPDF_WebP_EncodeRGBA(\r\n            buf.ptr,\r\n            buf.width,\r\n            buf.height,\r\n            buf.stride,\r\n            webpQ,\r\n            outPtrPtr,\r\n          );\r\n          const outPtr = pdf.getValue(outPtrPtr, 'i32');\r\n          return blobFrom(outPtr, size, 'image/webp');\r\n        }\r\n        case 'image/jpeg': {\r\n          const size = this.pdfiumModule.EPDF_JPEG_EncodeRGBA(\r\n            buf.ptr,\r\n            buf.width,\r\n            buf.height,\r\n            buf.stride,\r\n            jpegQ,\r\n            outPtrPtr,\r\n          );\r\n          const outPtr = pdf.getValue(outPtrPtr, 'i32');\r\n          return blobFrom(outPtr, size, 'image/jpeg');\r\n        }\r\n        */\r\n        case 'image/png':\r\n        default: {\r\n          const size = this.pdfiumModule.EPDF_PNG_EncodeRGBA(\r\n            buf.ptr,\r\n            buf.width,\r\n            buf.height,\r\n            buf.stride,\r\n            pngLevel,\r\n            outPtrPtr,\r\n          );\r\n          const outPtr = pdf.getValue(outPtrPtr, 'i32');\r\n          return blobFrom(WasmPointer(outPtr), size, 'image/png');\r\n        }\r\n      }\r\n    } finally {\r\n      this.memoryManager.free(outPtrPtr);\r\n    }\r\n  }\r\n\r\n  private renderRectEncoded(\r\n    doc: PdfDocumentObject,\r\n    page: PdfPageObject,\r\n    rect: Rect,\r\n    options?: PdfRenderPageOptions,\r\n  ): PdfTask<T> {\r\n    const task = new Task<T, PdfErrorReason>();\r\n\r\n    const imageType: ImageConversionTypes = options?.imageType ?? 'image/webp';\r\n    const quality = options?.imageQuality;\r\n    const rotation: Rotation = options?.rotation ?? Rotation.Degree0;\r\n\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'document does not open',\r\n      });\r\n    }\r\n\r\n    // ---- 1) decide device size (scale × dpr, swap for 90/270)\r\n    const scale = Math.max(0.01, options?.scaleFactor ?? 1);\r\n    const dpr = Math.max(1, options?.dpr ?? 1);\r\n    const finalScale = scale * dpr;\r\n\r\n    const baseW = rect.size.width;\r\n    const baseH = rect.size.height;\r\n    const swap = (rotation & 1) === 1; // 90 or 270\r\n\r\n    const wDev = Math.max(1, Math.round((swap ? baseH : baseW) * finalScale));\r\n    const hDev = Math.max(1, Math.round((swap ? baseW : baseH) * finalScale));\r\n    const stride = wDev * 4;\r\n    const bytes = stride * hDev;\r\n\r\n    const pageCtx = ctx.acquirePage(page.index);\r\n    const shouldRenderForms = options?.withForms ?? false;\r\n    const formHandle = shouldRenderForms ? pageCtx.getFormHandle() : undefined;\r\n\r\n    // ---- 2) allocate a BGRA bitmap in WASM\r\n    const heapPtr = this.memoryManager.malloc(bytes);\r\n    const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(\r\n      wDev,\r\n      hDev,\r\n      BitmapFormat.Bitmap_BGRA,\r\n      heapPtr,\r\n      stride,\r\n    );\r\n    // white background like page renderers typically do\r\n    this.pdfiumModule.FPDFBitmap_FillRect(bitmapPtr, 0, 0, wDev, hDev, 0xffffffff);\r\n\r\n    const M = buildUserToDeviceMatrix(rect, rotation, wDev, hDev);\r\n\r\n    const mPtr = this.memoryManager.malloc(6 * 4); // FS_MATRIX\r\n    const mView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, mPtr, 6);\r\n    mView.set([M.a, M.b, M.c, M.d, M.e, M.f]);\r\n\r\n    // Clip to the whole bitmap (device space)\r\n    const clipPtr = this.memoryManager.malloc(4 * 4); // FS_RECTF {left,bottom,right,top}\r\n    const clipView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, clipPtr, 4);\r\n    clipView.set([0, 0, wDev, hDev]);\r\n\r\n    // Rendering flags: swap byte order to present RGBA to JS; include LCD_TEXT and ANNOT if asked\r\n    let flags = RenderFlag.REVERSE_BYTE_ORDER;\r\n    if (options?.withAnnotations ?? false) flags |= RenderFlag.ANNOT;\r\n\r\n    try {\r\n      this.pdfiumModule.FPDF_RenderPageBitmapWithMatrix(\r\n        bitmapPtr,\r\n        pageCtx.pagePtr,\r\n        mPtr,\r\n        clipPtr,\r\n        flags,\r\n      );\r\n\r\n      if (formHandle !== undefined) {\r\n        const formParams = computeFormDrawParams(M, rect, page.size, rotation);\r\n        const { startX, startY, formsWidth, formsHeight, scaleX, scaleY } = formParams;\r\n\r\n        // Draw form elements using the same effective transform as the page bitmap.\r\n        this.pdfiumModule.FPDF_FFLDraw(\r\n          formHandle,\r\n          bitmapPtr,\r\n          pageCtx.pagePtr,\r\n          startX,\r\n          startY,\r\n          formsWidth,\r\n          formsHeight,\r\n          rotation,\r\n          flags,\r\n        );\r\n      }\r\n    } finally {\r\n      pageCtx.release();\r\n      this.memoryManager.free(mPtr);\r\n      this.memoryManager.free(clipPtr);\r\n    }\r\n\r\n    const dispose = () => {\r\n      this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);\r\n      this.memoryManager.free(heapPtr);\r\n    };\r\n\r\n    this.imageDataConverter(\r\n      () => {\r\n        const heapBuf = this.pdfiumModule.pdfium.HEAPU8.buffer as unknown as ArrayBuffer;\r\n        const data = new Uint8ClampedArray(heapBuf, heapPtr, bytes);\r\n        return {\r\n          width: wDev,\r\n          height: hDev,\r\n          data,\r\n        };\r\n      },\r\n      imageType,\r\n      quality,\r\n    )\r\n      .then((out) => task.resolve(out))\r\n      .catch((e) => {\r\n        this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'Error', e);\r\n        // Check if it's an OffscreenCanvas error and we haven't copied data yet\r\n        if (e instanceof OffscreenCanvasError) {\r\n          // Fallback to WASM encoding without wasting the copy\r\n          this.logger.info(LOG_SOURCE, LOG_CATEGORY, 'Fallback to WASM encoding');\r\n          try {\r\n            const blob = this.encodeViaWasm(\r\n              { ptr: heapPtr, width: wDev, height: hDev, stride },\r\n              { type: imageType, quality },\r\n            );\r\n            task.resolve(blob as T);\r\n          } catch (wasmError) {\r\n            task.reject({ code: PdfErrorCode.Unknown, message: String(wasmError) });\r\n          }\r\n        } else {\r\n          task.reject({ code: PdfErrorCode.Unknown, message: String(e) });\r\n        }\r\n      })\r\n      .finally(dispose);\r\n\r\n    return task;\r\n  }\r\n\r\n  /**\r\n   * Read the target of pdf link annotation\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param getActionPtr - callback function to retrive the pointer of action\r\n   * @param getDestinationPtr - callback function to retrive the pointer of destination\r\n   * @returns target of link\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfLinkAnnoTarget(\r\n    docPtr: number,\r\n    getActionPtr: () => number,\r\n    getDestinationPtr: () => number,\r\n  ): PdfLinkTarget | undefined {\r\n    const destinationPtr = getDestinationPtr();\r\n    if (destinationPtr) {\r\n      const destination = this.readPdfDestination(docPtr, destinationPtr);\r\n\r\n      return {\r\n        type: 'destination',\r\n        destination,\r\n      };\r\n    } else {\r\n      const actionPtr = getActionPtr();\r\n      if (actionPtr) {\r\n        const action = this.readPdfAction(docPtr, actionPtr);\r\n\r\n        return {\r\n          type: 'action',\r\n          action,\r\n        };\r\n      }\r\n    }\r\n  }\r\n\r\n  private createLocalDestPtr(docPtr: number, dest: PdfDestinationObject): number {\r\n    // Load page for local destinations.\r\n    const pagePtr = this.pdfiumModule.FPDF_LoadPage(docPtr, dest.pageIndex);\r\n    if (!pagePtr) return 0;\r\n\r\n    try {\r\n      if (dest.zoom.mode === PdfZoomMode.XYZ) {\r\n        const { x, y, zoom } = dest.zoom.params;\r\n        // We treat provided x/y/zoom as “specified”.\r\n        return this.pdfiumModule.EPDFDest_CreateXYZ(\r\n          pagePtr,\r\n          /*has_left*/ true,\r\n          x,\r\n          /*has_top*/ true,\r\n          y,\r\n          /*has_zoom*/ true,\r\n          zoom,\r\n        );\r\n      }\r\n\r\n      // Map non-XYZ “view modes” to PDFDEST_VIEW_* and params.\r\n      let viewEnum: PdfZoomMode;\r\n      let params: number[] = [];\r\n\r\n      switch (dest.zoom.mode) {\r\n        case PdfZoomMode.FitPage:\r\n          viewEnum = PdfZoomMode.FitPage; // no params\r\n          break;\r\n        case PdfZoomMode.FitHorizontal:\r\n          // FitH needs top; use view[0] if provided, else 0\r\n          viewEnum = PdfZoomMode.FitHorizontal;\r\n          params = [dest.view?.[0] ?? 0];\r\n          break;\r\n        case PdfZoomMode.FitVertical:\r\n          // FitV needs left; use view[0] if provided, else 0\r\n          viewEnum = PdfZoomMode.FitVertical;\r\n          params = [dest.view?.[0] ?? 0];\r\n          break;\r\n        case PdfZoomMode.FitRectangle:\r\n          // FitR needs left, bottom, right, top (pad with zeros).\r\n          {\r\n            const v = dest.view ?? [];\r\n            params = [v[0] ?? 0, v[1] ?? 0, v[2] ?? 0, v[3] ?? 0];\r\n            viewEnum = PdfZoomMode.FitRectangle;\r\n          }\r\n          break;\r\n        case PdfZoomMode.Unknown:\r\n        default:\r\n          // Unknown cannot be encoded as a valid explicit destination.\r\n          return 0;\r\n      }\r\n\r\n      return this.withFloatArray(params, (ptr, count) =>\r\n        this.pdfiumModule.EPDFDest_CreateView(pagePtr, viewEnum, ptr, count),\r\n      );\r\n    } finally {\r\n      this.pdfiumModule.FPDF_ClosePage(pagePtr);\r\n    }\r\n  }\r\n\r\n  private applyBookmarkTarget(docPtr: number, bmPtr: number, target: PdfLinkTarget): boolean {\r\n    if (target.type === 'destination') {\r\n      const destPtr = this.createLocalDestPtr(docPtr, target.destination);\r\n      if (!destPtr) return false;\r\n      const ok = this.pdfiumModule.EPDFBookmark_SetDest(docPtr, bmPtr, destPtr);\r\n      return !!ok;\r\n    }\r\n\r\n    // target.type === 'action'\r\n    const action = target.action;\r\n    switch (action.type) {\r\n      case PdfActionType.Goto: {\r\n        const destPtr = this.createLocalDestPtr(docPtr, action.destination);\r\n        if (!destPtr) return false;\r\n        const actPtr = this.pdfiumModule.EPDFAction_CreateGoTo(docPtr, destPtr);\r\n        if (!actPtr) return false;\r\n        return !!this.pdfiumModule.EPDFBookmark_SetAction(docPtr, bmPtr, actPtr);\r\n      }\r\n\r\n      case PdfActionType.URI: {\r\n        const actPtr = this.pdfiumModule.EPDFAction_CreateURI(docPtr, action.uri);\r\n        if (!actPtr) return false;\r\n        return !!this.pdfiumModule.EPDFBookmark_SetAction(docPtr, bmPtr, actPtr);\r\n      }\r\n\r\n      case PdfActionType.LaunchAppOrOpenFile: {\r\n        const actPtr = this.withWString(action.path, (wptr) =>\r\n          this.pdfiumModule.EPDFAction_CreateLaunch(docPtr, wptr),\r\n        );\r\n        if (!actPtr) return false;\r\n        return !!this.pdfiumModule.EPDFBookmark_SetAction(docPtr, bmPtr, actPtr);\r\n      }\r\n\r\n      case PdfActionType.RemoteGoto:\r\n        // We need a file path to build a GoToR action. Your Action shape\r\n        // doesn’t carry a path, so we’ll reject for now.\r\n        return false;\r\n\r\n      case PdfActionType.Unsupported:\r\n      default:\r\n        return false;\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Read pdf action from pdf document\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param actionPtr - pointer to pdf action object\r\n   * @returns pdf action object\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfAction(docPtr: number, actionPtr: number): PdfActionObject {\r\n    const actionType = this.pdfiumModule.FPDFAction_GetType(actionPtr) as PdfActionType;\r\n    let action: PdfActionObject;\r\n    switch (actionType) {\r\n      case PdfActionType.Unsupported:\r\n        action = {\r\n          type: PdfActionType.Unsupported,\r\n        };\r\n        break;\r\n      case PdfActionType.Goto:\r\n        {\r\n          const destinationPtr = this.pdfiumModule.FPDFAction_GetDest(docPtr, actionPtr);\r\n          if (destinationPtr) {\r\n            const destination = this.readPdfDestination(docPtr, destinationPtr);\r\n\r\n            action = {\r\n              type: PdfActionType.Goto,\r\n              destination,\r\n            };\r\n          } else {\r\n            action = {\r\n              type: PdfActionType.Unsupported,\r\n            };\r\n          }\r\n        }\r\n        break;\r\n      case PdfActionType.RemoteGoto:\r\n        {\r\n          // In case of remote goto action,\r\n          // the application should first use FPDFAction_GetFilePath\r\n          // to get file path, then load that particular document,\r\n          // and use its document handle to call this\r\n          action = {\r\n            type: PdfActionType.Unsupported,\r\n          };\r\n        }\r\n        break;\r\n      case PdfActionType.URI:\r\n        {\r\n          const uri = readString(\r\n            this.pdfiumModule.pdfium,\r\n            (buffer, bufferLength) => {\r\n              return this.pdfiumModule.FPDFAction_GetURIPath(\r\n                docPtr,\r\n                actionPtr,\r\n                buffer,\r\n                bufferLength,\r\n              );\r\n            },\r\n            this.pdfiumModule.pdfium.UTF8ToString,\r\n          );\r\n\r\n          action = {\r\n            type: PdfActionType.URI,\r\n            uri,\r\n          };\r\n        }\r\n        break;\r\n      case PdfActionType.LaunchAppOrOpenFile:\r\n        {\r\n          const path = readString(\r\n            this.pdfiumModule.pdfium,\r\n            (buffer, bufferLength) => {\r\n              return this.pdfiumModule.FPDFAction_GetFilePath(actionPtr, buffer, bufferLength);\r\n            },\r\n            this.pdfiumModule.pdfium.UTF8ToString,\r\n          );\r\n          action = {\r\n            type: PdfActionType.LaunchAppOrOpenFile,\r\n            path,\r\n          };\r\n        }\r\n        break;\r\n    }\r\n\r\n    return action;\r\n  }\r\n\r\n  /**\r\n   * Read pdf destination object\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param destinationPtr - pointer to pdf destination\r\n   * @returns pdf destination object\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfDestination(docPtr: number, destinationPtr: number): PdfDestinationObject {\r\n    const pageIndex = this.pdfiumModule.FPDFDest_GetDestPageIndex(docPtr, destinationPtr);\r\n    // Every params is a float value\r\n    const maxParmamsCount = 4;\r\n    const paramsCountPtr = this.memoryManager.malloc(maxParmamsCount);\r\n    const paramsPtr = this.memoryManager.malloc(maxParmamsCount * 4);\r\n    const zoomMode = this.pdfiumModule.FPDFDest_GetView(\r\n      destinationPtr,\r\n      paramsCountPtr,\r\n      paramsPtr,\r\n    ) as PdfZoomMode;\r\n    const paramsCount = this.pdfiumModule.pdfium.getValue(paramsCountPtr, 'i32');\r\n    const view: number[] = [];\r\n    for (let i = 0; i < paramsCount; i++) {\r\n      const paramPtr = paramsPtr + i * 4;\r\n      view.push(this.pdfiumModule.pdfium.getValue(paramPtr, 'float'));\r\n    }\r\n    this.memoryManager.free(paramsCountPtr);\r\n    this.memoryManager.free(paramsPtr);\r\n\r\n    if (zoomMode === PdfZoomMode.XYZ) {\r\n      const hasXPtr = this.memoryManager.malloc(1);\r\n      const hasYPtr = this.memoryManager.malloc(1);\r\n      const hasZPtr = this.memoryManager.malloc(1);\r\n      const xPtr = this.memoryManager.malloc(4);\r\n      const yPtr = this.memoryManager.malloc(4);\r\n      const zPtr = this.memoryManager.malloc(4);\r\n\r\n      const isSucceed = this.pdfiumModule.FPDFDest_GetLocationInPage(\r\n        destinationPtr,\r\n        hasXPtr,\r\n        hasYPtr,\r\n        hasZPtr,\r\n        xPtr,\r\n        yPtr,\r\n        zPtr,\r\n      );\r\n      if (isSucceed) {\r\n        const hasX = this.pdfiumModule.pdfium.getValue(hasXPtr, 'i8');\r\n        const hasY = this.pdfiumModule.pdfium.getValue(hasYPtr, 'i8');\r\n        const hasZ = this.pdfiumModule.pdfium.getValue(hasZPtr, 'i8');\r\n\r\n        const x = hasX ? this.pdfiumModule.pdfium.getValue(xPtr, 'float') : 0;\r\n        const y = hasY ? this.pdfiumModule.pdfium.getValue(yPtr, 'float') : 0;\r\n        const zoom = hasZ ? this.pdfiumModule.pdfium.getValue(zPtr, 'float') : 0;\r\n\r\n        this.memoryManager.free(hasXPtr);\r\n        this.memoryManager.free(hasYPtr);\r\n        this.memoryManager.free(hasZPtr);\r\n        this.memoryManager.free(xPtr);\r\n        this.memoryManager.free(yPtr);\r\n        this.memoryManager.free(zPtr);\r\n\r\n        return {\r\n          pageIndex,\r\n          zoom: {\r\n            mode: zoomMode,\r\n            params: {\r\n              x,\r\n              y,\r\n              zoom,\r\n            },\r\n          },\r\n          view,\r\n        };\r\n      }\r\n\r\n      this.memoryManager.free(hasXPtr);\r\n      this.memoryManager.free(hasYPtr);\r\n      this.memoryManager.free(hasZPtr);\r\n      this.memoryManager.free(xPtr);\r\n      this.memoryManager.free(yPtr);\r\n      this.memoryManager.free(zPtr);\r\n\r\n      return {\r\n        pageIndex,\r\n        zoom: {\r\n          mode: zoomMode,\r\n          params: {\r\n            x: 0,\r\n            y: 0,\r\n            zoom: 0,\r\n          },\r\n        },\r\n        view,\r\n      };\r\n    }\r\n\r\n    return {\r\n      pageIndex,\r\n      zoom: {\r\n        mode: zoomMode,\r\n      },\r\n      view,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read attachmet from pdf document\r\n   * @param docPtr - pointer to pdf document object\r\n   * @param index - index of attachment\r\n   * @returns attachment content\r\n   *\r\n   * @private\r\n   */\r\n  private readPdfAttachment(docPtr: number, index: number): PdfAttachmentObject {\r\n    const attachmentPtr = this.pdfiumModule.FPDFDoc_GetAttachment(docPtr, index);\r\n    const name = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) => {\r\n        return this.pdfiumModule.FPDFAttachment_GetName(attachmentPtr, buffer, bufferLength);\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n    const description = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) => {\r\n        return this.pdfiumModule.EPDFAttachment_GetDescription(attachmentPtr, buffer, bufferLength);\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n    const mimeType = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) => {\r\n        return this.pdfiumModule.FPDFAttachment_GetSubtype(attachmentPtr, buffer, bufferLength);\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n    const creationDate = this.getAttachmentDate(attachmentPtr, 'CreationDate');\r\n    const checksum = readString(\r\n      this.pdfiumModule.pdfium,\r\n      (buffer, bufferLength) => {\r\n        return this.pdfiumModule.FPDFAttachment_GetStringValue(\r\n          attachmentPtr,\r\n          'Checksum',\r\n          buffer,\r\n          bufferLength,\r\n        );\r\n      },\r\n      this.pdfiumModule.pdfium.UTF16ToString,\r\n    );\r\n    const size = this.getAttachmentNumber(attachmentPtr, 'Size');\r\n\r\n    return {\r\n      index,\r\n      name,\r\n      description,\r\n      mimeType,\r\n      size,\r\n      creationDate,\r\n      checksum,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Convert coordinate of point from device coordinate to page coordinate\r\n   * @param page  - pdf page infor\r\n   * @param position - position of point\r\n   * @returns converted position\r\n   *\r\n   * @private\r\n   */\r\n  private convertDevicePointToPagePoint(page: PdfPageObject, position: Position): Position {\r\n    const DW = page.size.width;\r\n    const DH = page.size.height;\r\n    const r = page.rotation & 3;\r\n\r\n    if (r === 0) {\r\n      // 0°\r\n      return { x: position.x, y: DH - position.y };\r\n    }\r\n    if (r === 1) {\r\n      // 90° CW\r\n      // x_d = sx*y, y_d = sy*x  =>  x = y_d/sy, y = x_d/sx\r\n      return { x: position.y, y: position.x };\r\n    }\r\n    if (r === 2) {\r\n      // 180°\r\n      return { x: DW - position.x, y: position.y };\r\n    }\r\n    {\r\n      // 270° CW\r\n      // x_d = DW - sx*y, y_d = DH - sy*x\r\n      return { x: DH - position.y, y: DW - position.x };\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Convert coordinate of point from page coordinate to device coordinate\r\n   * @param page  - pdf page infor\r\n   * @param position - position of point\r\n   * @returns converted position\r\n   *\r\n   * @private\r\n   */\r\n  private convertPagePointToDevicePoint(page: PdfPageObject, position: Position): Position {\r\n    const DW = page.size.width;\r\n    const DH = page.size.height;\r\n    const r = page.rotation & 3;\r\n\r\n    if (r === 0) {\r\n      // 0°\r\n      return { x: position.x, y: DH - position.y };\r\n    }\r\n    if (r === 1) {\r\n      // 90° CW\r\n      return { x: position.y, y: position.x };\r\n    }\r\n    if (r === 2) {\r\n      // 180°\r\n      return { x: DW - position.x, y: position.y };\r\n    }\r\n    {\r\n      // 270° CW\r\n      return { x: DW - position.y, y: DH - position.x };\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Convert coordinate of rectangle from page coordinate to device coordinate\r\n   * @param page  - pdf page infor\r\n   * @param pagePtr - pointer to pdf page object\r\n   * @param pageRect - rectangle that needs to be converted\r\n   * @returns converted rectangle\r\n   *\r\n   * @private\r\n   */\r\n  private convertPageRectToDeviceRect(\r\n    page: PdfPageObject,\r\n    pageRect: {\r\n      left: number;\r\n      top: number;\r\n      right: number;\r\n      bottom: number;\r\n    },\r\n  ): Rect {\r\n    const { x, y } = this.convertPagePointToDevicePoint(page, {\r\n      x: pageRect.left,\r\n      y: pageRect.top,\r\n    });\r\n    const rect = {\r\n      origin: {\r\n        x,\r\n        y,\r\n      },\r\n      size: {\r\n        width: Math.abs(pageRect.right - pageRect.left),\r\n        height: Math.abs(pageRect.top - pageRect.bottom),\r\n      },\r\n    };\r\n\r\n    return rect;\r\n  }\r\n\r\n  /**\r\n   * Read the appearance stream of annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param mode - appearance mode\r\n   * @returns appearance stream\r\n   *\r\n   * @private\r\n   */\r\n  private readPageAnnoAppearanceStreams(annotationPtr: number) {\r\n    return {\r\n      normal: this.readPageAnnoAppearanceStream(annotationPtr, AppearanceMode.Normal),\r\n      rollover: this.readPageAnnoAppearanceStream(annotationPtr, AppearanceMode.Rollover),\r\n      down: this.readPageAnnoAppearanceStream(annotationPtr, AppearanceMode.Down),\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Read the appearance stream of annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param mode - appearance mode\r\n   * @returns appearance stream\r\n   *\r\n   * @private\r\n   */\r\n  private readPageAnnoAppearanceStream(annotationPtr: number, mode = AppearanceMode.Normal) {\r\n    const utf16Length = this.pdfiumModule.FPDFAnnot_GetAP(annotationPtr, mode, 0, 0);\r\n    const bytesCount = (utf16Length + 1) * 2; // include NIL\r\n    const bufferPtr = this.memoryManager.malloc(bytesCount);\r\n    this.pdfiumModule.FPDFAnnot_GetAP(annotationPtr, mode, bufferPtr, bytesCount);\r\n    const ap = this.pdfiumModule.pdfium.UTF16ToString(bufferPtr);\r\n    this.memoryManager.free(bufferPtr);\r\n\r\n    return ap;\r\n  }\r\n\r\n  /**\r\n   * Set the appearance stream of annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @param mode - appearance mode\r\n   * @param apContent - appearance stream content (null to remove)\r\n   * @returns whether the appearance stream was set successfully\r\n   *\r\n   * @private\r\n   */\r\n  private setPageAnnoAppearanceStream(\r\n    annotationPtr: number,\r\n    mode: AppearanceMode = AppearanceMode.Normal,\r\n    apContent: string,\r\n  ): boolean {\r\n    // UTF-16LE buffer (+2 bytes for NUL)\r\n    const bytes = 2 * (apContent.length + 1);\r\n    const ptr = this.memoryManager.malloc(bytes);\r\n    try {\r\n      this.pdfiumModule.pdfium.stringToUTF16(apContent, ptr, bytes);\r\n      const ok = this.pdfiumModule.FPDFAnnot_SetAP(annotationPtr, mode, ptr);\r\n      return !!ok;\r\n    } finally {\r\n      this.memoryManager.free(ptr);\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Set the rect of specified annotation\r\n   * @param page - page info that the annotation is belonged to\r\n   * @param annotationPtr - pointer to annotation object\r\n   * @param rect - target rectangle\r\n   * @returns whether the rect is setted\r\n   *\r\n   * @private\r\n   */\r\n  private setPageAnnoRect(page: PdfPageObject, annotPtr: number, rect: Rect): boolean {\r\n    // Snap device edges the same way FPDF_DeviceToPage(int,int,...) did (truncate → floor for ≥0)\r\n    const x0d = Math.floor(rect.origin.x);\r\n    const y0d = Math.floor(rect.origin.y);\r\n    const x1d = Math.floor(rect.origin.x + rect.size.width);\r\n    const y1d = Math.floor(rect.origin.y + rect.size.height);\r\n\r\n    // Map all 4 integer corners to page space (handles any /Rotate)\r\n    const TL = this.convertDevicePointToPagePoint(page, { x: x0d, y: y0d });\r\n    const TR = this.convertDevicePointToPagePoint(page, { x: x1d, y: y0d });\r\n    const BR = this.convertDevicePointToPagePoint(page, { x: x1d, y: y1d });\r\n    const BL = this.convertDevicePointToPagePoint(page, { x: x0d, y: y1d });\r\n\r\n    // Page-space AABB\r\n    let left = Math.min(TL.x, TR.x, BR.x, BL.x);\r\n    let right = Math.max(TL.x, TR.x, BR.x, BL.x);\r\n    let bottom = Math.min(TL.y, TR.y, BR.y, BL.y);\r\n    let top = Math.max(TL.y, TR.y, BR.y, BL.y);\r\n    if (left > right) [left, right] = [right, left];\r\n    if (bottom > top) [bottom, top] = [top, bottom];\r\n\r\n    // Write FS_RECTF in memory order: L, T, R, B\r\n    const ptr = this.memoryManager.malloc(16);\r\n    const pdf = this.pdfiumModule.pdfium;\r\n    pdf.setValue(ptr + 0, left, 'float'); // L\r\n    pdf.setValue(ptr + 4, top, 'float'); // T\r\n    pdf.setValue(ptr + 8, right, 'float'); // R\r\n    pdf.setValue(ptr + 12, bottom, 'float'); // B\r\n\r\n    const ok = this.pdfiumModule.FPDFAnnot_SetRect(annotPtr, ptr);\r\n    this.memoryManager.free(ptr);\r\n    return !!ok;\r\n  }\r\n\r\n  /**\r\n   * Read the rectangle of annotation\r\n   * @param annotationPtr - pointer to pdf annotation\r\n   * @returns rectangle of annotation\r\n   *\r\n   * @private\r\n   */\r\n  private readPageAnnoRect(annotationPtr: number) {\r\n    const pageRectPtr = this.memoryManager.malloc(4 * 4);\r\n    const pageRect = {\r\n      left: 0,\r\n      top: 0,\r\n      right: 0,\r\n      bottom: 0,\r\n    };\r\n    if (this.pdfiumModule.FPDFAnnot_GetRect(annotationPtr, pageRectPtr)) {\r\n      pageRect.left = this.pdfiumModule.pdfium.getValue(pageRectPtr, 'float');\r\n      pageRect.top = this.pdfiumModule.pdfium.getValue(pageRectPtr + 4, 'float');\r\n      pageRect.right = this.pdfiumModule.pdfium.getValue(pageRectPtr + 8, 'float');\r\n      pageRect.bottom = this.pdfiumModule.pdfium.getValue(pageRectPtr + 12, 'float');\r\n    }\r\n    this.memoryManager.free(pageRectPtr);\r\n\r\n    return pageRect;\r\n  }\r\n\r\n  /**\r\n   * Get highlight rects for a specific character range (for search highlighting)\r\n   * @param page - pdf page info\r\n   * @param pagePtr - pointer to pdf page\r\n   * @param textPagePtr - pointer to pdf text page\r\n   * @param startIndex - starting character index\r\n   * @param charCount - number of characters in the range\r\n   * @returns array of rectangles for highlighting the specified character range\r\n   *\r\n   * @private\r\n   */\r\n  private getHighlightRects(\r\n    page: PdfPageObject,\r\n    textPagePtr: number,\r\n    startIndex: number,\r\n    charCount: number,\r\n  ): Rect[] {\r\n    const rectsCount = this.pdfiumModule.FPDFText_CountRects(textPagePtr, startIndex, charCount);\r\n    const highlightRects: Rect[] = [];\r\n\r\n    // scratch doubles for the page-space rect\r\n    const l = this.memoryManager.malloc(8);\r\n    const t = this.memoryManager.malloc(8);\r\n    const r = this.memoryManager.malloc(8);\r\n    const b = this.memoryManager.malloc(8);\r\n\r\n    for (let i = 0; i < rectsCount; i++) {\r\n      const ok = this.pdfiumModule.FPDFText_GetRect(textPagePtr, i, l, t, r, b);\r\n      if (!ok) continue;\r\n\r\n      const left = this.pdfiumModule.pdfium.getValue(l, 'double');\r\n      const top = this.pdfiumModule.pdfium.getValue(t, 'double');\r\n      const right = this.pdfiumModule.pdfium.getValue(r, 'double');\r\n      const bottom = this.pdfiumModule.pdfium.getValue(b, 'double');\r\n\r\n      // transform all four corners to device space\r\n      const p1 = this.convertPagePointToDevicePoint(page, { x: left, y: top });\r\n      const p2 = this.convertPagePointToDevicePoint(page, { x: right, y: top });\r\n      const p3 = this.convertPagePointToDevicePoint(page, { x: right, y: bottom });\r\n      const p4 = this.convertPagePointToDevicePoint(page, { x: left, y: bottom });\r\n\r\n      const xs = [p1.x, p2.x, p3.x, p4.x];\r\n      const ys = [p1.y, p2.y, p3.y, p4.y];\r\n\r\n      const x = Math.min(...xs);\r\n      const y = Math.min(...ys);\r\n      const width = Math.max(...xs) - x;\r\n      const height = Math.max(...ys) - y;\r\n\r\n      // ceil so highlights fully cover glyphs at integer pixels\r\n      highlightRects.push({\r\n        origin: { x, y },\r\n        size: { width: Math.ceil(width), height: Math.ceil(height) },\r\n      });\r\n    }\r\n\r\n    this.memoryManager.free(l);\r\n    this.memoryManager.free(t);\r\n    this.memoryManager.free(r);\r\n    this.memoryManager.free(b);\r\n\r\n    return highlightRects;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.searchAllPages}\r\n   *\r\n   * Runs inside the worker.\r\n   * Emits per-page progress: { page, results }\r\n   *\r\n   * @public\r\n   */\r\n  searchAllPages(\r\n    doc: PdfDocumentObject,\r\n    keyword: string,\r\n    options?: PdfSearchAllPagesOptions,\r\n  ): PdfTask<SearchAllPagesResult, PdfPageSearchProgress> {\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'searchAllPages', doc, keyword, options);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SearchAllPages', 'Begin', doc.id);\r\n\r\n    // Resolve early if doc not open\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SearchAllPages', 'End', doc.id);\r\n      return PdfTaskHelper.resolve<SearchAllPagesResult, PdfPageSearchProgress>({\r\n        results: [],\r\n        total: 0,\r\n      });\r\n    }\r\n\r\n    // Build UTF-16 keyword buffer\r\n    const length = 2 * (keyword.length + 1);\r\n    const keywordPtr = this.memoryManager.malloc(length);\r\n    this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);\r\n\r\n    // Fold flags\r\n    const flag =\r\n      options?.flags?.reduce((acc: MatchFlag, f: MatchFlag) => acc | f, MatchFlag.None) ??\r\n      MatchFlag.None;\r\n\r\n    // Create task with progress payload\r\n    const task = PdfTaskHelper.create<SearchAllPagesResult, PdfPageSearchProgress>();\r\n\r\n    let cancelled = false;\r\n    task.wait(\r\n      () => {},\r\n      (err) => {\r\n        if (err.type === 'abort') cancelled = true;\r\n      },\r\n    );\r\n\r\n    const CHUNK_SIZE = 100; // tune as needed\r\n    const allResults: SearchResult[] = [];\r\n\r\n    const processChunk = (startIdx: number): void => {\r\n      if (cancelled) return;\r\n\r\n      const endIdx = Math.min(startIdx + CHUNK_SIZE, doc.pageCount);\r\n\r\n      try {\r\n        for (let pageIndex = startIdx; pageIndex < endIdx && !cancelled; pageIndex++) {\r\n          // Search this page once\r\n          const pageResults = this.searchAllInPage(ctx, doc.pages[pageIndex], keywordPtr, flag);\r\n\r\n          // Accumulate and emit progress\r\n          allResults.push(...pageResults);\r\n          task.progress({ page: pageIndex, results: pageResults });\r\n        }\r\n      } catch (e) {\r\n        if (!cancelled) {\r\n          this.memoryManager.free(keywordPtr);\r\n          this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SearchAllPages', 'End', doc.id);\r\n          task.reject({\r\n            code: PdfErrorCode.Unknown,\r\n            message: `Error searching document: ${e}`,\r\n          });\r\n        }\r\n        return;\r\n      }\r\n\r\n      if (cancelled) return;\r\n\r\n      if (endIdx >= doc.pageCount) {\r\n        this.memoryManager.free(keywordPtr);\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, 'SearchAllPages', 'End', doc.id);\r\n        task.resolve({ results: allResults, total: allResults.length });\r\n        return;\r\n      }\r\n\r\n      // yield to event loop\r\n      setTimeout(() => processChunk(endIdx), 0);\r\n    };\r\n\r\n    // kick off\r\n    setTimeout(() => processChunk(0), 0);\r\n\r\n    // Ensure buffer is freed if caller aborts mid-flight\r\n    task.wait(\r\n      () => {},\r\n      (err) => {\r\n        if (err.type === 'abort') {\r\n          try {\r\n            this.memoryManager.free(keywordPtr);\r\n          } catch {}\r\n        }\r\n      },\r\n    );\r\n\r\n    return task;\r\n  }\r\n\r\n  /**\r\n   * Extract word-aligned context for a search hit.\r\n   *\r\n   * @param fullText      full UTF-16 page text (fetch this once per page!)\r\n   * @param start         index of 1st char that matched\r\n   * @param count         number of chars in the match\r\n   * @param windowChars   minimum context chars to keep left & right\r\n   */\r\n  private buildContext(\r\n    fullText: string,\r\n    start: number,\r\n    count: number,\r\n    windowChars = 30,\r\n  ): TextContext {\r\n    const WORD_BREAK = /[\\s\\u00A0.,;:!?()\\[\\]{}<>/\\\\\\-\"'`\"”\\u2013\\u2014]/;\r\n\r\n    // Find the start of a word moving left\r\n    const findWordStart = (index: number): number => {\r\n      while (index > 0 && !WORD_BREAK.test(fullText[index - 1])) index--;\r\n      return index;\r\n    };\r\n\r\n    // Find the end of a word moving right\r\n    const findWordEnd = (index: number): number => {\r\n      while (index < fullText.length && !WORD_BREAK.test(fullText[index])) index++;\r\n      return index;\r\n    };\r\n\r\n    // Move left to build context\r\n    let left = start;\r\n    while (left > 0 && WORD_BREAK.test(fullText[left - 1])) left--; // Skip blanks\r\n    let collected = 0;\r\n    while (left > 0 && collected < windowChars) {\r\n      left--;\r\n      if (!WORD_BREAK.test(fullText[left])) collected++;\r\n    }\r\n    left = findWordStart(left);\r\n\r\n    // Move right to build context\r\n    let right = start + count;\r\n    while (right < fullText.length && WORD_BREAK.test(fullText[right])) right++; // Skip blanks\r\n    collected = 0;\r\n    while (right < fullText.length && collected < windowChars) {\r\n      if (!WORD_BREAK.test(fullText[right])) collected++;\r\n      right++;\r\n    }\r\n    right = findWordEnd(right);\r\n\r\n    // Compose the context\r\n    const before = fullText.slice(left, start).replace(/\\s+/g, ' ').trimStart();\r\n    const match = fullText.slice(start, start + count);\r\n    const after = fullText\r\n      .slice(start + count, right)\r\n      .replace(/\\s+/g, ' ')\r\n      .trimEnd();\r\n\r\n    return {\r\n      before: this.tidy(before),\r\n      match: this.tidy(match),\r\n      after: this.tidy(after),\r\n      truncatedLeft: left > 0,\r\n      truncatedRight: right < fullText.length,\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Tidy the text to remove any non-printable characters and whitespace\r\n   * @param s - text to tidy\r\n   * @returns tidied text\r\n   *\r\n   * @private\r\n   */\r\n  private tidy(s: string): string {\r\n    return (\r\n      s\r\n        /* 1️⃣  join words split by hyphen + U+FFFE + whitespace */\r\n        .replace(/-\\uFFFE\\s*/g, '')\r\n\r\n        /* 2️⃣  drop any remaining U+FFFE, soft-hyphen, zero-width chars */\r\n        .replace(/[\\uFFFE\\u00AD\\u200B\\u2060\\uFEFF]/g, '')\r\n\r\n        /* 3️⃣  collapse whitespace so we stay on one line */\r\n        .replace(/\\s+/g, ' ')\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Search for all occurrences of a keyword on a single page\r\n   * This method efficiently loads the page only once and finds all matches\r\n   *\r\n   * @param docPtr - pointer to pdf document\r\n   * @param page - pdf page object\r\n   * @param pageIndex - index of the page\r\n   * @param keywordPtr - pointer to the search keyword\r\n   * @param flag - search flags\r\n   * @returns array of search results on this page\r\n   *\r\n   * @private\r\n   */\r\n  private searchAllInPage(\r\n    ctx: DocumentContext,\r\n    page: PdfPageObject,\r\n    keywordPtr: number,\r\n    flag: number,\r\n  ): SearchResult[] {\r\n    return ctx.borrowPage(page.index, (pageCtx) => {\r\n      const textPagePtr = pageCtx.getTextPage();\r\n\r\n      // Load the full text of the page once\r\n      const total = this.pdfiumModule.FPDFText_CountChars(textPagePtr);\r\n      const bufPtr = this.memoryManager.malloc(2 * (total + 1));\r\n      this.pdfiumModule.FPDFText_GetText(textPagePtr, 0, total, bufPtr);\r\n      const fullText = this.pdfiumModule.pdfium.UTF16ToString(bufPtr);\r\n      this.memoryManager.free(bufPtr);\r\n\r\n      const pageResults: SearchResult[] = [];\r\n\r\n      // Initialize search handle once for the page\r\n      const searchHandle = this.pdfiumModule.FPDFText_FindStart(\r\n        textPagePtr,\r\n        keywordPtr,\r\n        flag,\r\n        0, // Start from the beginning of the page\r\n      );\r\n\r\n      // Call FindNext repeatedly to get all matches on the page\r\n      while (this.pdfiumModule.FPDFText_FindNext(searchHandle)) {\r\n        const charIndex = this.pdfiumModule.FPDFText_GetSchResultIndex(searchHandle);\r\n        const charCount = this.pdfiumModule.FPDFText_GetSchCount(searchHandle);\r\n\r\n        const rects = this.getHighlightRects(page, textPagePtr, charIndex, charCount);\r\n\r\n        const context = this.buildContext(fullText, charIndex, charCount);\r\n\r\n        pageResults.push({\r\n          pageIndex: page.index,\r\n          charIndex,\r\n          charCount,\r\n          rects,\r\n          context,\r\n        });\r\n      }\r\n\r\n      // Close the search handle only once after finding all results\r\n      this.pdfiumModule.FPDFText_FindClose(searchHandle);\r\n      return pageResults;\r\n    });\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc @elhalawany/models!PdfEngine.preparePrintDocument}\r\n   *\r\n   * Prepares a PDF document for printing with specified options.\r\n   * Creates a new document with selected pages and optionally removes annotations\r\n   * for optimal printing performance.\r\n   *\r\n   * @public\r\n   */\r\n  preparePrintDocument(doc: PdfDocumentObject, options?: PdfPrintOptions): PdfTask<ArrayBuffer> {\r\n    const { includeAnnotations = true, pageRange = null } = options ?? {};\r\n\r\n    this.logger.debug(LOG_SOURCE, LOG_CATEGORY, 'preparePrintDocument', doc, options);\r\n    this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'Begin', doc.id);\r\n\r\n    // Verify document is open\r\n    const ctx = this.cache.getContext(doc.id);\r\n    if (!ctx) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.DocNotOpen,\r\n        message: 'Document is not open',\r\n      });\r\n    }\r\n\r\n    // Create new document for printing\r\n    const printDocPtr = this.pdfiumModule.FPDF_CreateNewDocument();\r\n    if (!printDocPtr) {\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'End', doc.id);\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.CantCreateNewDoc,\r\n        message: 'Cannot create print document',\r\n      });\r\n    }\r\n\r\n    try {\r\n      // Validate and sanitize page range\r\n      const sanitizedPageRange = this.sanitizePageRange(pageRange, doc.pageCount);\r\n\r\n      // Import pages from source document\r\n      // pageRange null means import all pages\r\n      if (\r\n        !this.pdfiumModule.FPDF_ImportPages(\r\n          printDocPtr,\r\n          ctx.docPtr,\r\n          sanitizedPageRange ?? '',\r\n          0, // Insert at beginning\r\n        )\r\n      ) {\r\n        this.pdfiumModule.FPDF_CloseDocument(printDocPtr);\r\n        this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'Failed to import pages for printing');\r\n        this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'End', doc.id);\r\n\r\n        return PdfTaskHelper.reject({\r\n          code: PdfErrorCode.CantImportPages,\r\n          message: 'Failed to import pages for printing',\r\n        });\r\n      }\r\n\r\n      // Remove annotations if requested\r\n      if (!includeAnnotations) {\r\n        const removalResult = this.removeAnnotationsFromPrintDocument(printDocPtr);\r\n\r\n        if (!removalResult.success) {\r\n          this.pdfiumModule.FPDF_CloseDocument(printDocPtr);\r\n          this.logger.error(\r\n            LOG_SOURCE,\r\n            LOG_CATEGORY,\r\n            `Failed to remove annotations: ${removalResult.error}`,\r\n          );\r\n          this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'End', doc.id);\r\n\r\n          return PdfTaskHelper.reject({\r\n            code: PdfErrorCode.Unknown,\r\n            message: `Failed to prepare print document: ${removalResult.error}`,\r\n          });\r\n        }\r\n\r\n        this.logger.debug(\r\n          LOG_SOURCE,\r\n          LOG_CATEGORY,\r\n          `Removed ${removalResult.annotationsRemoved} annotations from ${removalResult.pagesProcessed} pages`,\r\n        );\r\n      }\r\n\r\n      // Save the prepared document to buffer\r\n      const buffer = this.saveDocument(printDocPtr);\r\n\r\n      // Clean up\r\n      this.pdfiumModule.FPDF_CloseDocument(printDocPtr);\r\n\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'End', doc.id);\r\n      return PdfTaskHelper.resolve(buffer);\r\n    } catch (error) {\r\n      // Ensure cleanup on any error\r\n      if (printDocPtr) {\r\n        this.pdfiumModule.FPDF_CloseDocument(printDocPtr);\r\n      }\r\n\r\n      this.logger.error(LOG_SOURCE, LOG_CATEGORY, 'preparePrintDocument failed', error);\r\n      this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `PreparePrintDocument`, 'End', doc.id);\r\n\r\n      return PdfTaskHelper.reject({\r\n        code: PdfErrorCode.Unknown,\r\n        message: error instanceof Error ? error.message : 'Failed to prepare print document',\r\n      });\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Removes all annotations from a print document using fast raw annotation functions.\r\n   * This method is optimized for performance by avoiding full page loading.\r\n   *\r\n   * @param printDocPtr - Pointer to the print document\r\n   * @returns Result object with success status and statistics\r\n   *\r\n   * @private\r\n   */\r\n  private removeAnnotationsFromPrintDocument(printDocPtr: number): {\r\n    success: boolean;\r\n    annotationsRemoved: number;\r\n    pagesProcessed: number;\r\n    error?: string;\r\n  } {\r\n    let totalAnnotationsRemoved = 0;\r\n    let pagesProcessed = 0;\r\n\r\n    try {\r\n      const pageCount = this.pdfiumModule.FPDF_GetPageCount(printDocPtr);\r\n\r\n      // Process each page\r\n      for (let pageIndex = 0; pageIndex < pageCount; pageIndex++) {\r\n        // Get annotation count using the fast raw function\r\n        const annotCount = this.pdfiumModule.EPDFPage_GetAnnotCountRaw(printDocPtr, pageIndex);\r\n\r\n        if (annotCount <= 0) {\r\n          pagesProcessed++;\r\n          continue;\r\n        }\r\n\r\n        // Remove annotations in reverse order to maintain indices\r\n        // This is important because removing an annotation shifts the indices of subsequent ones\r\n        let annotationsRemovedFromPage = 0;\r\n\r\n        for (let annotIndex = annotCount - 1; annotIndex >= 0; annotIndex--) {\r\n          // Use the fast raw removal function\r\n          const removed = this.pdfiumModule.EPDFPage_RemoveAnnotRaw(\r\n            printDocPtr,\r\n            pageIndex,\r\n            annotIndex,\r\n          );\r\n\r\n          if (removed) {\r\n            annotationsRemovedFromPage++;\r\n            totalAnnotationsRemoved++;\r\n          } else {\r\n            this.logger.warn(\r\n              LOG_SOURCE,\r\n              LOG_CATEGORY,\r\n              `Failed to remove annotation ${annotIndex} from page ${pageIndex}`,\r\n            );\r\n          }\r\n        }\r\n\r\n        // Generate content for the page if annotations were removed\r\n        if (annotationsRemovedFromPage > 0) {\r\n          // We need to regenerate the page content after removing annotations\r\n          const pagePtr = this.pdfiumModule.FPDF_LoadPage(printDocPtr, pageIndex);\r\n          if (pagePtr) {\r\n            this.pdfiumModule.FPDFPage_GenerateContent(pagePtr);\r\n            this.pdfiumModule.FPDF_ClosePage(pagePtr);\r\n          }\r\n        }\r\n\r\n        pagesProcessed++;\r\n      }\r\n\r\n      return {\r\n        success: true,\r\n        annotationsRemoved: totalAnnotationsRemoved,\r\n        pagesProcessed: pagesProcessed,\r\n      };\r\n    } catch (error) {\r\n      return {\r\n        success: false,\r\n        annotationsRemoved: totalAnnotationsRemoved,\r\n        pagesProcessed: pagesProcessed,\r\n        error: error instanceof Error ? error.message : 'Unknown error during annotation removal',\r\n      };\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Sanitizes and validates a page range string.\r\n   * Ensures page numbers are within valid bounds and properly formatted.\r\n   *\r\n   * @param pageRange - Page range string (e.g., \"1,3,5-7\") or null for all pages\r\n   * @param totalPages - Total number of pages in the document\r\n   * @returns Sanitized page range string or null for all pages\r\n   *\r\n   * @private\r\n   */\r\n  private sanitizePageRange(\r\n    pageRange: string | null | undefined,\r\n    totalPages: number,\r\n  ): string | null {\r\n    // Null or empty means all pages\r\n    if (!pageRange || pageRange.trim() === '') {\r\n      return null;\r\n    }\r\n\r\n    try {\r\n      const sanitized: number[] = [];\r\n      const parts = pageRange.split(',');\r\n\r\n      for (const part of parts) {\r\n        const trimmed = part.trim();\r\n\r\n        if (trimmed.includes('-')) {\r\n          // Handle range (e.g., \"5-7\")\r\n          const [startStr, endStr] = trimmed.split('-').map((s) => s.trim());\r\n          const start = parseInt(startStr, 10);\r\n          const end = parseInt(endStr, 10);\r\n\r\n          if (isNaN(start) || isNaN(end)) {\r\n            this.logger.warn(LOG_SOURCE, LOG_CATEGORY, `Invalid range: ${trimmed}`);\r\n            continue;\r\n          }\r\n\r\n          // Clamp to valid bounds (1-based page numbers)\r\n          const validStart = Math.max(1, Math.min(start, totalPages));\r\n          const validEnd = Math.max(1, Math.min(end, totalPages));\r\n\r\n          // Add all pages in range\r\n          for (let i = validStart; i <= validEnd; i++) {\r\n            if (!sanitized.includes(i)) {\r\n              sanitized.push(i);\r\n            }\r\n          }\r\n        } else {\r\n          // Handle single page number\r\n          const pageNum = parseInt(trimmed, 10);\r\n\r\n          if (isNaN(pageNum)) {\r\n            this.logger.warn(LOG_SOURCE, LOG_CATEGORY, `Invalid page number: ${trimmed}`);\r\n            continue;\r\n          }\r\n\r\n          // Clamp to valid bounds\r\n          const validPageNum = Math.max(1, Math.min(pageNum, totalPages));\r\n\r\n          if (!sanitized.includes(validPageNum)) {\r\n            sanitized.push(validPageNum);\r\n          }\r\n        }\r\n      }\r\n\r\n      // If no valid pages found, return null (all pages)\r\n      if (sanitized.length === 0) {\r\n        this.logger.warn(LOG_SOURCE, LOG_CATEGORY, 'No valid pages in range, using all pages');\r\n        return null;\r\n      }\r\n\r\n      // Sort and convert back to range string\r\n      sanitized.sort((a, b) => a - b);\r\n\r\n      // Optimize consecutive pages into ranges\r\n      const optimized: string[] = [];\r\n      let rangeStart = sanitized[0];\r\n      let rangeEnd = sanitized[0];\r\n\r\n      for (let i = 1; i < sanitized.length; i++) {\r\n        if (sanitized[i] === rangeEnd + 1) {\r\n          rangeEnd = sanitized[i];\r\n        } else {\r\n          // End current range\r\n          if (rangeStart === rangeEnd) {\r\n            optimized.push(rangeStart.toString());\r\n          } else if (rangeEnd - rangeStart === 1) {\r\n            optimized.push(rangeStart.toString());\r\n            optimized.push(rangeEnd.toString());\r\n          } else {\r\n            optimized.push(`${rangeStart}-${rangeEnd}`);\r\n          }\r\n\r\n          // Start new range\r\n          rangeStart = sanitized[i];\r\n          rangeEnd = sanitized[i];\r\n        }\r\n      }\r\n\r\n      // Add final range\r\n      if (rangeStart === rangeEnd) {\r\n        optimized.push(rangeStart.toString());\r\n      } else if (rangeEnd - rangeStart === 1) {\r\n        optimized.push(rangeStart.toString());\r\n        optimized.push(rangeEnd.toString());\r\n      } else {\r\n        optimized.push(`${rangeStart}-${rangeEnd}`);\r\n      }\r\n\r\n      const result = optimized.join(',');\r\n\r\n      this.logger.debug(\r\n        LOG_SOURCE,\r\n        LOG_CATEGORY,\r\n        `Sanitized page range: \"${pageRange}\" -> \"${result}\"`,\r\n      );\r\n\r\n      return result;\r\n    } catch (error) {\r\n      this.logger.error(LOG_SOURCE, LOG_CATEGORY, `Error sanitizing page range: ${error}`);\r\n      return null; // Fallback to all pages\r\n    }\r\n  }\r\n}\r\n"],"names":["readString","wasmModule","readChars","parseChars","defaultLength","buffer","wasmExports","malloc","i","HEAP8","actualLength","str","free","readArrayBuffer","bufferSize","bufferPtr","arrayBuffer","ArrayBuffer","view","DataView","setInt8","getValue","RESERVED_INFO_KEYS","Set","isValidCustomKey","key","length","has","c","charCodeAt","computeFormDrawParams","matrix","rect","pageSize","rotation","rectLeft","origin","x","rectBottom","y","rectRight","size","width","rectTop","height","pageWidth","pageHeight","scaleX","Math","hypot","a","b","scaleY","d","swap","formsWidth","max","round","formsHeight","startX","startY","Rotation","Degree0","Degree90","Degree180","Degree270","DEFAULT_CONFIG","pageTtl","maxPagesPerDocument","PdfCache","constructor","pdfium","config","this","docs","Map","setDocument","id","filePtr","docPtr","ctx","get","DocumentContext","set","getContext","docId","closeDocument","dispose","delete","closeAllDocuments","values","clear","updateConfig","newConfig","Object","assign","getCacheStats","pagesByDocument","totalPages","entries","pageCount","getCacheSize","documents","pageCache","PageCache","acquirePage","pageIdx","acquire","borrowPage","fn","forceReleaseAll","pdf","FPDF_CloseDocument","cache","accessOrder","evictIfNeeded","pagePtr","FPDF_LoadPage","PageContext","removeFromAccessOrder","updateAccessOrder","clearExpiryTimer","bumpRefCount","existed","release","disposeImmediate","updateTtl","lruPageIdx","getRefCount","push","index","indexOf","splice","ttl","onFinalDispose","refCount","disposed","Error","expiryTimer","clearTimeout","newTtl","setTimeout","textPagePtr","FPDFText_ClosePage","formHandle","FORM_OnBeforeClosePage","PDFiumExt_ExitFormFillEnvironment","formInfoPtr","PDFiumExt_CloseFormFillInfo","FPDF_ClosePage","getTextPage","ensureAlive","FPDFText_LoadPage","getFormHandle","PDFiumExt_OpenFormFillInfo","PDFiumExt_InitFormFillEnvironment","FORM_OnAfterLoadPage","withAnnotation","annotIdx","annotPtr","FPDFPage_GetAnnot","FPDFPage_CloseAnnot","LIMITS","MAX_TOTAL_MEMORY","LOG_SOURCE","LOG_CATEGORY","MemoryManager","pdfiumModule","logger","allocations","totalAllocated","ptr","allocation","timestamp","Date","now","stack","isEnabled","warn","getStats","allocationCount","Array","from","checkLeaks","alloc","BitmapFormat","RenderFlag","PdfiumErrorCode","OffscreenCanvasError","message","super","name","browserImageDataToBlobConverter","getImageData","imageType","quality","OffscreenCanvas","Promise","reject","pdfImage","imageData","ImageData","data","off","putImageData","convertToBlob","type","options","memoryLeakCheckInterval","NoopLogger","imageDataConverter","memoryManager","setInterval","initialize","PdfTaskHelper","debug","perf","PDFiumExt_Init","resolve","destroy","FPDF_DestroyLibrary","clearInterval","withWString","value","stringToUTF16","withFloatArray","arr","bytes","setValue","openDocumentUrl","file","mode","password","url","task","create","loadTask","fetchFullAndOpen","openDocumentWithRangeRequest","rangeCheck","checkRangeSupport","supportsRanges","fileLength","content","pdfFile","openDocumentBuffer","wait","doc","err","reason","error","code","PdfErrorCode","Unknown","String","headResponse","fetch","method","headers","parseInt","testResponse","Range","status","e","response","ok","statusText","arrayBuf","knownFileLength","retrieveFileLength","openDocumentFromLoader","callback","offset","xhr","XMLHttpRequest","open","overrideMimeType","setRequestHeader","send","convertResponseToUint8Array","responseText","resp","lenStr","text","array","Uint8Array","HEAPU8","FPDF_LoadMemDocument","lastError","FPDF_GetLastError","FPDF_GetPageCount","pages","sizePtr","FPDF_GetPageSizeByIndexF","EPDF_GetPageRotationByIndex","page","pdfDoc","fileLoader","callbackPtr","addFunction","_pThis","pBuf","fileAccessPtr","FPDF_LoadCustomDocument","getMetadata","DocNotOpen","creationRaw","readMetaText","modRaw","metadata","title","author","subject","keywords","producer","creator","creationDate","pdfDateToDate","modificationDate","trapped","getMetaTrapped","custom","readAllMeta","setMetadata","meta","strMap","field","v","s","setMetaText","writeDate","raw","dateToPdfDate","setMetaTrapped","getDocPermissions","permissions","FPDF_GetDocPermissions","getDocUserPermissions","FPDF_GetDocUserPermissions","getSignatures","signatures","count","FPDF_GetSignatureCount","signatureObjPtr","FPDF_GetSignatureObject","contents","FPDFSignatureObj_GetContents","byteRange","FPDFSignatureObj_GetByteRange","subFilter","FPDFSignatureObj_GetSubFilter","bufferLength","FPDFSignatureObj_GetReason","UTF16ToString","time","FPDFSignatureObj_GetTime","UTF8ToString","docMDP","FPDFSignatureObj_GetDocMDPPermission","getBookmarks","bookmarks","readPdfBookmarks","setBookmarks","list","EPDFBookmark_Clear","build","parentPtr","items","item","bmPtr","wptr","EPDFBookmark_AppendChild","target","applyBookmarkTarget","_a","children","deleteBookmarks","renderPage","renderRectEncoded","renderPageRect","getAllAnnotations","cancelled","ignore","out","processChunk","startIdx","endIdx","min","annots","readPageAnnotationsRaw","progress","annotations","readAllAnnotations","annotationsByPage","pageAnnotations","readPageAnnotations","getPageAnnotations","createPageAnnotation","annotation","context","pageCtx","annotationPtr","EPDFPage_CreateAnnot","CantCreateAnnot","isUuidV4","uuidV4","setAnnotString","CantSetAnnotString","setPageAnnoRect","CantSetAnnotRect","isSucceed","PdfAnnotationSubtype","INK","addInkStroke","STAMP","addStampContent","TEXT","addTextContent","FREETEXT","addFreeTextContent","LINE","addLineContent","POLYLINE","POLYGON","addPolyContent","CIRCLE","SQUARE","addShapeContent","UNDERLINE","STRIKEOUT","SQUIGGLY","HIGHLIGHT","addTextMarkupContent","blendMode","EPDFAnnot_GenerateAppearanceWithBlend","EPDFAnnot_GenerateAppearance","FPDFPage_GenerateContent","FPDFPage_RemoveAnnot","CantSetAnnotContent","updatePageAnnotation","getAnnotationByName","NotFound","FPDFAnnot_RemoveInkList","removePageAnnotation","result","removeAnnotationByName","getPageTextRects","textRects","readPageTextRects","renderThumbnail","scaleFactor","rest","getAttachments","attachments","FPDFDoc_GetAttachmentCount","attachment","readPdfAttachment","addAttachment","params","description","mimeType","byteLength","attachmentPtr","wNamePtr","FPDFDoc_AddAttachment","wDescriptionPtr","EPDFAttachment_SetDescription","EPDFAttachment_SetSubtype","u8","len","contentPtr","FPDFAttachment_SetFile","removeAttachment","FPDFDoc_DeleteAttachment","readAttachmentContent","FPDFDoc_GetAttachment","FPDFAttachment_GetFile","CantReadAttachmentSize","CantReadAttachmentContent","setFormFieldValue","formFillInfoPtr","FORM_SetFocusedAnnot","CantFocusAnnot","kind","FORM_SelectAllText","FORM_ForceToKillFocus","CantSelectText","textPtr","FORM_ReplaceSelection","FORM_SetIndexSelected","isSelected","CantSelectOption","kReturn","FORM_OnChar","CantCheckField","flattenPage","flag","PdfPageFlattenFlag","Display","FPDFPage_Flatten","extractPages","pageIndexes","newDocPtr","FPDF_CreateNewDocument","CantCreateNewDoc","pageIndexesPtr","FPDF_ImportPagesByIndex","CantImportPages","saveDocument","extractText","strings","charCount","FPDFText_CountChars","FPDFText_GetText","join","getTextSlices","slices","byPage","forEach","pageIndex","slice","pos","bufPtr","charIndex","stripPdfUnwantedMarkers","merge","files","fileIds","map","ptrs","reverse","FPDF_ImportPages","random","mergePages","mergeConfigs","configIds","pageIndices","validPageIndices","filter","pageString","saveAsCopy","modified","setAnnotationDate","created","inReplyToId","setInReplyToId","setAnnotationIcon","icon","PdfAnnotationIcon","Comment","setAnnotationFlags","flags","state","stateModel","setBorderStyle","PdfAnnotationBorderStyle","SOLID","setAnnotationOpacity","opacity","setAnnotationTextAlignment","textAlign","setAnnotationVerticalAlignment","verticalAlign","setAnnotationDefaultAppearance","fontFamily","fontSize","fontColor","intent","setAnnotIntent","backgroundColor","setAnnotationColor","PdfAnnotationColorType","Color","EPDFAnnot_ClearColor","strokeWidth","setInkList","inkList","color","setLinePoints","linePoints","start","end","setLineEndings","lineEndings","PdfAnnotationLineEnding","None","_b","strokeStyle","setBorderDashPattern","strokeDashArray","InteriorColor","strokeColor","setPdfAnnoVertices","vertices","setAnnotCustom","syncQuadPointsAnno","segmentRects","FPDFAnnot_GetObjectCount","FPDFAnnot_RemoveObject","addImageObject","EPDFAnnot_UpdateAppearanceToRect","PdfStampFit","Cover","pixelCount","bitmapBufferPtr","red","green","blue","alpha","bitmapPtr","FPDFBitmap_CreateEx","imageObjectPtr","FPDFPageObj_NewImageObj","FPDFBitmap_Destroy","FPDFImageObj_SetBitmap","FPDFPageObj_Destroy","matrixPtr","FPDFPageObj_SetMatrix","pagePos","convertDevicePointToPagePoint","FPDFPageObj_Transform","FPDFAnnot_AppendObject","writerPtr","PDFiumExt_OpenFileWriter","PDFiumExt_SaveAsCopy","PDFiumExt_GetFileWriterSize","dataPtr","PDFiumExt_GetFileWriterData","PDFiumExt_CloseFileWriter","readCatalogLanguage","byteLen","EPDFCatalog_GetLanguage","EPDF_HasMetaText","FPDF_GetMetaText","EPDF_SetMetaText","Number","EPDF_GetMetaTrapped","PdfTrappedStatus","NotSet","True","False","toSet","EPDF_SetMetaTrapped","getMetaKeyCount","customOnly","EPDF_GetMetaKeyCount","getMetaKeyName","EPDF_GetMetaKeyName","buflen","n","rootBookmarkPtr","bookmarkPtr","FPDFBookmark_GetFirstChild","bookmark","readPdfBookmark","FPDFBookmark_GetNextSibling","FPDFBookmark_GetTitle","readPdfBookmarkTarget","FPDFBookmark_GetAction","FPDFBookmark_GetDest","rectsCount","FPDFText_CountRects","topPtr","leftPtr","rightPtr","bottomPtr","FPDFText_GetRect","left","top","right","bottom","deviceXPtr","deviceYPtr","FPDF_PageToDevice","ceil","abs","utf16Length","FPDFText_GetBoundedText","bytesCount","textBuffer","FPDFText_GetCharIndexAtPos","FPDFText_GetFontSize","FPDFText_GetFontInfo","textBufferPtr","flagsPtr","textRect","font","family","getPageGeometry","label","glyphCount","glyphs","g","readGlyphInfo","runs","buildRunsFromGlyphs","current","curObjPtr","bounds","objPtr","FPDFText_GetTextObject","charStart","minX","minY","maxX","maxY","isEmpty","isSpace","dx1Ptr","dy1Ptr","dx2Ptr","dy2Ptr","rectPtr","FPDFText_GetLooseCharBox","p","x1","y1","x2","y2","FPDFText_GetUnicode","getPageGlyphs","total","readCharBox","FPDFText_GetCharBox","annotationCount","FPDFPage_GetAnnotCount","anno","readPageAnnotation","EPDFPage_GetAnnotCountRaw","EPDFPage_GetAnnotRaw","getAnnotString","subType","FPDFAnnot_GetSubtype","readPdfTextAnno","readPdfFreeTextAnno","LINK","readPdfLinkAnno","WIDGET","readPdfWidgetAnno","FILEATTACHMENT","readPdfFileAttachmentAnno","readPdfInkAnno","readPdfPolygonAnno","readPdfPolylineAnno","readPdfLineAnno","readPdfHighlightAnno","readPdfStampAnno","readPdfSquareAnno","readPdfCircleAnno","readPdfUnderlineAnno","readPdfSquigglyAnno","readPdfStrikeOutAnno","CARET","readPdfCaretAnno","readPdfAnno","readAnnotationColor","colorType","rPtr","gPtr","bPtr","colour","EPDFAnnot_GetColor","getAnnotationColor","annotationColor","pdfColorToWebColor","webColor","pdfColor","webColorToPdfColor","EPDFAnnot_SetColor","getAnnotationOpacity","opacityPtr","EPDFAnnot_GetOpacity","pdfAlphaToWebOpacity","pdfOpacity","webOpacityToPdfAlpha","EPDFAnnot_SetOpacity","getAnnotationTextAlignment","EPDFAnnot_GetTextAlignment","alignment","EPDFAnnot_SetTextAlignment","getAnnotationVerticalAlignment","EPDFAnnot_GetVerticalAlignment","EPDFAnnot_SetVerticalAlignment","getAnnotationDefaultAppearance","fontPtr","EPDFAnnot_GetDefaultAppearance","EPDFAnnot_SetDefaultAppearance","getBorderStyle","widthPtr","style","UNKNOWN","EPDFAnnot_GetBorderStyle","EPDFAnnot_SetBorderStyle","getAnnotationIcon","EPDFAnnot_GetIcon","EPDFAnnot_SetIcon","getBorderEffect","intensityPtr","EPDFAnnot_GetBorderEffect","intensity","getRectangleDifferences","lPtr","tPtr","EPDFAnnot_GetRectangleDifferences","getAnnotationDate","date","getAttachmentDate","getAttachmentString","setAttachmentDate","setAttachmentString","getBorderDashPattern","EPDFAnnot_GetBorderDashPatternCount","pattern","arrPtr","okNative","EPDFAnnot_GetBorderDashPattern","EPDFAnnot_SetBorderDashPattern","clean","isFinite","getLineEndings","startPtr","endPtr","EPDFAnnot_GetLineEndings","EPDFAnnot_SetLineEndings","getLinePoints","FPDFAnnot_GetLine","sx","sy","ex","ey","convertPagePointToDevicePoint","p1","p2","buf","EPDFAnnot_SetLine","getQuadPointsAnno","quadCount","FPDFAnnot_CountAttachmentPoints","quads","qi","quadPtr","FPDFAnnot_GetAttachmentPoints","xs","ys","base","p3","p4","quadToRect","rects","writeQuad","r","q","rectToQuad","FPDFAnnot_SetAttachmentPoints","FPDFAnnot_AppendAttachmentPoints","redactTextInRects","recurseForms","drawBlackBoxes","_c","_d","allocFSQuadsBufferFromRects","EPDFText_RedactInQuads","getInkList","pathCount","FPDFAnnot_GetInkListCount","points","FPDFAnnot_GetInkListPath","j","px","py","stroke","pDev","pPage","idx","FPDFAnnot_AddInkStroke","getAnnotCustom","annoRect","readPageAnnoRect","convertPageRectToDeviceRect","getInReplyToId","getAnnotationFlags","defaultStyle","da","richContent","getAnnotRichContent","PdfStandardFont","linkPtr","FPDFAnnot_GetLink","readPdfLinkAnnoTarget","FPDFLink_GetAction","FPDFLink_GetDest","pageRect","readPdfWidgetAnnoField","EPDFAnnot_GetBlendMode","getAnnotIntent","readPdfAnnoVertices","interiorColor","DASHED","first","last","pop","readPdfPageObject","pageObjectPtr","FPDFPageObj_GetType","PdfPageObjectType","PATH","readPathObject","IMAGE","readImageObject","FORM","readFormObject","pathObjectPtr","segmentCount","FPDFPath_CountSegments","FPDFPageObj_GetBounds","segments","segment","readPdfSegment","readPdfPageObjectTransformMatrix","annotationObjectPtr","segmentIndex","segmentPtr","FPDFPath_GetPathSegment","segmentType","FPDFPathSegment_GetType","isClosed","FPDFPathSegment_GetClose","pointXPtr","pointYPtr","FPDFPathSegment_GetPoint","pointX","pointY","point","FPDFImageObj_GetBitmap","FPDFBitmap_GetBuffer","bitmapWidth","FPDFBitmap_GetWidth","bitmapHeight","FPDFBitmap_GetHeight","format","FPDFBitmap_GetFormat","Uint8ClampedArray","formObjectPtr","objectCount","FPDFFormObj_CountObjects","objects","FPDFFormObj_GetObject","pageObj","FPDFPageObj_GetMatrix","f","readStampAnnotationContents","FPDFAnnot_GetObject","getStrokeWidth","hPtr","vPtr","wPtr","FPDFAnnot_GetBorder","rawFlags","FPDFAnnot_GetFlags","flagsToNames","namesToFlags","FPDFAnnot_SetFlags","FPDFAnnot_GetLinkedAnnot","EPDFAnnot_SetLinkedAnnot","FPDFAnnot_GetStringValue","FPDFAttachment_GetStringValue","getAttachmentNumber","outPtr","EPDFAttachment_GetIntegerValue","JSON","parse","console","jsonString","stringify","EPDFAnnot_GetIntent","EPDFAnnot_SetIntent","EPDFAnnot_GetRichContent","EPDFPage_GetAnnotByName","EPDFPage_RemoveAnnotByName","wValPtr","FPDFAnnot_SetStringValue","FPDFAttachment_SetStringValue","FPDFAnnot_GetVertices","pointsPtr","pagePt","EPDFAnnot_SetVertices","getActionPtr","getDestinationPtr","actionPtr","action","readPdfAction","destinationPtr","destination","readPdfDestination","FPDFAnnot_GetFormFieldFlags","FPDFAnnot_GetFormFieldType","FPDFAnnot_GetFormFieldName","alternateName","FPDFAnnot_GetFormFieldAlternateName","FPDFAnnot_GetFormFieldValue","PDF_FORM_FIELD_TYPE","COMBOBOX","LISTBOX","FPDFAnnot_GetOptionCount","FPDFAnnot_GetOptionLabel","FPDFAnnot_IsOptionSelected","isChecked","CHECKBOX","RADIOBUTTON","FPDFAnnot_IsChecked","renderPageAnnotation","dpr","AppearanceMode","Normal","imageQuality","Task","finalScale","toIntRect","devRect","transformRect","wDev","hDev","stride","heapPtr","FPDFBitmap_FillRect","M","buildUserToDeviceMatrix","mPtr","Float32Array","HEAPF32","EPDF_RenderAnnotBitmap","rgba","subarray","then","catch","blob","encodeViaWasm","wasmError","finally","opts","blobFrom","mime","copy","Blob","outPtrPtr","EPDF_PNG_EncodeRGBA","baseW","baseH","withForms","clipPtr","withAnnotations","FPDF_RenderPageBitmapWithMatrix","formParams","FPDF_FFLDraw","heapBuf","info","createLocalDestPtr","dest","zoom","PdfZoomMode","XYZ","EPDFDest_CreateXYZ","viewEnum","FitPage","FitHorizontal","FitVertical","FitRectangle","EPDFDest_CreateView","destPtr","EPDFBookmark_SetDest","PdfActionType","Goto","actPtr","EPDFAction_CreateGoTo","EPDFBookmark_SetAction","URI","EPDFAction_CreateURI","uri","LaunchAppOrOpenFile","path","EPDFAction_CreateLaunch","RemoteGoto","Unsupported","FPDFAction_GetType","FPDFAction_GetDest","FPDFAction_GetURIPath","FPDFAction_GetFilePath","FPDFDest_GetDestPageIndex","paramsCountPtr","paramsPtr","maxParmamsCount","zoomMode","FPDFDest_GetView","paramsCount","paramPtr","hasXPtr","hasYPtr","hasZPtr","xPtr","yPtr","zPtr","FPDFDest_GetLocationInPage","hasX","hasY","hasZ","FPDFAttachment_GetName","EPDFAttachment_GetDescription","FPDFAttachment_GetSubtype","checksum","position","DW","DH","readPageAnnoAppearanceStreams","normal","readPageAnnoAppearanceStream","rollover","Rollover","down","Down","FPDFAnnot_GetAP","ap","setPageAnnoAppearanceStream","apContent","FPDFAnnot_SetAP","x0d","floor","y0d","x1d","y1d","TL","TR","BR","BL","FPDFAnnot_SetRect","pageRectPtr","FPDFAnnot_GetRect","getHighlightRects","startIndex","highlightRects","l","t","searchAllPages","keyword","results","keywordPtr","reduce","acc","MatchFlag","allResults","pageResults","searchAllInPage","buildContext","fullText","windowChars","WORD_BREAK","test","collected","findWordStart","findWordEnd","before","replace","trimStart","match","after","trimEnd","tidy","truncatedLeft","truncatedRight","searchHandle","FPDFText_FindStart","FPDFText_FindNext","FPDFText_GetSchResultIndex","FPDFText_GetSchCount","FPDFText_FindClose","preparePrintDocument","includeAnnotations","pageRange","printDocPtr","sanitizedPageRange","sanitizePageRange","removalResult","removeAnnotationsFromPrintDocument","success","annotationsRemoved","pagesProcessed","totalAnnotationsRemoved","annotCount","annotationsRemovedFromPage","annotIndex","EPDFPage_RemoveAnnotRaw","trim","sanitized","parts","split","part","trimmed","includes","startStr","endStr","isNaN","validStart","validEnd","pageNum","validPageNum","sort","optimized","rangeStart","rangeEnd","toString"],"mappings":"mDAaO,SAASA,EACdC,EACAC,EACAC,EACAC,EAAwB,KAExB,IAAIC,EAASJ,EAAWK,YAAYC,OAAOH,GAC3C,IAAA,IAASI,EAAI,EAAGA,EAAIJ,EAAeI,IACtBP,EAAAQ,MAAMJ,EAASG,GAAK,EAE3B,MAAAE,EAAeR,EAAUG,EAAQD,GACnC,IAAAO,EACJ,GAAID,EAAeN,EAAe,CACrBH,EAAAK,YAAYM,KAAKP,GACnBA,EAAAJ,EAAWK,YAAYC,OAAOG,GACvC,IAAA,IAASF,EAAI,EAAGA,EAAIE,EAAcF,IACrBP,EAAAQ,MAAMJ,EAASG,GAAK,EAEjCN,EAAUG,EAAQK,GAClBC,EAAMR,EAAWE,EAAM,MAEvBM,EAAMR,EAAWE,GAIZ,OAFIJ,EAAAK,YAAYM,KAAKP,GAErBM,CACT,CASgB,SAAAE,EACdZ,EACAC,GAEM,MAAAY,EAAaZ,EAAU,EAAG,GAE1Ba,EAAYd,EAAWK,YAAYC,OAAOO,GAEhDZ,EAAUa,EAAWD,GAEf,MAAAE,EAAc,IAAIC,YAAYH,GAC9BI,EAAO,IAAIC,SAASH,GAE1B,IAAA,IAASR,EAAI,EAAGA,EAAIM,EAAYN,IAC9BU,EAAKE,QAAQZ,EAAGP,EAAWoB,SAASN,EAAYP,EAAG,OAK9C,OAFIP,EAAAK,YAAYM,KAAKG,GAErBC,CACT,CAEA,MAAMM,MAAyBC,IAAI,CACjC,QACA,SACA,UACA,WACA,WACA,UACA,eACA,UACA,YAGK,SAASC,EAAiBC,GAG/B,IAAKA,GAAOA,EAAIC,OAAS,IAAY,OAAA,EACrC,GAAIJ,EAAmBK,IAAIF,GAAa,OAAA,EACxC,GAAe,MAAXA,EA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