🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@vtfk/pdf-splitter

Package Overview
Dependencies
Maintainers
7
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vtfk/pdf-splitter

A pdf splitter based on node-pdftk

Source
npmnpm
Version
1.0.4
Version published
Maintainers
7
Created
Source

pdf-splitter

NodeJS package for splitting pdfs, based on given ranges or keywords. Uses PDFtk and node-pdftk for splitting, and PDF.js for pdf-text-reading

Requirements

Make sure you have PDFtk installed. Save the path to the executable as an environment variable "PDFTK_EXT".

For example in .env

PDFTK_EXT="<installationPath>/PDFtk/bin/pdftk"

Installing

$ npm install @vtfk/pdf-splitter

Usage

With array of page-ranges

Specify which pages you want to split into new documents

DescriptionValue
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']
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 <NameOfPdf>-<index>.pdf
}

const result = await splitPdf(pdfToSplit)
console.log(result)

With array of keywords/sentences

Specify on which keywords/sentences you want to split the document on

NOTE: At least one keyword or sentence must be unique for the document

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 <NameOfPdf>-<index>.pdf
}

const result = await splitPdf(pdfToSplit)
console.log(result)

Options

Only return the pages where the keywords are present as separate documents

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 <NameOfPdf>-<index>.pdf
    onlyPagesWithKeywords: true
}

const result = await splitPdf(pdfToSplit)
console.log(result)

Keywords

pdf

FAQs

Package last updated on 30 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts