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.7.1

Published

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://img.shields.io/npm/v/@mlightcad/cad-pdf-plugin.svg)](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)

Readme

@mlightcad/cad-pdf-plugin

License: MIT npm version

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

| Command | Description | |---------|-------------| | -cpdf | Export via command-line prompts (no dialog; AutoCAD-style - prefix) | | cpdf | Same as -cpdf when no UI command is registered. In cad-viewer, cpdf opens an export options dialog instead | | ipdf | Import vector geometry from a PDF file into model space |

The plugin is designed for lazy loading so PDF libraries (pdf-lib via @mlightcad/pdf-renderer, pdfjs-dist) are only downloaded when a user runs -cpdf / cpdf or ipdf.

Key features

  • Vector PDF export — renders model space and each paper-space layout as PDF pages with @mlightcad/pdf-renderer (native AcGi PDF backend). Paper-space pages include model content shown through viewports, clipped to each viewport frame.
  • Busy indicator — export shows the same conversion spinner as chtml so the browser stays responsive
  • Export options — model-space framing (Extents / Display) and optional paper-space layouts
  • 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/pdf-renderer

Runtime dependencies (bundled with this package):

  • pdfjs-dist (import only)

Build

Produces dist/index.js (main library) and dist/register.js (lazy-registration entry).

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

Usage

Lazy registration (recommended)

Register the plugin with the document manager's plugin manager. Import from the /register subpath so only the registration stub enters your initial bundle; the main plugin chunk loads on first use of -cpdf, cpdf, or ipdf:

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

registerLazyPdfPlugin(AcApDocManager.instance.pluginManager)

Do not import registerLazyPdfPlugin from the package root in application code — that resolves to the full library build and defeats lazy loading.

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 (command-line prompts)
await AcApDocManager.instance.editor.executeCommand('-cpdf')

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

In cad-viewer, use cpdf to open the export options dialog; -cpdf remains available on the command line for prompt-based export.

cad-viewer registers this plugin automatically via registerLazyPlugins() in its app bootstrap and registers the cpdf dialog command separately.

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,
  resolveAcApPdfExportOptions
} from '@mlightcad/cad-pdf-plugin'

// Export
const context: AcApContext = /* active context */
await new AcApPdfConvertor().convert(
  context,
  resolveAcApPdfExportOptions({
    modelSpaceFit: 'extents',
    exportLayouts: true
  })
)

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

How it works

Export (-cpdf / dialog)

  1. Collect options: model-space framing (Extents / Display) and whether to export layouts.
  2. Show the application busy overlay (same animation pattern as chtml).
  3. Call @mlightcad/pdf-renderer exportDatabaseToPdf. With layouts enabled, model space and every paper space become one PDF page each.
  4. Download the resulting PDF bytes.

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 | |--------|------| | createPdfPlugin | Async factory used by lazy loader | | PDF_PLUGIN_NAME, PDF_PLUGIN_TRIGGERS | Plugin id and command triggers | | @mlightcad/cad-pdf-plugin/register | registerLazyPdfPlugin and registration constants | | AcApPdfPlugin | AcApPlugin implementation | | AcApConvertToPdfCmd | -cpdf / fallback cpdf command class | | AcApImportPdfCmd | ipdf command class | | AcApPdfConvertor | CAD → PDF export utility | | AcApPdfExportOptions, resolveAcApPdfExportOptions | Export option types and defaults | | AcApPdfImportConvertor | PDF → CAD entities import utility |

Project layout

| Path | Role | |------|------| | src/register.ts | Lazy plugin registration (/register entry) and createPdfPlugin | | src/AcApPdfPlugin.ts | Plugin lifecycle (onLoad / onUnload) | | src/AcApConvertToPdfCmd.ts | -cpdf command (command-line prompts) | | src/AcApImportPdfCmd.ts | ipdf command | | src/AcApPdfConvertor.ts | Export pipeline (exportDatabaseToPdf) | | src/AcApPdfExportOptions.ts | Export option types and defaults | | src/AcApPdfImportConvertor.ts | Import pipeline (pdf.js operator parsing) |

Role in MLightCAD

This package extends cad-simple-viewer with optional PDF I/O. Export uses @mlightcad/pdf-renderer; import uses pdfjs-dist. Heavy PDF dependencies stay out of the core viewer bundle through lazy loading.

License

MIT