diff --git a/test/integration/document_properties_spec.mjs b/test/integration/document_properties_spec.mjs index 6afb20f1a..e4192dd64 100644 --- a/test/integration/document_properties_spec.mjs +++ b/test/integration/document_properties_spec.mjs @@ -88,7 +88,7 @@ describe("PDFDocumentProperties", () => { await closePages(pages); }); - it("must check that the document properties dialog has the correct information", async () => { + it("check that the document properties dialog has the correct information", async () => { await Promise.all( pages.map(async ([browserName, page]) => { await openDocumentProperties(page); @@ -130,7 +130,7 @@ describe("PDFDocumentProperties", () => { await closePages(pages); }); - it("must check that the document properties dialog has the correct information", async () => { + it("check that the document properties dialog has the correct information", async () => { await Promise.all( pages.map(async ([browserName, page]) => { await openDocumentProperties(page); @@ -169,7 +169,7 @@ describe("PDFDocumentProperties", () => { await closePages(pages); }); - it("must check that the document properties dialog has the correct information", async () => { + it("check that the document properties dialog has the correct information", async () => { await Promise.all( pages.map(async ([browserName, page]) => { // Open a binary PDF document, such that `contentLength` is undefined. @@ -219,7 +219,7 @@ describe("PDFDocumentProperties", () => { await closePages(pages); }); - it("must check that the document properties dialog has the correct information", async () => { + it("check that the document properties dialog has the correct information", async () => { await Promise.all( pages.map(async ([browserName, page]) => { await openDocumentProperties(page); @@ -300,7 +300,7 @@ describe("PDFDocumentProperties", () => { await closePages(pages); }); - it("must check that the document properties dialog has the correct information", async () => { + it("check that the document properties dialog has the correct information", async () => { await Promise.all( pages.map(async ([browserName, page]) => { await openDocumentProperties(page); @@ -354,4 +354,76 @@ describe("PDFDocumentProperties", () => { ); }); }); + + describe("Document with corrupt page", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait( + "Pages-tree-refs.pdf", + ".textLayer .endOfContent", + null, + null, + { page: 2 } + ); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("check that the document properties dialog has the correct information", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await openDocumentProperties(page); + + await checkFieldProperties(page, { + fileName: "Pages-tree-refs.pdf", + fileSize: `${FSI}1.07${PDI} KB (${FSI}1,098${PDI} bytes)`, + title: "-", + author: "-", + subject: "-", + keywords: "-", + creationDate: "-", + modificationDate: "-", + creator: "-", + producer: "-", + version: "1.7", + pageCount: "2", + pageSize: "-", + linearized: "No", + }); + + await closeDocumentProperties(page); + + // Goto the first page (which is *not* corrupt). + await page.click("#previous"); + await page.waitForFunction( + () => window.PDFViewerApplication.page === 1 + ); + + await openDocumentProperties(page); + + await checkFieldProperties(page, { + fileName: "Pages-tree-refs.pdf", + fileSize: `${FSI}1.07${PDI} KB (${FSI}1,098${PDI} bytes)`, + title: "-", + author: "-", + subject: "-", + keywords: "-", + creationDate: "-", + modificationDate: "-", + creator: "-", + producer: "-", + version: "1.7", + pageCount: "2", + pageSize: `${FSI}8.27${PDI} × ${FSI}11.69${PDI} ${FSI}in${PDI} (${FSI}A4${PDI}, ${FSI}portrait${PDI})`, + linearized: "No", + }); + + await closeDocumentProperties(page); + }) + ); + }); + }); }); diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index f7150b72c..98327e8bf 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -121,7 +121,13 @@ class PDFDocumentProperties { pdfPage, ] = await Promise.all([ this.pdfDocument.getMetadata(), - this.pdfDocument.getPage(currentPageNumber), + this.pdfDocument.getPage(currentPageNumber).catch(reason => { + console.error( + `PDFDocumentProperties - unable to get page ${currentPageNumber}.`, + reason + ); + return null; + }), ]); const [ @@ -138,7 +144,7 @@ class PDFDocumentProperties { this._titleLookup(), this.#parseDate(metadata?.get("xmp:createdate"), info.CreationDate), this.#parseDate(metadata?.get("xmp:modifydate"), info.ModDate), - this.#parsePageSize(getPageSizeInches(pdfPage), pagesRotation), + this.#parsePageSize(pdfPage, pagesRotation), this.#parseLinearization(info.IsLinearized), ]); @@ -245,10 +251,11 @@ class PDFDocumentProperties { : undefined; } - async #parsePageSize(pageSizeInches, pagesRotation) { - if (!pageSizeInches) { + async #parsePageSize(pdfPage, pagesRotation) { + if (!pdfPage) { return undefined; } + let pageSizeInches = getPageSizeInches(pdfPage); // Take the viewer rotation into account as well; compare with Adobe Reader. if (pagesRotation % 180 !== 0) { pageSizeInches = {