Skip to content
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
4 changes: 3 additions & 1 deletion src/core/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { bytesToString, info, warn } from "../shared/util.js";
import { Dict, isName, Name, Ref } from "./primitives.js";
import { Dict, isDict, isName, Name, Ref } from "./primitives.js";
import {
escapePDFName,
escapeString,
Expand Down Expand Up @@ -117,6 +117,8 @@ async function writeStream(stream, buffer, transform) {
!isFilterZeroCompressedObject &&
// /Crypt must come first (ISO 32000-1, 7.4.10).
!cryptFilterName &&
// Preserve plaintext metadata (ISO 32000-1, 14.3.2, note 2).
!isDict(dict, "Metadata") &&
bytes.length >= MIN_LENGTH_FOR_COMPRESSING
) {
try {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/writer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ describe("Writer", function () {
);
}
});

it("should not compress a metadata stream", async function () {
// Above the compression threshold.
const string = "a".repeat(300);
const stream = new StringStream(string, new Dict());
stream.dict.setIfName("Type", "Metadata");
stream.dict.setIfName("Subtype", "XML");

const buffer = [];
await writeValue(stream, buffer, null);

expect(buffer.join("")).toEqual(
"<< /Type /Metadata /Subtype /XML /Length 300>> stream\n" +
`${string}\nendstream`
);
});
});

describe("XFA", function () {
Expand Down
Loading