(entries: Array<[string, PdfRef]>)
| 311 | * @returns A PdfDict representing the name tree root |
| 312 | */ |
| 313 | export function buildNameTree(entries: Array<[string, PdfRef]>): PdfDict { |
| 314 | // Sort entries by key (lexicographic) |
| 315 | const sorted = [...entries].sort((a, b) => compareKeys(a[0], b[0])); |
| 316 | |
| 317 | // Build flat /Names array: [key1, ref1, key2, ref2, ...] |
| 318 | const namesArray: PdfObject[] = []; |
| 319 | |
| 320 | for (const [key, ref] of sorted) { |
| 321 | namesArray.push(PdfString.fromString(key)); |
| 322 | namesArray.push(ref); |
| 323 | } |
| 324 | |
| 325 | const dict = new PdfDict(); |
| 326 | dict.set("Names", new PdfArray(namesArray)); |
| 327 | |
| 328 | return dict; |
| 329 | } |
no test coverage detected