Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Annotations with corrupt /BS-entries #17395

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,15 @@ class Annotation {
}
if (borderStyle.has("BS")) {
const dict = borderStyle.get("BS");
const dictType = dict.get("Type");

if (!dictType || isName(dictType, "Border")) {
this.borderStyle.setWidth(dict.get("W"), this.rectangle);
this.borderStyle.setStyle(dict.get("S"));
this.borderStyle.setDashArray(dict.getArray("D"));
if (dict instanceof Dict) {
const dictType = dict.get("Type");

if (!dictType || isName(dictType, "Border")) {
this.borderStyle.setWidth(dict.get("W"), this.rectangle);
this.borderStyle.setStyle(dict.get("S"));
this.borderStyle.setDashArray(dict.getArray("D"));
}
}
} else if (borderStyle.has("Border")) {
const array = borderStyle.getArray("Border");
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/pypdf2332.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/py-pdf/pypdf/files/13606678/output.pdf
9 changes: 9 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,15 @@
"rounds": 1,
"type": "eq"
},
{ "id": "pypdf2332",
"file": "pdfs/pypdf2332.pdf",
"md5": "883d2cf4d0ed16e32c917498fe9843dd",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq",
"annotations": true
},
{ "id": "issue6151",
"file": "pdfs/issue6151.pdf",
"md5": "926f8c6b25e6f0978759f7947d70e079",
Expand Down
6 changes: 2 additions & 4 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
import {
CMAP_URL,
createIdFactory,
getNodeVersion,
Snuffleupagus marked this conversation as resolved.
Show resolved Hide resolved
STANDARD_FONT_DATA_URL,
XRefMock,
} from "./test_utils.js";
Expand Down Expand Up @@ -2209,10 +2208,9 @@ describe("annotation", function () {
});

it("should compress and save text", async function () {
if (isNodeJS && getNodeVersion().major >= 20) {
if (isNodeJS) {
pending(
"CompressionStream behaves differently in Node.js >= 20, " +
"compared to Firefox, Chrome, and Node.js 18."
"CompressionStream behaves differently in Node.js, compared to Firefox and Chrome."
Snuffleupagus marked this conversation as resolved.
Show resolved Hide resolved
);
}
const textWidgetRef = Ref.get(123, 0);
Expand Down
11 changes: 0 additions & 11 deletions test/unit/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,11 @@ function createIdFactory(pageIndex) {
return page._localIdFactory;
}

function getNodeVersion() {
if (!isNodeJS) {
throw new Error("getNodeVersion - only valid in Node.js environments.");
}
const [major, minor, patch] = process.versions.node
.split(".")
.map(parseFloat);
return { major, minor, patch };
}

export {
buildGetDocumentParams,
CMAP_URL,
createIdFactory,
DefaultFileReaderFactory,
getNodeVersion,
STANDARD_FONT_DATA_URL,
TEST_PDFS_PATH,
XRefMock,
Expand Down