| 18 | } |
| 19 | |
| 20 | toString() { |
| 21 | // Needs to be sorted by key |
| 22 | const sortedKeys = Object.keys(this._items).sort((a, b) => |
| 23 | a.localeCompare(b), |
| 24 | ); |
| 25 | |
| 26 | const out = ['<<']; |
| 27 | if (sortedKeys.length > 1) { |
| 28 | const first = sortedKeys[0], |
| 29 | last = sortedKeys[sortedKeys.length - 1]; |
| 30 | out.push( |
| 31 | ` /Limits ${PDFObject.convert([new String(first), new String(last)])}`, |
| 32 | ); |
| 33 | } |
| 34 | out.push(' /Names ['); |
| 35 | for (let key of sortedKeys) { |
| 36 | out.push( |
| 37 | ` ${PDFObject.convert(new String(key))} ${PDFObject.convert( |
| 38 | this._items[key], |
| 39 | )}`, |
| 40 | ); |
| 41 | } |
| 42 | out.push(']'); |
| 43 | out.push('>>'); |
| 44 | return out.join('\n'); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | export default PDFNameTree; |