@mlightcad/cad-pdf-exporter 0.0.0-stage → 1.8.0-preview.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mlightcad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,79 @@
1
- # Temporary Holding Version
1
+ # @mlightcad/cad-pdf-exporter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Headless (Node) export of DXF/DWG drawings to vector PDF.
4
+
5
+ > **1.8.0:** New package. Same shared pipeline as browser `cpdf`, via
6
+ > `@mlightcad/cad-pdf-core`, so server/CI export does not need Playwright or a
7
+ > browser. See the [upgrade guide](../../docs/development/upgrade-guide.md).
8
+
9
+ Uses `@mlightcad/data-model` + `@mlightcad/pdf-renderer` through
10
+ `@mlightcad/cad-pdf-core`, the same pipeline as the browser `cpdf` command in
11
+ `@mlightcad/cad-pdf-plugin`. **Does not** depend on
12
+ `@mlightcad/cad-simple-viewer` or a browser.
13
+
14
+ ## Options
15
+
16
+ | Option | Values | Default | Notes |
17
+ | --------------- | ----------------------- | --------- | ----- |
18
+ | `colorMode` | `color` / `monochrome` | `color` | `monochrome`: white paper, all drawing content black |
19
+ | `textMode` | `text` / `vector` | `text` | `text` embeds fonts so text stays selectable |
20
+ | `exportLayouts` | `true` / `false` | `true` | `true`: model space and every paper-space layout, one page each |
21
+ | `title` | string | file stem | PDF document title |
22
+ | `fontsDir` | path | — | Local font library (takes precedence over `fontsUrl`) |
23
+ | `fontsUrl` | URL | jsDelivr | Remote font library base URL |
24
+ | `fontMapping` | `{ [from]: to }` | — | Font name substitutions |
25
+ | `dwgParser` | `libredwg` / `dwg` | `libredwg`| `dwg` needs the optional `@mlightcad/dwg-converter` |
26
+ | `dwgLicenseKey` | string | — | License for `dwgParser: 'dwg'` |
27
+
28
+ Model space is always framed by drawable extents. A headless export has no
29
+ live view, so the plugin's `Display` framing is not offered.
30
+
31
+ In `monochrome` mode, linework and text are black and solid/gradient fills
32
+ become grey by luminance. Wipeouts still mask in white and raster images keep
33
+ their pixels. PNG and JPEG images are embedded; other raster formats (BMP,
34
+ GIF) need a browser canvas to convert, so they are skipped in Node.
35
+
36
+ ## Example
37
+
38
+ After `pnpm build`, from this package:
39
+
40
+ ```sh
41
+ node examples/export-pdf.mjs drawing.dwg drawing.pdf
42
+ node examples/export-pdf.mjs drawing.dwg drawing-bw.pdf --color-mode monochrome
43
+ node examples/export-pdf.mjs drawing.dwg drawing.pdf --text-mode vector --no-layouts --fonts-dir D:/cad-data
44
+ ```
45
+
46
+ ## API
47
+
48
+ ```ts
49
+ import {
50
+ convertDatabaseToPdf,
51
+ exportFileToPdf
52
+ } from '@mlightcad/cad-pdf-exporter'
53
+
54
+ // File → file
55
+ await exportFileToPdf('drawing.dwg', 'drawing.pdf', {
56
+ colorMode: 'monochrome',
57
+ // Local font library: a face folder, that folder with fonts.json, or a
58
+ // cad-data checkout (faces resolved from its fonts/ directory).
59
+ fontsDir: 'D:/code/cad-data'
60
+ })
61
+
62
+ // Already-open database → bytes
63
+ const bytes = await convertDatabaseToPdf(database, { title: 'drawing' })
64
+ ```
65
+
66
+ ## Fonts
67
+
68
+ Text is drawn by the same MText engine as the viewer, running on the Node
69
+ main thread. Fonts come from `fontsDir` or `fontsUrl` (by default the public
70
+ cad-data library on jsDelivr; set `HTTPS_PROXY` when the network needs a
71
+ proxy). With `textMode: 'text'`, TrueType/OpenType/WOFF faces are subset
72
+ and embedded. SHX fonts have nothing to embed, so their text is drawn as
73
+ vector glyphs.
74
+
75
+ ## Related packages
76
+
77
+ - `@mlightcad/cad-pdf-core` — shared options and export pipeline
78
+ - `@mlightcad/cad-pdf-plugin` — browser `cpdf` / `-cpdf` commands
79
+ - `@mlightcad/cad-html-exporter` — the HTML counterpart of this package