mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-07 17:05:38 +02:00
Allow /XYZ destinations without zoom parameter (issue 18408)
According to the PDF specification these destinations should have a zoom 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 zoom parameter optional when validating explicit destinations in both the worker and the viewer.
This commit is contained in:
parent
e1f64a5b3e
commit
d24a61c648
5 changed files with 54 additions and 8 deletions
|
@ -64,26 +64,27 @@ function isValidExplicitDest(dest) {
|
||||||
if (!(zoom instanceof Name)) {
|
if (!(zoom instanceof Name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const argsLen = args.length;
|
||||||
let allowNull = true;
|
let allowNull = true;
|
||||||
switch (zoom.name) {
|
switch (zoom.name) {
|
||||||
case "XYZ":
|
case "XYZ":
|
||||||
if (args.length !== 3) {
|
if (argsLen < 2 || argsLen > 3) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Fit":
|
case "Fit":
|
||||||
case "FitB":
|
case "FitB":
|
||||||
return args.length === 0;
|
return argsLen === 0;
|
||||||
case "FitH":
|
case "FitH":
|
||||||
case "FitBH":
|
case "FitBH":
|
||||||
case "FitV":
|
case "FitV":
|
||||||
case "FitBV":
|
case "FitBV":
|
||||||
if (args.length > 1) {
|
if (argsLen > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "FitR":
|
case "FitR":
|
||||||
if (args.length !== 4) {
|
if (argsLen !== 4) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
allowNull = false;
|
allowNull = false;
|
||||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -13,6 +13,7 @@
|
||||||
!issue1155r.pdf
|
!issue1155r.pdf
|
||||||
!issue2017r.pdf
|
!issue2017r.pdf
|
||||||
!bug1727053.pdf
|
!bug1727053.pdf
|
||||||
|
!issue18408_reduced.pdf
|
||||||
!bug1907000_reduced.pdf
|
!bug1907000_reduced.pdf
|
||||||
!issue11913.pdf
|
!issue11913.pdf
|
||||||
!issue2391-1.pdf
|
!issue2391-1.pdf
|
||||||
|
|
BIN
test/pdfs/issue18408_reduced.pdf
Normal file
BIN
test/pdfs/issue18408_reduced.pdf
Normal file
Binary file not shown.
|
@ -1901,6 +1901,49 @@ describe("api", function () {
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("gets outline, with /XYZ destinations that lack zoom parameter (issue 18408)", async function () {
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("issue18408_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: "XYZ" }, 65, 705],
|
||||||
|
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: "XYZ" }, 60, 710],
|
||||||
|
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 outline, with /FitH destinations that lack coordinate parameter (bug 1907000)", async function () {
|
it("gets outline, with /FitH destinations that lack coordinate parameter (bug 1907000)", async function () {
|
||||||
const loadingTask = getDocument(
|
const loadingTask = getDocument(
|
||||||
buildGetDocumentParams("bug1907000_reduced.pdf")
|
buildGetDocumentParams("bug1907000_reduced.pdf")
|
||||||
|
|
|
@ -505,26 +505,27 @@ class PDFLinkService {
|
||||||
if (!(typeof zoom === "object" && typeof zoom?.name === "string")) {
|
if (!(typeof zoom === "object" && typeof zoom?.name === "string")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const argsLen = args.length;
|
||||||
let allowNull = true;
|
let allowNull = true;
|
||||||
switch (zoom.name) {
|
switch (zoom.name) {
|
||||||
case "XYZ":
|
case "XYZ":
|
||||||
if (args.length !== 3) {
|
if (argsLen < 2 || argsLen > 3) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Fit":
|
case "Fit":
|
||||||
case "FitB":
|
case "FitB":
|
||||||
return args.length === 0;
|
return argsLen === 0;
|
||||||
case "FitH":
|
case "FitH":
|
||||||
case "FitBH":
|
case "FitBH":
|
||||||
case "FitV":
|
case "FitV":
|
||||||
case "FitBV":
|
case "FitBV":
|
||||||
if (args.length > 1) {
|
if (argsLen > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "FitR":
|
case "FitR":
|
||||||
if (args.length !== 4) {
|
if (argsLen !== 4) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
allowNull = false;
|
allowNull = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue