DWG To PDF
Overview
Use this skill to convert CAD drawings into PDF files without uploading the drawing to a web service. Prefer the bundled script because DWG conversion has several brittle details on Windows: ODA command-line argument order, CAD library dependencies, and non-ASCII output paths.
Workflow
- Confirm the source file exists and identify whether it is
.dwgor.dxf. - Choose an output path. If the user did not specify one, save
<source-stem>.pdfbeside the source file. - Run
scripts/convert_dwg_to_pdf.pywith absolute paths:
python scripts/convert_dwg_to_pdf.py --input "D:\path\plan.dwg" --output "D:\path\plan.pdf"
- Verify the result in the script output:
pagesmust be at least 1.bytesmust be greater than 0.previewshould point to a rendered PNG of page 1.
- Open the PDF for the user when they asked to "open" it or when opening is clearly useful.
Tooling
The script supports:
.dwg: convert to DXF with ODA File Converter, then render to PDF..dxf: render directly to PDF.
If ODA File Converter is missing, install it with Windows Package Manager when allowed:
winget install --id ODA.ODAFileConverter -e --accept-source-agreements --accept-package-agreements --disable-interactivity
The script requires Python packages ezdxf, matplotlib, and pymupdf. If they are missing and package installation is allowed, install them:
python -m pip install ezdxf matplotlib pymupdf
Quality Checks
Always check that the generated PDF renders. A non-empty PDF can still be wrong if the drawing was not visible, the page was badly cropped, or text/fonts failed.
Use the generated preview PNG for a quick visual check. If it is blank or heavily cropped:
- rerun with a larger paper size, for example
--paper a2-landscape; - try direct ODA viewer/manual print if the drawing uses layouts or features that
ezdxfcannot render well; - tell the user if the output may not preserve every CAD feature exactly.
Notes
- Do not modify the original DWG. Work from a copied intermediate folder when converting.
- Avoid web converters unless the user explicitly approves uploading the drawing.
- When saving to Chinese or other non-ASCII paths, let the script write to an ASCII temporary PDF first and copy it to the requested output path.
- Use absolute file paths in final responses.