A pdf splitter based on node-pdftk
npm install @vtfk/pdf-splitterMake sure you have PDFtk installed. Save the path to the executable as an environment variable "PDFTK_EXT".
For example in .env
```
PDFTK_EXT="
`bash`
$ npm install @vtfk/pdf-splitter
| Description | Value |
| -------- | -------- |
| Page one and three as separate documents | ['1', '3'] |
| Page one to four (inclusive) as doc and page three, six, and eight to ten (inclusive) as doc | ['1-4', '3 6 8-10'] |
`javascript
const splitPdf = require('@vtfk/pdf-splitter')
const pdfToSplit = {
pdfPath: 'a pdf.pdf',
ranges: ['1-4', '3 6 8-10', '4 2'],
outputDir: 'path/to/outputDirectory', // Optional, defaults to directory of the input pdf
outputName: 'nameForResultingPdfs' // Optional, defaults to the
}
const result = await splitPdf(pdfToSplit)
console.log(result)
`
NOTE: At least one keyword or sentence must be unique for the document
`javascript
const splitPdf = require('@vtfk/pdf-splitter')
const pdfToSplit = {
pdfPath: 'a pdf.pdf',
keywords: ['a unique sentence for the page you want to split on', 'word', 'another'],
outputDir: 'path/to/outputDirectory', // Optional, defaults to directory of the input pdf
outputName: 'nameForResultingPdfs' // Optional, defaults to the
}
const result = await splitPdf(pdfToSplit)
console.log(result)
`$3
options.onlyPagesWithKeywords
Only return the pages where the keywords are present as separate documents
`javascript
const splitPdf = require('@vtfk/pdf-splitter')
const pdfToSplit = {
pdfPath: 'a pdf.pdf',
keywords: ['a unique sentence for the page you want to split on', 'word', 'another'],
outputDir: 'path/to/outputDirectory', // Optional, defaults to directory of the input pdf
outputName: 'nameForResultingPdfs', // Optional, defaults to the
onlyPagesWithKeywords: true
}
const result = await splitPdf(pdfToSplit)
console.log(result)
``
options.orKeywords
Only require ONE of the keywords to be present on the page, for it to split on that pagejavascript
const splitPdf = require('@vtfk/pdf-splitter')
const pdfToSplit = {
pdfPath: 'a pdf.pdf',
keywords: ['a unique sentence for the page you want to split on', 'word', 'another'], // will split if one of these are present on the page
outputDir: 'path/to/outputDirectory', // Optional, defaults to directory of the input pdf
outputName: 'nameForResultingPdfs', // Optional, defaults to the
orKeywords: true // Optional, defaults to false
}
const result = await splitPdf(pdfToSplit)
console.log(result)
``