(dict: PdfDict)
| 65 | * @returns The parsed parameters, or null if invalid |
| 66 | */ |
| 67 | export function parseLinearizationDict(dict: PdfDict): LinearizationParams | null { |
| 68 | // Required fields |
| 69 | const version = dict.getNumber("Linearized")?.value; |
| 70 | const fileLength = dict.getNumber("L")?.value; |
| 71 | const firstPage = dict.getNumber("O")?.value; |
| 72 | const endOfFirstPage = dict.getNumber("E")?.value; |
| 73 | const pageCount = dict.getNumber("N")?.value; |
| 74 | const mainXRefOffset = dict.getNumber("T")?.value; |
| 75 | |
| 76 | // Hint stream info (in /H array) |
| 77 | const hintArray = dict.getArray("H"); |
| 78 | const hintOffset = hintArray?.at(0); |
| 79 | const hintLength = hintArray?.at(1); |
| 80 | |
| 81 | if ( |
| 82 | version === undefined || |
| 83 | fileLength === undefined || |
| 84 | firstPage === undefined || |
| 85 | endOfFirstPage === undefined || |
| 86 | pageCount === undefined || |
| 87 | mainXRefOffset === undefined |
| 88 | ) { |
| 89 | return null; |
| 90 | } |
| 91 | |
| 92 | return { |
| 93 | version, |
| 94 | fileLength, |
| 95 | hintOffset: hintOffset && hintOffset instanceof PdfNumber ? hintOffset.value : 0, |
| 96 | hintLength: hintLength && hintLength instanceof PdfNumber ? hintLength.value : 0, |
| 97 | firstPage, |
| 98 | endOfFirstPage, |
| 99 | pageCount, |
| 100 | mainXRefOffset, |
| 101 | }; |
| 102 | } |
no test coverage detected