Improve handling of corrupt pages in the PDFDocumentProperties dialog

If the active page is corrupt that currently results in the entire dialog being "blank", thus providing no information, which seems unfortunate and it's easy enough to only skip `pageSizeField` in that rare case.
This commit is contained in:
Jonas Jenwald 2026-05-18 17:26:39 +02:00
parent e05b6d6f59
commit 1e62f01773
2 changed files with 88 additions and 9 deletions

View File

@ -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);
})
);
});
});
});

View File

@ -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 = {