Overview

Two packages that turn PDFs and webpages into clean, structured HTML, in Node, the browser and Cloudflare Workers.

When people hand a research tool a document, they expect an answer at once, not after minutes of OCR. These two packages are built around that:

PackageInputOutput
extract-pdfA PDF URL or ArrayBufferStructured HTML (headings, lists, footnotes, code and quote blocks, Table of Contents links), the title and author, and a per-page scan of which pages would benefit from OCR.
extract-webpageA URL, an HTML string, a DOM document, or a DOCX bufferThe main content as basic HTML, plus title, author, date, publisher, an APA-style citation and a word count.

extract-webpage uses extract-pdf itself: a URL that turns out to be a PDF is converted by it.

Install

npm i extract-pdf extract-webpage
# or
bun add extract-pdf extract-webpage

A first call

import { convertPDFToHTML } from 'extract-pdf';
import { extractContent } from 'extract-webpage';

const pdf = await convertPDFToHTML('https://arxiv.org/pdf/1706.03762');
const page = await extractContent('https://en.wikipedia.org/wiki/Web_scraping');

console.log(pdf.title, pdf.ocrScan.pagesNeedingOcr);
console.log(page.cite, page.word_count);

Where to go next

On this page