This is an independent community resource about Dia. We are not affiliated with the GNOME Dia project. Command examples below were verified against Dia’s documented CLI behavior; flags may vary slightly by build.

Dia Command Line: Batch Export Diagrams

Dia is a GUI app — but it ships with a genuinely useful command-line mode. dia -e converts diagrams without opening a window, which means you can batch-export hundreds of .dia files, or wire diagram generation into documentation builds and CI pipelines. This guide covers the practical patterns.

The Basics

dia -e output.png input.dia        # export one diagram to PNG
dia -e output.svg input.dia        # vector SVG for documents
dia -e output.pdf input.dia        # PDF for print/runbooks

The export format is inferred from the output extension. Common choices: png, svg, pdf, eps. On Windows, run this from the Dia installation’s bin directory or add it to your PATH.

Headless environments: on a Linux server without a display, prefix with xvfb-run (e.g. xvfb-run dia -e out.png in.dia) since Dia still initializes its graphics stack.

Batch: Convert a Whole Folder

# Linux/macOS: export every .dia in docs/ to PNG
for f in docs/*.dia; do
  dia -e "${f%.dia}.png" "$f"
done

# Windows PowerShell equivalent
Get-ChildItem docs\*.dia | ForEach-Object {
  & dia.exe -e ($_.FullName -replace '\.dia$','.png') $_.FullName
}

Multi-Page Diagrams

If a .dia file has multiple pages, Dia exports each page — output filenames get a page suffix automatically. Verify the naming with one test file before batching hundreds.

Putting It in a Build (Makefile Example)

DIAGRAMS := $(wildcard diagrams/*.dia)
IMAGES   := $(DIAGRAMS:.dia=.png)

docs: $(IMAGES)

%.png: %.dia
	dia -e $@ $<

clean:
	rm -f $(IMAGES)

Now make docs regenerates every diagram image whenever sources change — diagrams stop rotting in your documentation.

CI Pipeline Notes

  • Install Dia in the CI image (apt install dia on Debian/Ubuntu runners) plus xvfb for headless export.
  • Pin the Dia version in your pipeline — rendering can shift subtly between builds.
  • Commit both .dia sources and generated images, or generate images as a build artifact.

For programmatic diagram generation (not just export), see automating Dia with Python.

Get Dia for the Command Line

Free download — the CLI ships with every desktop install.

Download Dia

Frequently Asked Questions

Can dia -e export a specific layer only?

Not directly via CLI flags in stock builds. Export the full diagram, or use Python scripting to toggle layers before exporting.

How do I control PNG resolution?

The GUI export dialog exposes size/DPI options; the CLI uses defaults. For high-res PNGs, export SVG via CLI and rasterize with a dedicated tool (e.g. rsvg-convert or Inkscape).

Does this work on Windows?

Yes — dia.exe accepts the same flags. Use full paths or run from the install bin folder.

dia: cannot open display — what now?

On headless Linux, install xvfb and prefix the command with xvfb-run.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *