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

@mlightcad/cad-pdf-plugin

v1.5.5

Published

PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers two system commands:

Readme

@mlightcad/cad-pdf-plugin

PDF export and import plugin for @mlightcad/cad-simple-viewer. Registers two system commands:

| Command | Description | |---------|-------------| | cpdf | Export the current drawing to a vector PDF (SVG pipeline → jsPDF) | | ipdf | Import vector geometry from a PDF file into model space |

The plugin is designed for lazy loading so PDF libraries (jspdf, pdfjs-dist, svg2pdf.js) are only downloaded when a user runs cpdf or ipdf.

Key features

  • Vector PDF export — renders model-space entities via @mlightcad/cad-svg-plugin, then converts SVG to PDF with svg2pdf.js
  • PDF import — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
  • Plugin API — implements AcApPlugin; register once with registerLazyPdfPlugin
  • Framework-agnostic — no Vue/React dependency; works anywhere cad-simple-viewer runs

Installation

pnpm add @mlightcad/cad-pdf-plugin

Peer dependencies:

  • @mlightcad/cad-simple-viewer
  • @mlightcad/data-model
  • @mlightcad/cad-svg-plugin

Runtime dependencies (bundled with this package):

  • jspdf
  • pdfjs-dist
  • svg2pdf.js

Build

pnpm --filter @mlightcad/cad-pdf-plugin build

Usage

Lazy registration (recommended)

Register the plugin with the document manager's plugin manager. The module chunk loads on first use of cpdf or ipdf:

import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
import { registerLazyPdfPlugin } from '@mlightcad/cad-pdf-plugin'

registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)

Equivalent manual registration:

import {
  createPdfPlugin,
  PDF_PLUGIN_NAME,
  PDF_PLUGIN_TRIGGERS
} from '@mlightcad/cad-pdf-plugin'

AcApDocManager.instance.pluginManager.registerLazyPlugin({
  name: PDF_PLUGIN_NAME,
  triggers: [...PDF_PLUGIN_TRIGGERS],
  loader: createPdfPlugin
})

After registration, users (or your UI) invoke commands through the editor:

// Export current drawing to PDF
await AcApDocManager.instance.editor.executeCommand('cpdf')

// Open file picker and import PDF vectors
await AcApDocManager.instance.editor.executeCommand('ipdf')

cad-viewer registers this plugin automatically via registerLazyPlugins() in its app bootstrap.

Eager registration

If you prefer loading PDF support up front:

import { AcApPdfPlugin } from '@mlightcad/cad-pdf-plugin'

await AcApDocManager.instance.pluginManager.loadPlugin(new AcApPdfPlugin())

Programmatic convertors

You can bypass the command layer and call the convertors directly:

import { AcApContext } from '@mlightcad/cad-simple-viewer'
import { AcApPdfConvertor, AcApPdfImportConvertor } from '@mlightcad/cad-pdf-plugin'

// Export
const context: AcApContext = /* active context */
await new AcApPdfConvertor().convert(context)

// Import from bytes
const buffer: ArrayBuffer = /* PDF file */
await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1

How it works

Export (cpdf)

  1. Iterate model-space entities and render with AcSvgRenderer (respects linetype scale, lineweight display, font mapping, background/foreground colors).
  2. Parse the SVG and pass it to svg2pdf.js inside a jsPDF document sized to the SVG viewBox.
  3. Trigger a browser download as drawing.pdf.

Import (ipdf)

  1. Show a native file picker (.pdf).
  2. Use pdfjs-dist to read operator lists from the selected page.
  3. Convert path operators (move, line, cubic Bézier, close) into AcDbLine / AcDbPolyline entities in model space.

Import is vector-only; raster/scanned PDF pages produce no entities. Only the requested page is processed (default: page 1).

Main exports

| Export | Role | |--------|------| | registerLazyPdfPlugin | One-line lazy registration helper | | createPdfPlugin | Async factory used by lazy loader | | PDF_PLUGIN_NAME, PDF_PLUGIN_TRIGGERS | Plugin id and command triggers | | AcApPdfPlugin | AcApPlugin implementation | | AcApConvertToPdfCmd | cpdf command class | | AcApImportPdfCmd | ipdf command class | | AcApPdfConvertor | SVG → PDF export utility | | AcApPdfImportConvertor | PDF → CAD entities import utility |

Project layout

| Path | Role | |------|------| | src/registerLazyPdfPlugin.ts | Lazy plugin registration API | | src/AcApPdfPlugin.ts | Plugin lifecycle (onLoad / onUnload) | | src/AcApConvertToPdfCmd.ts | cpdf command | | src/AcApImportPdfCmd.ts | ipdf command | | src/AcApPdfConvertor.ts | Export pipeline (SVG renderer + jsPDF) | | src/AcApPdfImportConvertor.ts | Import pipeline (pdf.js operator parsing) |

Role in MLightCAD

This package extends cad-simple-viewer with optional PDF I/O. It depends on cad-svg-plugin for export quality parity with the existing SVG export command (csvg) and keeps heavy PDF dependencies out of the core viewer bundle through lazy loading.

License

MIT