1. Products
  2.   CAD
  3.   PHP
  4.   DXF-Creator-for-PHP
 
  

Free PHP CAD Library to Generate AutoCAD DXF Files

Open Source PHP CAD Library to Create Lines, Circles, Arcs, Text, and Layers in DXF using PHP. Complete Tutorial on DXF-Creator-for-PHP with Real Code Samples.

What is DXF-Creator-for-PHP?

In today's engineering and manufacturing landscape, the ability to automate CAD file generation is a significant advantage. Whether you're building a web-based floor planner, an automated quoting system for CNC machining, or a custom furniture designer, generating DXF files programmatically can save hours of manual labor. One of the most efficient tools for this task in the PHP ecosystem is DXF-Creator-for-PHP. Originally developed by KOYU-Tech and built as an upgrade to the classic DXF-Writer, this library provides a clean, object-oriented way to create AutoCAD-compatible DXF files. There are several important features making worth using the DXF-Creator-for-PHP library. It supports lines, circles, arcs, points, text, and embedded images and fluent method chaining for clean, readable code. It supports RGB color support through a dedicated Color class and full layer management with per-layer colors and line types and so on.

DXF Creator for PHP is an open-source PHP library that lets you create Drawing Exchange Format (DXF) files — the universal file format used by AutoCAD, LibreCAD, DraftSight, and virtually every other CAD application. The library was originally derived from DXF-Writer (published on PHPClasses) and has since been significantly upgraded by KOYU-Tech with new features including image embedding, multi-layer support, RGB color mixing, and more. By leveraging its object-oriented approach, you can turn complex mathematical data into precise, industry-standard drawings with just a few lines of code.

Previous Next

Getting Started with DXF Creator for PHP

The recommended way to install DXF Creator for PHP is using GitHub. Please use the following command a smooth installation.

Install DXF-Creator-for-PHP via Composer

//composer require adamasantares/dxf "0.1.6"
or
"require": {
      "adamasantares/dxf": "0.1.6"
  }

Install DXF-Creator-for-PHP via GitHub

git clone https://github.com/KOYU-Tech/DXF-Creator-for-PHP.git 

You can also install it manually; download the latest release files directly from GitHub repository.

Simple DXF Geometry Creation via PHP

The open source DXF-Creator-for-PHP library has included complete support for creating and managing simple DXF geometry files inside PHP applications. The library supports essential geometric primitives such as Lines, Arcs, Circles and Points. These building blocks form the basis of almost every DXF drawing. The following example demonstrates how software developers can create a line, a circle, and an arc, and saves the result as geometry.dxf using PHP commands.

How to Add Basic Shapes to Create a CAD Drawing via PHP Library?

 use Creator;
use Color;
use LineType;

$dxf = new Creator(Creator::MILLIMETERS);

// Simple line
$dxf->addLine(0, 0, 0, 50, 50, 0);

// Circle at origin with radius 25
$dxf->addCircle(0, 0, 0, 25);

// Arc with 0–90 degree sweep
$dxf->addArc(50, 50, 0, 15.0, 270.0);

// Save the DXF
$dxf->saveToFile("geometry.dxf");

Layer and Style Management

Layers organize your drawing and control how entities appear. DXF-Creator-for-PHP library has included complete functionality for creating and handling layers inside PHP applications. the library lets you define new layers with specific colors and line types. The following example shows how layers are defined with different colors and line types inside PHP applications.

How to Create Custom Layers via PHP Library?

 $dxf->setLayer("outline", Color::BLUE, LineType::CONTINUOUS)
    ->addLine(10, 10, 0, 100, 10, 0);

$dxf->setLayer("details", Color::RED, LineType::DASHED)
    ->addCircle(50, 50, 0, 20);

$dxf->saveToFile("layers.dxf");

Image Embedding in DXF via PHP

The open source DXF-Creator-for-PHP library has provided support for embedding image inside AutoCAD DXF files. Not many DXF libraries support embedding image previews — but this library gives you that power too. With just a couple of lines of code developers can embed or delete an image with ease. Here is a simple example that shows how to inserts an image (e.g., logo or blueprint snapshot) into your DXF via PHP code.

How to Embed an image into DXF File via PHP Library?

$path   = "logo.png";
$size   = getimagesize($path);
$width  = $size[0];
$height = $size[1];

$dxf->addImage(0, 0, 0, 50, 50, 0, $path, $width, $height);

Drawing Lines via PHP Library

The open source DXF-Creator-for-PHP library makes it easy to draw and manage diagram lines using PHP library. Lines are the most fundamental CAD entity. The addLine() method accepts start and end coordinates in 3D space. The library supports adding, deleting, and In the following example, we're drawing a 200×150mm rectangle using four connected line segments.

How to Draw a Rectangular Border via PHP Library?

$dxf = new Creator(Creator::MILLIMETERS);

$dxf->addLine(0, 0, 0, 200, 0, 0)    // Bottom edge
    ->addLine(200, 0, 0, 200, 150, 0) // Right edge
    ->addLine(200, 150, 0, 0, 150, 0) // Top edge
    ->addLine(0, 150, 0, 0, 0, 0);    // Left edge