New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pdf2json

Package Overview
Dependencies
Maintainers
0
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf2json

PDF file parser that converts PDF binaries to JSON and text, powered by porting a fork of PDF.JS to Node.js

3.1.5
latest
Source
npm
Version published
Weekly downloads
144K
-16.19%
Maintainers
0
Weekly downloads
 
Created

What is pdf2json?

The pdf2json npm package is a utility that allows you to convert PDF files into JSON format. This can be particularly useful for extracting and processing data from PDF documents programmatically.

What are pdf2json's main functionalities?

Convert PDF to JSON

This feature allows you to convert a PDF file into a JSON object. The code sample demonstrates how to load a PDF file, parse it, and save the resulting JSON data to a file.

const fs = require('fs');
const PDFParser = require('pdf2json');

let pdfParser = new PDFParser();

pdfParser.on('pdfParser_dataError', errData => console.error(errData.parserError));
pdfParser.on('pdfParser_dataReady', pdfData => {
    fs.writeFile('./output.json', JSON.stringify(pdfData), (err) => {
        if (err) throw err;
        console.log('PDF data has been converted to JSON and saved to output.json');
    });
});

pdfParser.loadPDF('./sample.pdf');

Extract Text from PDF

This feature allows you to extract text content from a PDF file. The code sample demonstrates how to parse a PDF file and extract the text content, then save it to a text file.

const fs = require('fs');
const PDFParser = require('pdf2json');

let pdfParser = new PDFParser();

pdfParser.on('pdfParser_dataError', errData => console.error(errData.parserError));
pdfParser.on('pdfParser_dataReady', pdfData => {
    const text = pdfData.formImage.Pages.map(page => page.Texts.map(text => decodeURIComponent(text.R[0].T)).join(' ')).join('\n');
    fs.writeFile('./output.txt', text, (err) => {
        if (err) throw err;
        console.log('Text has been extracted from PDF and saved to output.txt');
    });
});

pdfParser.loadPDF('./sample.pdf');

Other packages similar to pdf2json

Keywords

pdf

FAQs

Package last updated on 03 Jan 2025

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