* Get an object by its index within the stream. * * @param index - 0-based index from XRef entry's indexInStream * @returns The parsed object, or null if index is out of range
(index: number)
| 148 | * @returns The parsed object, or null if index is out of range |
| 149 | */ |
| 150 | getObject(index: number): PdfObject | null { |
| 151 | this.parse(); |
| 152 | |
| 153 | if (this.index === null) { |
| 154 | throw new ObjectParseError("Index not parsed"); |
| 155 | } |
| 156 | |
| 157 | if (index < 0 || index >= this.index.length) { |
| 158 | return null; |
| 159 | } |
| 160 | |
| 161 | const entry = this.index[index]; |
| 162 | |
| 163 | if (this.decodedData === null) { |
| 164 | throw new ObjectParseError("Decoded data not parsed"); |
| 165 | } |
| 166 | |
| 167 | // Create scanner starting at the object's offset within the object section |
| 168 | const objectSection = this.decodedData.subarray(this.first); |
| 169 | const scanner = new Scanner(objectSection); |
| 170 | |
| 171 | scanner.moveTo(entry.offset); |
| 172 | |
| 173 | const reader = new TokenReader(scanner); |
| 174 | const parser = new ObjectParser(reader); |
| 175 | |
| 176 | parser.recoveryMode = this.options.recoveryMode ?? false; |
| 177 | parser.onWarning = this.options.onWarning ?? null; |
| 178 | |
| 179 | const result = parser.parseObject(); |
| 180 | |
| 181 | return result?.object ?? null; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Get all objects in this stream. |
no test coverage detected