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.
pdfjs-dist
Advanced tools
The pdfjs-dist package is a pre-built version of the PDF.js library, which is a general-purpose, web standards-based platform for parsing and rendering PDFs. It allows you to display PDF files in your web pages without the need for a native PDF reader. The package provides a wide range of features including, but not limited to, rendering PDFs, reading PDF metadata, and interacting with PDF content programmatically.
Rendering PDF pages to a canvas element
This code sample demonstrates how to render the first page of a PDF to a canvas element in the browser. It uses the getDocument method to load the PDF and the getPage method to access a specific page, then renders it to the provided canvas context.
const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js');
async function renderPage(url, canvasContext) {
const pdf = await pdfjsLib.getDocument(url).promise;
const page = await pdf.getPage(1);
const viewport = page.getViewport({ scale: 1.5 });
const renderContext = {
canvasContext: canvasContext,
viewport: viewport
};
await page.render(renderContext).promise;
}
Extracting text from a PDF page
This code sample shows how to extract text content from the first page of a PDF. It retrieves the text items from the page and then maps them to strings, joining them to form the full text content of the page.
const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js');
async function extractTextFromPage(url) {
const pdf = await pdfjsLib.getDocument(url).promise;
const page = await pdf.getPage(1);
const textContent = await page.getTextContent();
return textContent.items.map(item => item.str).join(' ');
}
pdf-parse is a package that provides functionality to extract text from PDF files. It is similar to pdfjs-dist in its text extraction capabilities but does not include the ability to render PDFs to a canvas element.
pdf-lib is a package that allows you to create, modify, and sign PDF documents in any JavaScript environment. While pdfjs-dist focuses on rendering and reading PDFs, pdf-lib provides more features for manipulating PDF files, such as adding pages, drawing shapes, and inserting images.
PDF.js is a Portable Document Format (PDF) library that is built with HTML5. Our goal is to create a general-purpose, web standards-based platform for parsing and rendering PDFs.
This is a pre-built version of the PDF.js source code. It is automatically generated by the build scripts.
For usage with older browsers/environments, without native support for the
latest JavaScript features, please see the legacy/
folder.
Please see this wiki page for information about supported browsers/environments.
See https://github.com/mozilla/pdf.js for learning and contributing.
FAQs
Generic build of Mozilla's PDF.js library.
We found that pdfjs-dist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.