Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The pdf-parse npm package is a simple and effective tool for extracting text and metadata from PDF files. It can be used to parse PDF files and retrieve their content in a structured format, making it useful for various applications such as data extraction, text analysis, and document processing.
Extract Text from PDF
This feature allows you to extract the text content from a PDF file. The code sample reads a PDF file from the filesystem and uses the pdf-parse package to extract and print the text content.
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('example.pdf');
pdf(dataBuffer).then(function(data) {
console.log(data.text); // Print the text content of the PDF
});
Extract Metadata from PDF
This feature allows you to extract metadata from a PDF file. The code sample reads a PDF file from the filesystem and uses the pdf-parse package to extract and print the metadata information such as title, author, and creation date.
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('example.pdf');
pdf(dataBuffer).then(function(data) {
console.log(data.info); // Print the metadata of the PDF
});
Extract Text and Metadata from PDF
This feature allows you to extract both text content and metadata from a PDF file. The code sample reads a PDF file from the filesystem and uses the pdf-parse package to extract and print both the text content and metadata information.
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('example.pdf');
pdf(dataBuffer).then(function(data) {
console.log(data.text); // Print the text content of the PDF
console.log(data.info); // Print the metadata of the PDF
});
pdf-lib is a library for creating and modifying PDF documents in JavaScript. Unlike pdf-parse, which focuses on extracting text and metadata, pdf-lib provides more comprehensive functionality for creating, editing, and manipulating PDF files.
pdfjs-dist is a distribution of the PDF.js library, which is a powerful tool for rendering PDF documents in web applications. While pdf-parse is used for extracting text and metadata, pdfjs-dist is primarily used for rendering PDFs in the browser and provides a more interactive experience.
pdf2json is a node.js module that parses PDF files and converts them into JSON format. It provides similar functionality to pdf-parse in terms of extracting text and metadata, but it outputs the data in a structured JSON format, which can be more convenient for certain applications.
Pure javascript cross-platform module to extract texts from PDFs.
npm install pdf-parse
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('path to PDF file...');
pdf(dataBuffer).then(function(data) {
// number of pages
console.log(data.numpages);
// number of rendered pages
console.log(data.numrender);
// PDF info
console.log(data.info);
// PDF metadata
console.log(data.metadata);
// PDF.js version
// check https://mozilla.github.io/pdf.js/getting_started/
console.log(data.version);
// PDF text
console.log(data.text);
});
You can use crawler-request which uses the pdf-parse
const fs = require('fs');
const pdf = require('pdf-parse');
let dataBuffer = fs.readFileSync('path to PDF file...');
pdf(dataBuffer).then(function(data) {
// use data
})
.catch(function(error){
// handle exceptions
})
// default render callback
function render_page(pageData) {
//check documents https://mozilla.github.io/pdf.js/
let render_options = {
//replaces all occurrences of whitespace with standard spaces (0x20). The default value is `false`.
normalizeWhitespace: false,
//do not attempt to combine same line TextItem's. The default value is `false`.
disableCombineTextItems: false
}
return pageData.getTextContent(render_options)
.then(function(textContent) {
let lastY, text = '';
for (let item of textContent.items) {
if (lastY == item.transform[5] || !lastY){
text += item.str;
}
else{
text += '\n' + item.str;
}
lastY = item.transform[5];
}
return text;
});
}
let options = {
pagerender: render_page
}
let dataBuffer = fs.readFileSync('path to PDF file...');
pdf(dataBuffer,options).then(function(data) {
//use new format
});
const DEFAULT_OPTIONS = {
// internal page parser callback
// you can set this option, if you need another format except raw text
pagerender: render_page,
// max page number to parse
max: 0,
//check https://mozilla.github.io/pdf.js/getting_started/
version: 'v1.10.100'
}
If you need another format except raw text.
Max number of page to parse. If the value is less than or equal to 0, parser renders all pages.
check pdf.js
'default'
'v1.9.426'
'v1.10.100'
'v1.10.88'
'v2.0.550'
default uses version v1.10.100
mozilla.github.io/pdf.js
mocha
or npm test
I use this package actively myself, so it has my top priority. You can chat on WhatsApp about any infos, ideas and suggestions.
If you find a bug or a mistake, you can help by submitting an issue to GitLab Repository
GitLab calls it merge request instead of pull request.
MIT licensed and all it's dependencies are MIT or BSD licensed.
FAQs
Pure javascript cross-platform module to extract text from PDFs.
The npm package pdf-parse receives a total of 599,532 weekly downloads. As such, pdf-parse popularity was classified as popular.
We found that pdf-parse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.