Skip to content

feat: add PDF export (cpdf) and PDF import (ipdf) commands#218

Open
4ni1ak wants to merge 5 commits intomlightcad:mainfrom
4ni1ak:feat/pdf-export
Open

feat: add PDF export (cpdf) and PDF import (ipdf) commands#218
4ni1ak wants to merge 5 commits intomlightcad:mainfrom
4ni1ak:feat/pdf-export

Conversation

@4ni1ak
Copy link
Copy Markdown
Contributor

@4ni1ak 4ni1ak commented Apr 16, 2026

Summary

Adds two new PDF-related commands:

1. cpdf — Export to PDF (vector)

Reuses the existing AcSvgRenderer pipeline, converts the SVG output to a vector PDF using jsPDF + svg2pdf.js, and downloads drawing.pdf.

2. ipdf — Import PDF

Uses pdfjs-dist to extract vector geometry from the first PDF page and append it to the current document's model space:

  • moveTo / lineToAcDbLine / AcDbPolyline
  • Cubic bezier curves → approximated polyline (8 segments each)
  • Coordinates scaled: 1 PDF point = 0.3528 mm, Y-axis flipped to match CAD convention

New files

File Purpose
AcApPdfConvertor.ts Export: SVG → PDF via jsPDF
AcApConvertToPdfCmd.ts Export command (cpdf)
AcApPdfImportConvertor.ts Import: PDF operators → CAD entities
AcApImportPdfCmd.ts Import command (ipdf)

Changed files

  • AcApDocManager.ts — registers cpdf and ipdf commands
  • command/index.ts — exports new classes
  • MlMainMenu.vue — "Export to PDF" and "Import PDF" menu items
  • locale/en/main.ts, locale/zh/main.ts — i18n keys

Test plan

  • pnpm build — all packages compile without errors
  • Open a DXF, menu → "Export to PDF" → drawing.pdf downloads with vector geometry
  • Menu → "Import PDF" → select a technical PDF → geometry appears in model space as lines/polylines
  • Type cpdf / ipdf in command bar — same results

@4ni1ak 4ni1ak changed the title feat: add PDF export command (cpdf) feat: add PDF export (cpdf) and PDF import (ipdf) commands Apr 16, 2026
4ni1ak added 3 commits April 16, 2026 16:02
- Add AcApPdfConvertor: reuses AcSvgRenderer pipeline, converts the
  resulting SVG to a vector PDF using jsPDF and svg2pdf.js
- Add AcApConvertToPdfCmd: thin command wrapper, registered as 'cpdf'
- Register 'cpdf' command in AcApDocManager.registerCommands()
- Add 'Export to PDF' menu item in MlMainMenu.vue
- Add exportPdf i18n key to en/zh locale files
- Add AcApPdfImportConvertor: loads PDF with pdfjs-dist, walks the
  operator list (moveTo/lineTo/curveTo/closePath), converts path segments
  to AcDbPolyline / AcDbLine entities, appends to model space
  - Cubic bezier curves approximated as 8-segment polylines
  - Coordinates scaled from PDF points to mm (1pt = 25.4/72 mm)
  - Y-axis flipped to match CAD coordinate convention
- Add AcApImportPdfCmd: thin command wrapper, registered as 'ipdf'
- Register 'ipdf' command in AcApDocManager.registerCommands()
- Add 'Import PDF' menu item in MlMainMenu.vue
- Add importPdf i18n key to en/zh locale files
@4ni1ak
Copy link
Copy Markdown
Contributor Author

4ni1ak commented Apr 16, 2026

Conflict resolved. The two TypeScript build errors (AcApMoveCmd.ts:88clone not on AcDbEntity, AcEdInputManager.ts:1504SHORTCUTMENU not in AcDbSystemVariables) originate from upstream commits #208 and #210, not from this PR. They will need to be fixed separately in the upstream data-model package.

@mlightcad
Copy link
Copy Markdown
Owner

@4ni1ak Is it possible to implement it as one plugin so that users can use it on demand because currently thei size of cad-viewer bundle isn't small any more. So I created plugin mechnisam to handle it. You can find the related code in folder 'packages\cad-simple-viewer\src\plugin'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants