mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 01:28:06 +02:00
[api-minor] Let Catalog.getAllPageDicts
return an *empty* dictionary when loading the first /Page fails (issue 15590)
In order to support opening certain corrupt PDF documents, particularly hand-edited ones, this patch adds support for letting the `Catalog.getAllPageDicts` method fallback to returning an *empty* dictionary to replace (only) the first /Page of the document. Given that the viewer cannot initialize/load without access to the first page, this will thus allow e.g. document-level scripting to run as expected. Note that by effectively replacing a corrupt or missing first /Page in this way[1], we'll now render nothing but a *blank* page for certain cases of broken/corrupt PDF documents which may look weird. *Please note:* This functionality is controlled via the existing `stopAtErrors` option, that can be passed to `getDocument`, since it's easy to imagine use-cases where this sort of fallback behaviour isn't desirable. --- [1] Currently we still require that a /Pages-dictionary is found though, however it *may* be possible to relax even that assumption if that becomes absolutely necessary in future corrupt documents.
This commit is contained in:
parent
2516ffa78e
commit
23930a249e
2 changed files with 37 additions and 20 deletions
|
@ -1191,6 +1191,8 @@ class Catalog {
|
|||
* @returns {Promise<Map>}
|
||||
*/
|
||||
async getAllPageDicts(recoveryMode = false) {
|
||||
const { ignoreErrors } = this.pdfManager.evaluatorOptions;
|
||||
|
||||
const queue = [{ currentNode: this.toplevelPagesDict, posInKids: 0 }];
|
||||
const visitedNodes = new RefSet();
|
||||
|
||||
|
@ -1215,6 +1217,11 @@ class Catalog {
|
|||
if (error instanceof XRefEntryException && !recoveryMode) {
|
||||
throw error;
|
||||
}
|
||||
if (recoveryMode && ignoreErrors && pageIndex === 0) {
|
||||
// Ensure that the viewer will always load (fixes issue15590.pdf).
|
||||
warn(`getAllPageDicts - Skipping invalid first page: "${error}".`);
|
||||
error = Dict.empty;
|
||||
}
|
||||
|
||||
map.set(pageIndex++, [error, null]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue