KJDRAW / FILES AND PROJECTS
Files and projects
Read and write KJD, package multi-drawing KJP projects and use the explicitly bounded ASCII DXF compatibility profile.
Choose a format#
| Format | Use it for | Contract boundary |
|---|---|---|
| KJD | One canonical transactional drawing | JSON model, validation and revisions |
| KJP | A portable project with drawings, assets, snapshots and journal | Deterministic ZIP64 package with hashes and read budgets |
| DXF | Interchange with the published ASCII subset | Named entities, resources and versions only |
The maintained compatibility matrix is the authority for format versions and semantic coverage.
Read and write a drawing#
const drawing = await sdk.readDocument(await file.arrayBuffer(), {
format: 'DXF',
})
const kjd = await sdk.writeDocument(drawing, { format: 'KJD' })
const dxf = await sdk.writeDocument(drawing, {
format: 'DXF',
version: '2018',
})
Adapters share the same document model. Keep the original input when evaluating interoperability, and treat an exported file as a new artifact rather than proof of application-specific durable storage.
DXF 2000 and newer exports retain named and empty layout identities, tab order and entity ownership. Import resolves layout/block references even without entity 410 hints; non-primary paper entities are written inside their space blocks for independent readers. Full paper settings, viewports and plotting fidelity remain outside this guarantee. Conflicting layout identities or ambiguous entity ownership fail the import instead of silently moving geometry.
Preserve DXF page configuration#
Imported layout payload.dxfPlotSettings retains 30 scalar AcDbPlotSettings fields, including paper dimensions, margins, offsets, window, units, rotation, scale and resource names. KJDxfPlotSettings is exported from the package; transaction.createLayout({ name, dxfPlotSettings }) also accepts it. The fields remain in KJD and DXF 2000+.
In the embedded editor, open Page setup from the top bar, choose a sheet and edit physical paper dimensions, margins, plot units, rotation or custom scale. Blank fields keep existing values. Apply changes only that sheet; Cancel/Escape and applying an unchanged form leave the drawing/history untouched. Changing either custom-scale field clears the standard-scale flag while preserving other flags. If the drawing changes while the form is open, close and reopen it before applying. Readonly editors disable the entry. This form configures exports; it does not provide print preview or drive a printer. Choose a plot area (display, extents, limits, named view, window or layout), enter a view name for named-view output, or four drawing-unit coordinates for a window. Window width and height must be positive. Origin offsets use millimeters. Fit to paper sets the standard-scale flag and scale type 0; custom ratio clears that flag. Existing unrelated flags and unused window/view settings are preserved. Named-view configuration stores the supplied reference; it does not verify or render that view.
await sdk.executeCommand('PAGESETUP', {
layoutName: 'Model',
dxf: { paperWidth: 594, paperHeight: 841, paperUnits: 1, rotation: 1,
plotType: 4, windowMinX: 0, windowMinY: 0, windowMaxX: 400, windowMaxY: 277,
scaleNumerator: 1, scaleDenominator: 100 },
})
dxf patches only supplied fields and supports undo/redo. Physical paper dimensions, margins and origin offsets always use millimeters; paperUnits is 0/inches, 1/mm or 2/pixels. rotation is the DXF index 0/1/2/3 for 0/90/180/270 degrees counterclockwise. This explicit mode preserves the existing native PLOTSETUP settings contract (degree rotation, nested scale, output device). Native plotSettings and the legacy paper envelope are not silently converted to DXF configuration; use dxf for interchange. R12/R14 exports reject populated DXF page settings. Invalid settings fail atomically.
Use the configured layout for strict vector or print output:
import { createDrawingPrintHtml, exportDrawingSvg } from '@kanjieteam/kjdraw'
const layout = drawing.getActiveLayout()
if (!layout) throw new Error('No active layout')
const svg = exportDrawingSvg(drawing, { layoutId: layout.id })
const print = createDrawingPrintHtml(drawing, { layoutId: layout.id, title: 'Drawing' })
console.log(svg.report.status, svg.paper.millimetersPerDrawingUnit)
// svg.svg and print.html are complete document strings.
Model-space output requires an explicit window (plotType: 4) or named view (plotType: 3). A paper layout uses its layout range. Strict export rejects geometry it cannot represent; inspect report before delivering the file.
This is configuration preservation, not physical printing or a page preview. Layout limits/extents, viewport projection, named page-setup dictionaries, shade-object handles, transparency XDATA and referenced printer/style files remain outside this guarantee. KJDraw does not execute resource names or load local printer configuration.
Package a project#
Use KJProjectSession when the application needs active-drawing state, membership and a command journal. Use createKjpPackage() and openKjpPackage() for lower-level package assembly and inspection. A browser file binding can download and reopen a KJP; a desktop or server provider defines atomic replacement and fsync guarantees.
Limits and DXF evidence#
KJD, KJP and DXF readers accept configurable byte/object/entity/archive budgets and abort signals. Export diagnostics make format decisions observable to the host.
The exact versions, entity/resource subset and independent ezdxf audit are maintained in the DXF compatibility contract.