Skip to content

Commit

Permalink
Allow e.g. /FitH destinations without additional parameter (bug 1907000)
Browse files Browse the repository at this point in the history
According to the PDF specification these destinations should have a coordinate parameter, which may however be `null`, but it shouldn't be omitted; please see https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G11.2095870

Hence we try to work-around bad PDF generators by making the coordinate parameter optional when validating explicit destinations in both the worker and the viewer.
  • Loading branch information
Snuffleupagus committed Jul 11, 2024
1 parent cf58113 commit 403d023
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function isValidExplicitDest(dest) {
case "FitBH":
case "FitV":
case "FitBV":
if (args.length !== 1) {
if (args.length > 1) {
return false;
}
break;
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
!issue1155r.pdf
!issue2017r.pdf
!bug1727053.pdf
!bug1907000_reduced.pdf
!issue11913.pdf
!issue2391-1.pdf
!issue2391-2.pdf
Expand Down
Binary file added test/pdfs/bug1907000_reduced.pdf
Binary file not shown.
43 changes: 43 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,49 @@ describe("api", function () {
await loadingTask.destroy();
});

it("gets outline, with /FitH destinations that lack coordinate parameter (bug 1907000)", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("bug1907000_reduced.pdf")
);
const pdfDoc = await loadingTask.promise;
const outline = await pdfDoc.getOutline();

expect(outline).toEqual([
{
action: null,
attachment: undefined,
dest: [{ num: 14, gen: 0 }, { name: "FitH" }],
url: null,
unsafeUrl: undefined,
newWindow: undefined,
setOCGState: undefined,
title: "Page 1",
color: new Uint8ClampedArray([0, 0, 0]),
count: undefined,
bold: false,
italic: false,
items: [],
},
{
action: null,
attachment: undefined,
dest: [{ num: 13, gen: 0 }, { name: "FitH" }],
url: null,
unsafeUrl: undefined,
newWindow: undefined,
setOCGState: undefined,
title: "Page 2",
color: new Uint8ClampedArray([0, 0, 0]),
count: undefined,
bold: false,
italic: false,
items: [],
},
]);

await loadingTask.destroy();
});

it("gets non-existent permissions", async function () {
const permissions = await pdfDocument.getPermissions();
expect(permissions).toEqual(null);
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_link_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class PDFLinkService {
case "FitBH":
case "FitV":
case "FitBV":
if (args.length !== 1) {
if (args.length > 1) {
return false;
}
break;
Expand Down

0 comments on commit 403d023

Please sign in to comment.