MCPcopy Create free account
hub / github.com/LibPDF-js/core / parseLinearizationDict

Function parseLinearizationDict

src/document/linearization.ts:67–102  ·  view source on GitHub ↗
(dict: PdfDict)

Source from the content-addressed store, hash-verified

65 * @returns The parsed parameters, or null if invalid
66 */
67export 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}

Callers 1

Calls 3

getArrayMethod · 0.80
atMethod · 0.80
getNumberMethod · 0.45

Tested by

no test coverage detected