npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@editneo/pdf

v0.1.3

Published

PDF transmutation engine for EditNeo — converts PDFs into editable blocks

Downloads

415

Readme

@editneo/pdf

Client-side PDF-to-blocks extraction for EditNeo. This package reads a PDF file in the browser, analyzes its text content and layout, and converts it into an array of NeoBlock objects that the editor can render and edit.

All processing happens locally — no files are uploaded to any server.

Installation

npm install @editneo/pdf @editneo/core

This package depends on pdfjs-dist for PDF parsing. The pdf.js worker is auto-configured from CDN.

Usage

import { extractBlocksFromPdf } from "@editneo/pdf";

// Get the PDF as an ArrayBuffer (from a file input, drag-and-drop, fetch, etc.)
const file = event.dataTransfer.files[0];
const buffer = await file.arrayBuffer();

const blocks = await extractBlocksFromPdf(buffer);
// blocks: NeoBlock[]

Each returned block has a type inferred from the PDF content (paragraphs, headings, images) and contains the extracted text as spans.

With the React drop zone

The PDFDropZone component from @editneo/react calls this function automatically when a user drops a PDF onto the editor:

import { PDFDropZone } from "@editneo/react";

<PDFDropZone>{/* editor content */}</PDFDropZone>;

Error handling

The function provides clear error messages for common failures:

try {
  const blocks = await extractBlocksFromPdf(buffer);
} catch (err) {
  // Possible errors:
  // "[EditNeo PDF] Cannot extract blocks: empty or missing PDF data"
  // "[EditNeo PDF] This PDF is password-protected. Please provide an unlocked file."
  // "[EditNeo PDF] Failed to load PDF: <reason>"
  console.error(err.message);
}

Per-page errors are caught individually — one corrupted page won't prevent the rest from extracting.

How Extraction Works

The extraction processes each page of the PDF in order and applies heuristics to convert raw PDF content into structured blocks.

Text extraction

PDF files don't have a concept of "paragraphs" or "headings" — they store positioned text fragments with font metadata. The extractor groups these fragments into blocks using vertical position gaps (>5 PDF units between lines starts a new block).

Heading detection

Headings are classified using multiple signals:

  • Font size ratio — text significantly larger than the page's most common font size
    • >1.8× → heading-1
    • >1.4× → heading-2
    • >1.15× (if bold or all-caps) → heading-3
  • Bold font name — fonts with "Bold", "Heavy", or "Black" in the name
  • Line length — headings are typically shorter than 120 characters
  • All-caps — uppercase text at normal size with a bold font → heading-3

Image extraction

The extractor scans each page's operator list for PaintImageXObject operations. When found, the raw pixel data is read and converted to a PNG data URI via canvas. Small decorative images (<50×50px) are filtered out. In SSR environments where document.createElement isn't available, a placeholder is used instead.

Limitations

  • Multi-column layouts — text from different columns may be merged or ordered incorrectly
  • Tables — table content is extracted as plain text, not as a structured table block
  • Footnotes and headers/footers — these are extracted as regular text blocks
  • Scanned PDFs — if the PDF contains only images (no text layer), the extractor produces only image blocks. OCR is not performed.

API Reference

extractBlocksFromPdf(data)

| Parameter | Type | Description | | --------- | ------------- | --------------------- | | data | ArrayBuffer | The raw PDF file data |

Returns: Promise<NeoBlock[]>

Throws: Error with descriptive message on failure (empty data, password-protected, corrupt file).

An array of NeoBlock objects in reading order. Each block has:

  • A generated UUID as its id
  • A type inferred from the content (paragraph, heading-1, heading-2, heading-3, or image)
  • A content array with a single Span containing the extracted text
  • Image blocks include props.src (data URI), props.width, and props.height
  • createdAt and updatedAt timestamps set to the extraction time

Example output

Given a PDF with a title, some body text, and an image, the function might return:

[
  {
    id: "a1b2c3...",
    type: "heading-1",
    content: [{ text: "Introduction to EditNeo" }],
    props: {},
    children: [],
    parentId: null,
    createdAt: 1707840000000,
    updatedAt: 1707840000000,
  },
  {
    id: "d4e5f6...",
    type: "paragraph",
    content: [{ text: "EditNeo is a modular block-based editor..." }],
    props: {},
    children: [],
    parentId: null,
    createdAt: 1707840000000,
    updatedAt: 1707840000000,
  },
  {
    id: "g7h8i9...",
    type: "image",
    content: [{ text: "" }],
    props: { src: "data:image/png;base64,...", width: 640, height: 480 },
    children: [],
    parentId: null,
    createdAt: 1707840000000,
    updatedAt: 1707840000000,
  },
];

License

MIT