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

added ignore warnings flags #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-qpdf2",
"version": "6.1.0",
"version": "6.2.0",
"description": "A Content Preserving transformations on PDFs wrapped around QPDF",
"keywords": [
"pdf",
Expand Down
11 changes: 10 additions & 1 deletion src/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const EncryptDefaults = {
type BaseYesNoOptions = "n" | "y";
type BasePrintOptions = "full" | "low" | "none";
interface BaseEncryptOptions {
/**
* If defined, will ignore warnings from qpdf
*/
ignoreWarnings?: boolean;
/** The location of the unencrypted pdf file */
input: string;
/** If defined, the output location of the encrypted pdf. If not defined, a Buffer will be returned. */
Expand Down Expand Up @@ -98,6 +102,11 @@ export const encrypt = async (userPayload: EncryptOptions): Promise<Buffer> => {
// This is required for qpdf 11+.
if (payload.keyLength === 40) callArguments.push("--allow-weak-crypto");

// Add Ignore warning flags
if (payload.ignoreWarnings) {
callArguments.push("--no-warn", "--warning-exit-0");
}

callArguments.push("--encrypt");

// Set user-password and owner-password
Expand Down Expand Up @@ -140,7 +149,7 @@ export const encrypt = async (userPayload: EncryptOptions): Promise<Buffer> => {
}
}
}

// Marks end of --encrypt options, Input file path
callArguments.push("--", payload.input);

Expand Down
17 changes: 17 additions & 0 deletions test/encrypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ test("Should encrypt and overwrite the file", async () => {
}),
).resolves.toBeTruthy();
});

test("should throw warnings", async () => {
await expect(
encrypt({
input: "test/example-warning.pdf",
}),
).rejects.toBeTruthy();
});

test("should encrypt without warnings", async () => {
await expect(
encrypt({
ignoreWarnings: true,
input: "test/example-warning.pdf",
}),
).resolves.toBeTruthy();
});
Binary file added test/example-warning.pdf
Binary file not shown.