@mlightcad/cad-pdf-plugin 1.6.3 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -23
- package/dist/cad-pdf-plugin-register.js +11 -10
- package/dist/cad-pdf-plugin-register.umd.cjs +1 -1
- package/dist/cad-pdf-plugin.js +17050 -41432
- package/dist/cad-pdf-plugin.umd.cjs +13 -270
- package/lib/AcApConvertToPdfCmd.d.ts +13 -2
- package/lib/AcApConvertToPdfCmd.d.ts.map +1 -1
- package/lib/AcApConvertToPdfCmd.js +153 -7
- package/lib/AcApConvertToPdfCmd.js.map +1 -1
- package/lib/AcApPdfConvertor.d.ts +18 -8
- package/lib/AcApPdfConvertor.d.ts.map +1 -1
- package/lib/AcApPdfConvertor.js +87 -94
- package/lib/AcApPdfConvertor.js.map +1 -1
- package/lib/AcApPdfExportOptions.d.ts +38 -0
- package/lib/AcApPdfExportOptions.d.ts.map +1 -0
- package/lib/AcApPdfExportOptions.js +12 -0
- package/lib/AcApPdfExportOptions.js.map +1 -0
- package/lib/AcApPdfFontResolver.d.ts +20 -0
- package/lib/AcApPdfFontResolver.d.ts.map +1 -0
- package/lib/AcApPdfFontResolver.js +105 -0
- package/lib/AcApPdfFontResolver.js.map +1 -0
- package/lib/AcApPdfGlyphProvider.d.ts +15 -0
- package/lib/AcApPdfGlyphProvider.d.ts.map +1 -0
- package/lib/AcApPdfGlyphProvider.js +277 -0
- package/lib/AcApPdfGlyphProvider.js.map +1 -0
- package/lib/AcApPdfPlugin.d.ts +13 -3
- package/lib/AcApPdfPlugin.d.ts.map +1 -1
- package/lib/AcApPdfPlugin.js +19 -7
- package/lib/AcApPdfPlugin.js.map +1 -1
- package/lib/createPdfPlugin.d.ts +3 -2
- package/lib/createPdfPlugin.d.ts.map +1 -1
- package/lib/createPdfPlugin.js +4 -2
- package/lib/createPdfPlugin.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/register.d.ts +7 -3
- package/lib/register.d.ts.map +1 -1
- package/lib/register.js +12 -5
- package/lib/register.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
4
|
[](https://www.npmjs.com/package/@mlightcad/cad-pdf-plugin)
|
|
5
5
|
|
|
6
|
-
PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers
|
|
6
|
+
PDF **export** and **import** plugin for [`@mlightcad/cad-simple-viewer`](../cad-simple-viewer). Registers system commands:
|
|
7
7
|
|
|
8
8
|
| Command | Description |
|
|
9
9
|
|---------|-------------|
|
|
10
|
-
|
|
|
10
|
+
| `-cpdf` | Export via **command-line prompts** (no dialog; AutoCAD-style `-` prefix) |
|
|
11
|
+
| `cpdf` | Same as `-cpdf` when no UI command is registered. In [`cad-viewer`](../cad-viewer), `cpdf` opens an **export options dialog** instead |
|
|
11
12
|
| `ipdf` | Import vector geometry from a PDF file into model space |
|
|
12
13
|
|
|
13
|
-
The plugin is designed for **lazy loading** so PDF libraries (`
|
|
14
|
+
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`.
|
|
14
15
|
|
|
15
16
|
## Key features
|
|
16
17
|
|
|
17
|
-
- **Vector PDF export** — renders model-space
|
|
18
|
+
- **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.
|
|
19
|
+
- **Busy indicator** — export shows the same conversion spinner as `chtml` so the browser stays responsive
|
|
20
|
+
- **Export options** — model-space framing (`Extents` / `Display`) and optional paper-space layouts
|
|
18
21
|
- **PDF import** — parses vector paths from the first page of a PDF (lines, polylines, Bézier curves) and appends CAD entities
|
|
19
22
|
- **Plugin API** — implements `AcApPlugin`; register once with `registerLazyPdfPlugin`
|
|
20
23
|
- **Framework-agnostic** — no Vue/React dependency; works anywhere `cad-simple-viewer` runs
|
|
@@ -29,13 +32,11 @@ Peer dependencies:
|
|
|
29
32
|
|
|
30
33
|
- `@mlightcad/cad-simple-viewer`
|
|
31
34
|
- `@mlightcad/data-model`
|
|
32
|
-
- `@mlightcad/
|
|
35
|
+
- `@mlightcad/pdf-renderer`
|
|
33
36
|
|
|
34
37
|
Runtime dependencies (bundled with this package):
|
|
35
38
|
|
|
36
|
-
- `
|
|
37
|
-
- `pdfjs-dist`
|
|
38
|
-
- `svg2pdf.js`
|
|
39
|
+
- `pdfjs-dist` (import only)
|
|
39
40
|
|
|
40
41
|
## Build
|
|
41
42
|
|
|
@@ -49,7 +50,7 @@ pnpm --filter @mlightcad/cad-pdf-plugin build
|
|
|
49
50
|
|
|
50
51
|
### Lazy registration (recommended)
|
|
51
52
|
|
|
52
|
-
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
|
|
53
|
+
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`:
|
|
53
54
|
|
|
54
55
|
```typescript
|
|
55
56
|
import { AcApDocManager } from '@mlightcad/cad-simple-viewer'
|
|
@@ -79,14 +80,16 @@ AcApDocManager.instance.pluginManager.registerLazyPlugin({
|
|
|
79
80
|
After registration, users (or your UI) invoke commands through the editor:
|
|
80
81
|
|
|
81
82
|
```typescript
|
|
82
|
-
// Export current drawing to PDF
|
|
83
|
-
await AcApDocManager.instance.editor.executeCommand('cpdf')
|
|
83
|
+
// Export current drawing to PDF (command-line prompts)
|
|
84
|
+
await AcApDocManager.instance.editor.executeCommand('-cpdf')
|
|
84
85
|
|
|
85
86
|
// Open file picker and import PDF vectors
|
|
86
87
|
await AcApDocManager.instance.editor.executeCommand('ipdf')
|
|
87
88
|
```
|
|
88
89
|
|
|
89
|
-
`cad-viewer`
|
|
90
|
+
In [`cad-viewer`](../cad-viewer), use `cpdf` to open the export options dialog; `-cpdf` remains available on the command line for prompt-based export.
|
|
91
|
+
|
|
92
|
+
`cad-viewer` registers this plugin automatically via `registerLazyPlugins()` in its app bootstrap and registers the `cpdf` dialog command separately.
|
|
90
93
|
|
|
91
94
|
### Eager registration
|
|
92
95
|
|
|
@@ -104,11 +107,21 @@ You can bypass the command layer and call the convertors directly:
|
|
|
104
107
|
|
|
105
108
|
```typescript
|
|
106
109
|
import { AcApContext } from '@mlightcad/cad-simple-viewer'
|
|
107
|
-
import {
|
|
110
|
+
import {
|
|
111
|
+
AcApPdfConvertor,
|
|
112
|
+
AcApPdfImportConvertor,
|
|
113
|
+
resolveAcApPdfExportOptions
|
|
114
|
+
} from '@mlightcad/cad-pdf-plugin'
|
|
108
115
|
|
|
109
116
|
// Export
|
|
110
117
|
const context: AcApContext = /* active context */
|
|
111
|
-
await new AcApPdfConvertor().convert(
|
|
118
|
+
await new AcApPdfConvertor().convert(
|
|
119
|
+
context,
|
|
120
|
+
resolveAcApPdfExportOptions({
|
|
121
|
+
modelSpaceFit: 'extents',
|
|
122
|
+
exportLayouts: true
|
|
123
|
+
})
|
|
124
|
+
)
|
|
112
125
|
|
|
113
126
|
// Import from bytes
|
|
114
127
|
const buffer: ArrayBuffer = /* PDF file */
|
|
@@ -117,11 +130,12 @@ await new AcApPdfImportConvertor().convert(context, buffer, 1) // page 1
|
|
|
117
130
|
|
|
118
131
|
## How it works
|
|
119
132
|
|
|
120
|
-
### Export (
|
|
133
|
+
### Export (`-cpdf` / dialog)
|
|
121
134
|
|
|
122
|
-
1.
|
|
123
|
-
2.
|
|
124
|
-
3.
|
|
135
|
+
1. Collect options: model-space framing (`Extents` / `Display`) and whether to export layouts.
|
|
136
|
+
2. Show the application busy overlay (same animation pattern as `chtml`).
|
|
137
|
+
3. Call `@mlightcad/pdf-renderer` `exportDatabaseToPdf`. With layouts enabled, model space and every paper space become one PDF page each.
|
|
138
|
+
4. Download the resulting PDF bytes.
|
|
125
139
|
|
|
126
140
|
### Import (`ipdf`)
|
|
127
141
|
|
|
@@ -139,9 +153,10 @@ Import is **vector-only**; raster/scanned PDF pages produce no entities. Only th
|
|
|
139
153
|
| `PDF_PLUGIN_NAME`, `PDF_PLUGIN_TRIGGERS` | Plugin id and command triggers |
|
|
140
154
|
| `@mlightcad/cad-pdf-plugin/register` | `registerLazyPdfPlugin` and registration constants |
|
|
141
155
|
| `AcApPdfPlugin` | `AcApPlugin` implementation |
|
|
142
|
-
| `AcApConvertToPdfCmd` | `cpdf` command class |
|
|
156
|
+
| `AcApConvertToPdfCmd` | `-cpdf` / fallback `cpdf` command class |
|
|
143
157
|
| `AcApImportPdfCmd` | `ipdf` command class |
|
|
144
|
-
| `AcApPdfConvertor` |
|
|
158
|
+
| `AcApPdfConvertor` | CAD → PDF export utility |
|
|
159
|
+
| `AcApPdfExportOptions`, `resolveAcApPdfExportOptions` | Export option types and defaults |
|
|
145
160
|
| `AcApPdfImportConvertor` | PDF → CAD entities import utility |
|
|
146
161
|
|
|
147
162
|
## Project layout
|
|
@@ -150,14 +165,15 @@ Import is **vector-only**; raster/scanned PDF pages produce no entities. Only th
|
|
|
150
165
|
|------|------|
|
|
151
166
|
| `src/register.ts` | Lazy plugin registration (`/register` entry) and `createPdfPlugin` |
|
|
152
167
|
| `src/AcApPdfPlugin.ts` | Plugin lifecycle (`onLoad` / `onUnload`) |
|
|
153
|
-
| `src/AcApConvertToPdfCmd.ts` |
|
|
168
|
+
| `src/AcApConvertToPdfCmd.ts` | `-cpdf` command (command-line prompts) |
|
|
154
169
|
| `src/AcApImportPdfCmd.ts` | `ipdf` command |
|
|
155
|
-
| `src/AcApPdfConvertor.ts` | Export pipeline (
|
|
170
|
+
| `src/AcApPdfConvertor.ts` | Export pipeline (`exportDatabaseToPdf`) |
|
|
171
|
+
| `src/AcApPdfExportOptions.ts` | Export option types and defaults |
|
|
156
172
|
| `src/AcApPdfImportConvertor.ts` | Import pipeline (pdf.js operator parsing) |
|
|
157
173
|
|
|
158
174
|
## Role in MLightCAD
|
|
159
175
|
|
|
160
|
-
This package extends `cad-simple-viewer` with optional PDF I/O.
|
|
176
|
+
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.
|
|
161
177
|
|
|
162
178
|
## License
|
|
163
179
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const s = "PdfPlugin", o = ["-cpdf", "cpdf", "ipdf"];
|
|
2
|
+
function P(r, e = {}) {
|
|
3
|
+
const t = e.disableExport === !0, i = t ? ["ipdf"] : [...o];
|
|
4
|
+
r.registerLazyPlugin({
|
|
5
|
+
name: s,
|
|
6
|
+
triggers: [...i],
|
|
6
7
|
loader: async () => {
|
|
7
|
-
const { createPdfPlugin:
|
|
8
|
-
return
|
|
8
|
+
const { createPdfPlugin: n } = await import("@mlightcad/cad-pdf-plugin");
|
|
9
|
+
return n({ disableExport: t });
|
|
9
10
|
}
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
s as PDF_PLUGIN_NAME,
|
|
15
|
+
o as PDF_PLUGIN_TRIGGERS,
|
|
16
|
+
P as registerLazyPdfPlugin
|
|
16
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var o=Object.create;var n=Object.defineProperty;var
|
|
1
|
+
"use strict";var o=Object.create;var n=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var u=(t,e,r,P)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of d(e))!l.call(t,i)&&i!==r&&n(t,i,{get:()=>e[i],enumerable:!(P=a(e,i))||P.enumerable});return t};var f=(t,e,r)=>(r=t!=null?o(c(t)):{},u(e||!t||!t.__esModule?n(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s="PdfPlugin",g=["-cpdf","cpdf","ipdf"];function p(t,e={}){const r=e.disableExport===!0,P=r?["ipdf"]:[...g];t.registerLazyPlugin({name:s,triggers:[...P],loader:async()=>{const{createPdfPlugin:i}=await import("@mlightcad/cad-pdf-plugin");return i({disableExport:r})}})}exports.PDF_PLUGIN_NAME=s;exports.PDF_PLUGIN_TRIGGERS=g;exports.registerLazyPdfPlugin=p;
|