Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
feat: allow different paper size options (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
artiebits authored Jan 21, 2023
1 parent a54ba84 commit a5e3b9d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ A function to print a PDF document.
- `monochrome` (`boolean`, Optional): Prints the document in black and white. Default is `false`.
- `side` (`string`, Optional): Supported names `duplex`, `duplexshort`, `duplexlong` and `simplex`.
- `bin` (`string`, Optional): Select tray to print to. Number or name.
- `paperSize` (`string`, Optional): Specifies the paper size. Supported names `A2`, `A3`, `A4`, `A5`, `A6`, `letter`, `legal`, `tabloid`, `statement`.
- `paperSize` (`string`, Optional): Specifies the paper size. `A2`, `A3`, `A4`, `A5`, `A6`, `letter`, `legal`, `tabloid`, `statement`, or a name selectable from your printer settings.
- `silent` (`boolean`, Optional): Silences SumatraPDF's error messages.
- `printDialog` (`boolean`, Optional): displays the Print dialog for all the files indicated on this command line.
- `copies`(`number`, Optional): Specifies how many copies will be printed.
Expand Down
11 changes: 0 additions & 11 deletions src/print/print.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,6 @@ describe("paper size", () => {
);
});
});

it("throws when incorrect paper size provided", () => {
const filename = "assets/sample.pdf";
const options = {
paperSize: "foo",
};

return expect(print(filename, options)).rejects.toBe(
"Invalid paper size provided. Valid names: A2, A3, A4, A5, A6, letter, legal, tabloid, statement"
);
});
});

describe("orientation", () => {
Expand Down
19 changes: 1 addition & 18 deletions src/print/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ const validSubsets = ["odd", "even"];
const validOrientations = ["portrait", "landscape"];
const validScales = ["noscale", "shrink", "fit"];
const validSides = ["duplex", "duplexshort", "duplexlong", "simplex"];
const validPaperSizes = [
"A2",
"A3",
"A4",
"A5",
"A6",
"letter",
"legal",
"tabloid",
"statement",
];

export default async function print(
pdf: string,
Expand Down Expand Up @@ -144,13 +133,7 @@ function getPrintSettings(options: PrintOptions): string[] {
}

if (paperSize) {
if (validPaperSizes.includes(paperSize)) {
printSettings.push(`paper=${paperSize}`);
} else {
throw `Invalid paper size provided. Valid names: ${validPaperSizes.join(
", "
)}`;
}
printSettings.push(`paper=${paperSize}`);
}

if (copies) {
Expand Down

0 comments on commit a5e3b9d

Please sign in to comment.