pdfbooklet 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/package.json +3 -2
  3. package/pdfbooklet.js +10 -14
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ To install
2
+
3
+ ```
4
+ npm i -g pdfbooklet
5
+ ```
6
+
7
+ To use
8
+
9
+ ```
10
+ pdfbooklet <input.pdf>
11
+
12
+ OPTIONS:
13
+ --paper-size (a4|letter), default is letter
14
+ --margin-inset X reduce margin of the original pdf on all sides by X (in inches)
15
+ --margin-inset X,Y reduce margin X on top and bottom, Y on left and right
16
+ --margin-inset X,Y,Z,A reduce margin-top by X, right by Y, bottom by Z, left by A
17
+ ```
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
- "name":"pdfbooklet",
3
- "version": "1.0.0",
2
+ "name": "pdfbooklet",
3
+ "version": "1.0.2",
4
4
  "description": "Create booklet from a pdf file suitable for compact printing",
5
5
  "main": "pdfbooklet.js",
6
6
  "bin": {
7
7
  "pdfbooklet": "pdfbooklet.js"
8
8
  },
9
9
  "files": [
10
+ "README.md",
10
11
  "pdfbooklet.js"
11
12
  ],
12
13
  "scripts": {
package/pdfbooklet.js CHANGED
@@ -27,9 +27,9 @@ pdfbooklet <input.pdf>
27
27
 
28
28
  OPTIONS:
29
29
  --paper-size (a4|letter), default is letter
30
- --margin-insets X reduce margin of the original pdf on all sides by X (in inches)
31
- --margin-insets X,Y reduce margin X on top and bottom, Y on left and right
32
- --margin-insets X,Y,Z,A reduce margin-top by X, right by Y, bottom by Z, left by A
30
+ --margin-inset X reduce margin of the original pdf on all sides by X (in inches)
31
+ --margin-inset X,Y reduce margin X on top and bottom, Y on left and right
32
+ --margin-inset X,Y,Z,A reduce margin-top by X, right by Y, bottom by Z, left by A
33
33
  `)
34
34
  process.exit(msg ? 1 : 0)
35
35
  }
@@ -98,17 +98,13 @@ async function createBooklet(inputPdfPath, outputPdfPath) {
98
98
  const {width, height} = a.size()
99
99
  const w = width - marginInsets.left - marginInsets.right;
100
100
  const h = height - marginInsets.top - marginInsets.bottom;
101
- const xscale = box.width / w;
102
- const yscale = box.height / h;
103
- const scale = xscale < yscale ? xscale : yscale;
104
- const w2 = w * scale;
105
- const h2 = h * scale;
106
-
107
- const dx = -marginInsets.left * scale;
108
- const dy = -marginInsets.top * scale;
101
+ const xScale = box.width / w;
102
+ const yScale = box.height / h;
103
+ const scale = xScale < yScale ? xScale : yScale;
104
+ const x = box.width / 2 + box.x - w * scale / 2;
105
+ const y = box.height / 2 + box.y - h * scale / 2;
109
106
  newPage.drawPage(a, {
110
- x: box.x + (box.width - w2) / 2 + dx,
111
- y: box.y + (box.height - h2) / 2 + dy,
107
+ x, y,
112
108
  xScale: scale,
113
109
  yScale: scale,
114
110
  })
@@ -161,8 +157,8 @@ for (let i = 2; i < process.argv.length; i++) {
161
157
  marginInsets.bottom = insets[0];
162
158
  marginInsets.top = insets[0];
163
159
  } else if (insets.length === 2) {
164
- marginInsets.bottom = insets[0];
165
160
  marginInsets.top = insets[0];
161
+ marginInsets.bottom = insets[0];
166
162
  marginInsets.left = insets[1];
167
163
  marginInsets.right = insets[1];
168
164
  } else if (insets.length === 4) {