Skip to content

Commit 287188b

Browse files
committed
New API
1 parent 0d13f78 commit 287188b

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ var spindrift = require('spindrift');
99

1010
// Use and chain any of these commands...
1111
var pdf = spindrift('in.pdf')
12-
.pages(7, 24)
13-
.page(1)
14-
.even()
15-
.odd()
16-
.rotate(90)
12+
.pages(4, 5, 6, 1, 12) // select or reorder individual pages
13+
.range(1, 10) // pages 1-10
14+
.even() // select even pages
15+
.odd() // select odd pages
16+
.rotate(90) // 90, 180, 270, 360
1717
.compress()
1818
.uncompress()
19-
.crop(100, 100, 300, 200) // left, bottom, right, top
19+
.crop(100, 100, 300, 200) // offset in points from left, bottom, right, top
2020

2121
// Join multiple files...
2222
var pdfA = spindrift('1.pdf'), pdfB = spindrift('2.pdf'), pdfC = spindrift('3.pdf')
@@ -43,15 +43,4 @@ pdf.extractImageStream(0)
4343

4444
* Install [PDFTK (http://www.pdflabs.com/docs/install-pdftk/)](http://www.pdflabs.com/docs/install-pdftk/) on your system.
4545
* Ensure you have Ghostscript installed (check by running `gs --version`).
46-
* *(optional)* To extract individual images from a page, install `pdfimages` with `brew install xpdf` or `apt-get install poppler-utils`.
47-
48-
## References
49-
50-
* http://hzqtc.github.com/2012/04/pdf-tools-merging-extracting-and-cropping.html
51-
* http://documentcloud.github.com/docsplit/
52-
* http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
53-
* http://segfault.in/2010/07/pdf-manipulations-and-conversions-from-linux-command-prompt/
54-
* http://www.maths.ox.ac.uk/help/faqs/files/manipulating-pdf-files
55-
* http://stackoverflow.com/questions/11754556/ghostscript-convert-a-pdf-and-output-in-a-textfile
56-
* http://right-sock.net/linux/better-convert-pdf-to-jpg-using-ghost-script/
57-
* http://stackoverflow.com/questions/12484353/how-to-crop-a-section-of-a-pdf-file-to-png-using-ghostscript?lq=1
46+
* *(optional)* To extract individual images from a page, install `pdfimages` with `brew install xpdf` or `apt-get install poppler-utils`.

example/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs');
22
var spindrift = require('..');
33

44
var pdf = spindrift(__dirname + '/test.pdf');
5-
var page = pdf.page(2);
5+
var page = pdf.pages(2);
66

77
// Streams
88
page.pdfStream().pipe(fs.createWriteStream(__dirname + '/test-page.pdf'));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spindrift",
3-
"version": "0.0.6",
3+
"version": "0.1.0",
44
"description": "PDF manipulation in Node.js! Split, join, crop, read, extract, boil, mash, stick them in a stew. ",
55
"main": "spindrift.js",
66
"dependencies": {

spindrift.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Command.prototype._input = function () {
7878

7979
// Cloning commands.
8080

81-
Command.prototype.pages = function (min, max) {
81+
Command.prototype.range = function (min, max) {
8282
var cmd = this._copy();
8383
return cmd._push([
8484
'pdftk', cmd._input(),
@@ -87,8 +87,14 @@ Command.prototype.pages = function (min, max) {
8787
]);
8888
};
8989

90-
Command.prototype.page = function (page) {
91-
return this.pages(page, page);
90+
Command.prototype.pages = function () {
91+
var args = Array.prototype.slice.call(arguments);
92+
var cmd = this._copy();
93+
return cmd._push([
94+
'pdftk', cmd._input(),
95+
'cat'].concat(args.map(Number), [
96+
'output', '-'
97+
]));
9298
};
9399

94100
Command.prototype.odd = function (min, max) {
@@ -396,4 +402,21 @@ spindrift.join = function () {
396402
return pdf;
397403
}
398404

399-
module.exports = spindrift;
405+
module.exports = spindrift;
406+
407+
/*
408+
409+
references
410+
411+
## References
412+
413+
* http://hzqtc.github.com/2012/04/pdf-tools-merging-extracting-and-cropping.html
414+
* http://documentcloud.github.com/docsplit/
415+
* http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
416+
* http://segfault.in/2010/07/pdf-manipulations-and-conversions-from-linux-command-prompt/
417+
* http://www.maths.ox.ac.uk/help/faqs/files/manipulating-pdf-files
418+
* http://stackoverflow.com/questions/11754556/ghostscript-convert-a-pdf-and-output-in-a-textfile
419+
* http://right-sock.net/linux/better-convert-pdf-to-jpg-using-ghost-script/
420+
* http://stackoverflow.com/questions/12484353/how-to-crop-a-section-of-a-pdf-file-to-png-using-ghostscript?lq=1
421+
422+
*/

0 commit comments

Comments
 (0)