-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (35 loc) · 895 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { subprocess, fs } from "@jspawn/jspawn";
import * as util from "apps-util";
export default async function (input) {
let rotate;
switch (input.method) {
case "custom":
rotate = input.rotate.map((x) => {
const relative = x.relative ? "+" : "";
return `--rotate=${relative}${normAngle(x.angle)}:${x.pages}`;
});
break;
case "relative":
rotate = [`--rotate=+${normAngle(input.angle)}:1-z`];
break;
case "fixed":
rotate = [`--rotate=${normAngle(input.angle)}:1-z`];
break;
}
const outPath = util.outPath(input.pdfFile.path, { suffix: "-rotated" });
await subprocess.run("qpdf", [
input.pdfFile.path,
"--pages",
".",
"1-z",
"--",
outPath,
...rotate,
]);
return { rotatedPDF: outPath };
}
function normAngle(deg) {
deg = deg % 360;
if (deg < 0) deg += 360;
return deg;
}