@mlightcad/cad-pdf-exporter 1.8.0-preview.3 → 1.8.0-preview.4
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 +21 -21
- package/README.md +81 -80
- package/dist/index.cjs +6884 -6314
- package/dist/index.js +6885 -6315
- package/examples/export-pdf.mjs +117 -111
- package/lib/convertDatabase.d.ts.map +1 -1
- package/lib/convertDatabase.js +1 -0
- package/lib/convertDatabase.js.map +1 -1
- package/lib/exportOptions.d.ts +6 -0
- package/lib/exportOptions.d.ts.map +1 -1
- package/lib/nodeFontLoader.d.ts.map +1 -1
- package/lib/nodeFontLoader.js +1 -5
- package/lib/nodeFontLoader.js.map +1 -1
- package/package.json +7 -7
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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,80 +1,81 @@
|
|
|
1
|
-
# @mlightcad/cad-pdf-exporter
|
|
2
|
-
|
|
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
|
-
| `
|
|
22
|
-
| `
|
|
23
|
-
| `
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
node examples/export-pdf.mjs drawing.dwg drawing
|
|
44
|
-
node examples/export-pdf.mjs drawing.dwg drawing.pdf --
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- `@mlightcad/cad-pdf-
|
|
80
|
-
- `@mlightcad/cad-
|
|
1
|
+
# @mlightcad/cad-pdf-exporter
|
|
2
|
+
|
|
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
|
+
| `exportEmptyLayouts` | `true` / `false` | `false` | `false`: skip empty paper-space layouts; model space is always kept |
|
|
22
|
+
| `title` | string | file stem | PDF document title |
|
|
23
|
+
| `fontsDir` | path | — | Local font library (takes precedence over `fontsUrl`) |
|
|
24
|
+
| `fontsUrl` | URL | jsDelivr | Remote font library base URL |
|
|
25
|
+
| `fontMapping` | `{ [from]: to }` | — | Font name substitutions |
|
|
26
|
+
| `dwgParser` | `libredwg` / `dwg` | `libredwg`| `dwg` needs the optional `@mlightcad/dwg-converter` |
|
|
27
|
+
| `dwgLicenseKey` | string | — | License for `dwgParser: 'dwg'` |
|
|
28
|
+
| `drawNoPlotLayers` | `true` / `false` | `false` | `false`: omit no-plot layers (matches cad-editor / AutoCAD plot) |
|
|
29
|
+
|
|
30
|
+
Model space is always framed by drawable extents. A headless export has no
|
|
31
|
+
live view, so the plugin's `Display` framing is not offered.
|
|
32
|
+
|
|
33
|
+
In `monochrome` mode, linework and text are black and solid/gradient fills
|
|
34
|
+
become grey by luminance. Wipeouts still mask in white and raster images keep
|
|
35
|
+
their pixels. PNG and JPEG images are embedded; other raster formats (BMP,
|
|
36
|
+
GIF) need a browser canvas to convert, so they are skipped in Node.
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
After `pnpm build`, from this package:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
node examples/export-pdf.mjs drawing.dwg drawing.pdf
|
|
44
|
+
node examples/export-pdf.mjs drawing.dwg drawing-bw.pdf --color-mode monochrome
|
|
45
|
+
node examples/export-pdf.mjs drawing.dwg drawing.pdf --text-mode vector --no-layouts --fonts-dir D:/cad-data
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import {
|
|
52
|
+
convertDatabaseToPdf,
|
|
53
|
+
exportFileToPdf
|
|
54
|
+
} from '@mlightcad/cad-pdf-exporter'
|
|
55
|
+
|
|
56
|
+
// File → file
|
|
57
|
+
await exportFileToPdf('drawing.dwg', 'drawing.pdf', {
|
|
58
|
+
colorMode: 'monochrome',
|
|
59
|
+
// Local font library: a face folder, that folder with fonts.json, or a
|
|
60
|
+
// cad-data checkout (faces resolved from its fonts/ directory).
|
|
61
|
+
fontsDir: 'D:/code/cad-data'
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Already-open database → bytes
|
|
65
|
+
const bytes = await convertDatabaseToPdf(database, { title: 'drawing' })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Fonts
|
|
69
|
+
|
|
70
|
+
Text is drawn by the same MText engine as the viewer, running on the Node
|
|
71
|
+
main thread. Fonts come from `fontsDir` or `fontsUrl` (by default the public
|
|
72
|
+
cad-data library on jsDelivr; set `HTTPS_PROXY` when the network needs a
|
|
73
|
+
proxy). With `textMode: 'text'`, TrueType/OpenType/WOFF faces are subset
|
|
74
|
+
and embedded. SHX fonts have nothing to embed, so their text is drawn as
|
|
75
|
+
vector glyphs.
|
|
76
|
+
|
|
77
|
+
## Related packages
|
|
78
|
+
|
|
79
|
+
- `@mlightcad/cad-pdf-core` — shared options and export pipeline
|
|
80
|
+
- `@mlightcad/cad-pdf-plugin` — browser `cpdf` / `-cpdf` commands
|
|
81
|
+
- `@mlightcad/cad-html-exporter` — the HTML counterpart of this package
|