Skip to content

Commit

Permalink
Merge pull request #18 from jjwilly16/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
jjwilly16 authored Aug 4, 2018
2 parents 2db0d50 + 84be116 commit a5d930c
Show file tree
Hide file tree
Showing 23 changed files with 1,774 additions and 448 deletions.
15 changes: 9 additions & 6 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ rules:

# Should only have parentheses if arrow function has more than 1 argument
arrow-parens:
- warn
- error
- as-needed

# Expects commas after functions
comma-dangle:
- warn
- error
- arrays: always
objects: always
imports: never
Expand Down Expand Up @@ -57,6 +57,9 @@ rules:
# allow ~~
no-bitwise: 0

# allow old buffer constructor
no-buffer-constructor: 0

# console is allowed
no-console: 0

Expand All @@ -74,7 +77,7 @@ rules:

# allow multiple lines greater than 2
no-multiple-empty-lines:
- warn
- error
- max: 2
maxEOF: 1

Expand All @@ -101,7 +104,7 @@ rules:

# no unused vars, except for function arguments
no-unused-vars:
- warn
- error
- args: none

# functions are allowed to be hoisted
Expand All @@ -121,9 +124,9 @@ rules:
# arrow functions are not always necessary
prefer-arrow-callback: 0

# when using let instead of const and no reassignment, only give a warning, no error
# when using let instead of const and no reassignment, only give a erroring, no error
prefer-const:
- warn
- error

# prefer using `hello, ${name}` vs 'hello, ' + name
prefer-template: 0
Expand Down
60 changes: 49 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

A wrapper for [PDFtk](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) with streams and promises. All methods included.

> **2.0 Note** - If you are planning on upgrading from version 1, you shouldn't have any problems unless you are subclassing the PdfTk class - it is no longer being directly exposed. All methods should behave the same as before.
## Requirements ##

Make sure you have [PDFtk](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) installed and in your system path.
Make sure you have [PDFtk](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) installed and in your system path (or configure the plugin to point to your binary file - see options below).

> **Mac users** - Be aware of [this PDFTk issue](https://github.com/jjwilly16/node-pdftk/issues/3)
Expand All @@ -22,7 +24,7 @@ const pdftk = require('node-pdftk');

## Usage ##

> Fill a form
#### Fill a form ####

```javascript
pdftk
Expand All @@ -42,7 +44,7 @@ pdftk
});
```

> Catenate pages
#### Concatenate pages ####

```javascript
pdftk
Expand All @@ -60,7 +62,7 @@ pdftk
});
```

> Stamp page
#### Stamp page ####

```javascript
pdftk
Expand All @@ -75,6 +77,36 @@ pdftk
});
```

## Options ##

Options can be configured with the **configure** method. These options will be inherited by all instances.

```javascript
const pdftk = require('node-pdftk');

pdftk.configure({
bin: '/your/path/to/pdftk/bin',
Promise: require('bluebird'),
ignoreWarnings: true,
});
```

---
Name | Description | Type | Default Value
--- | --- | --- | ---
bin | Path to your PdfTk executable | String | 'pdftk'
Promise | Promise library to implement | Object | Promise
ignoreWarnings | Ignore PdfTk warnings. Useful with huge PDF files | Boolean | False

## Configuring your PdfTk path ##

If you need to configure a path to your PdfTk executable, you have a couple of options:

1. Set the **bin** option with the **configure** method (see the **options** section above).
2. Set an environmental variable named **PDFTK_PATH**.

The **bin** option takes precedence over everything, followed by the environmental variable, and will fall back to 'pdftk' if those are not set.

## How it works ##

All instances must begin with the **.input** method and end with the **.output** method.
Expand All @@ -83,13 +115,13 @@ The **.input** method will accept a buffer, file path, or an array of buffer/fil

Any method called after input will simply add on commands. There is a certain amount of responsibility in the user's hands to make sure the commands will work properly in the order you call them. For example, you cannot call *.fillForm().stamp()*. Read the [PDFtk docs](https://www.pdflabs.com/docs/pdftk-man-page/) to learn more.

The **.output** method simply executes the command and spits out the stdout either as a buffer or to a file.
The **.output** method simply executes the command and returns a promise that resolves the stdout as a buffer (you can also write to disk as well with a file path argument).

- **Note:** - The output method is not needed for all methods (e.g. burst, unpackFiles)
- **Note:** - The output method is not needed for all methods (e.g. burst, unpackFiles) - it is internally called with those.

## More Examples ##

> Express example - render directly in browser
#### Express example - render directly in browser ####

```javascript
app.get('./file.pdf', (req, res, next) => {
Expand All @@ -106,7 +138,7 @@ app.get('./file.pdf', (req, res, next) => {
});
```

> Input a buffer, output a file and a buffer
#### Input a buffer, output a file and a buffer ####

```javascript
pdftk
Expand All @@ -120,7 +152,7 @@ pdftk
});
```

> Useful chaining
#### Useful chaining ####

```javascript
pdftk
Expand All @@ -144,9 +176,9 @@ pdftk

## Testing ##

> The tests are a work in progress
> The tests are a work in progress (feel free to submit pull requests)
Because of the small differences with pdfs being generated across OS platforms, some of the test files are generated in the npm 'pretest' script with pdftk. If you have some sort of special setup where your pdftk path is not standard, you will want to edit that script in package.json.
Because of the small differences with pdfs being generated across OS platforms, a lot of the test files are generated in the npm 'pretest' script with pdftk. If you have some sort of special setup where your pdftk path is not standard, you will want to edit that script in [pretest.js](./pretest.js) (it does check for the **PDFTK_PATH** environmental variable, though).

Run tests with:

Expand All @@ -159,3 +191,9 @@ Test coverage with:
```bash
npm run coverage
```

## Contributing ##

If you feel the library could be improved in any way, feel free to submit a pull request. I'm pretty laid back so I don't expect much, but all I ask is that you run the tests to make sure everything is kosher (my eslint rules may bite you in the ass there).

Please keep in mind that this library is just a wrapper for something else, so try to avoid extending the functionality beyond what it is intended to do.
Loading

0 comments on commit a5d930c

Please sign in to comment.