Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdf2json

Package Overview
Dependencies
Maintainers
1
Versions
107
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.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
169K
increased by11.39%
Maintainers
1
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

FAQs

Package last updated on 09 Aug 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc