1. Products
  2.   CAD
  3.   PHP
  4.   DXFighter
 
  

PHP Library for AutoCAD DXF Files Reading & Writing 

Open Source PHP CAD Library That Enables Programmers to Read, Edit and Write AutoCAD DXF Files. It Supports Basic DXF Exports & Read Lines from File.

What is DXFighter Library?

If you're a developer working with CAD data in web-based applications, DXFighter is a must-have tool. It’s a lightweight, Free DXF PHP API designed specifically for handling AutoCAD DXF files in PHP. This open-source solution is perfect for anyone looking to generate DXF drawings or read DXF files without relying on heavy, platform-dependent CAD software. DXF (Drawing Exchange Format), developed by Autodesk, is a widely adopted format for CAD interoperability. DXFighter serves as a practical and efficient PHP AutoCAD library, giving you direct control over DXF entities inside your applications. While it doesn't support the latest DXF version, it’s ideal for basic exports and lightweight CAD workflows.

With DXFighter, developers can easily draw and read common diagram elements. It supports creating and reading Arcs, Circles, Ellipses, Lines, Polylines, Points, Splines, Text, and Inserts and reading. These graphical components (known as entities) represent the visual content of any DXF file. Whether you're building a simple CAD viewer, automating technical drawing exports, or creating shape-based diagrams, DXFighter provides the essential building blocks. Its user-friendly API makes it accessible even for those new to CAD programming, and with a permissive BSD 3-Clause license, it’s free to use in both personal and commercial projects.

Previous Next

Getting Started with DXFighter

The recommended way to install DXFighter is using GitHub. Please use the following command a smooth installation.

Clone DXFighter via NuGet GitHub

git clone https://github.com/enjoping/DXFighter.git  

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

Generate AutoCAD DXF Drawing via PHP Library

The open source DXFighter library has incorporated complete functionality for generating AutoCAD DXF documents inside PHP applications. Once the DXF file is created, users can add and manage different kinds of entities inside the drawings such as Arcs, Circles, Ellipses, Lines, WPolyline, Points, Polyline, Text, Spline, and Insert. At the moment the library only allows to add entities and update their properties, other will follow soon.

How to Generate AutoCAD DXF via PHP API?

require_once('DXFighter.php');

$fighter = new \DXFighter\DXFighter(); //Create an Instance of the DXFighter class

$fighter->addEntity(new \DXFighter\lib\Line(array(0, 0, 0), array(10, 10, 0))); //Draw a line from Point (0|0|0) to (10|10|0)

$fighter->addEntity(new \DXFighter\lib\Circle(array(5, 0, 0), 3)); //Draw a circle centered on (5|0|0) with a radius of 3

$fighter->to_string(); //Output the DXF using echo

$fighter->saveAs('dxfighter.dxf'); //Write the DXF to a file named dxfighter.dxf

AutoCAD DXF File Reading inside PHP Apps

The DXFighter library has included a powerful reader that enables software developers to open and read the contents of AutoCAD DXF documents with just a couple of lines of code. At the moment the library has included support for reading some important entities such as Ellipses, Lines, Polyline, Text, Spline and Insert.

How to Read Lines from DXF File via PHP API

The open source DXFighter library allows software developers to open an AutoCAD DXF documents and read some lines from it using just a couple of PHP commands. To achieve this task user need to get the Line object from the Entities array and access its properties. The following example demonstrates how to read lines from DXF File.

How to Read Lines from DXF File via PHP API?

use DXFighter\DXFighter;
$dxf = new DXFighter('some-file.dxf');
echo "Loaded OK.\n";

$entities = $dxf->getEntities();
$line = $entities[0];
$end = $line->getEnd();
echo "Saw line to {$end[0]},{$end[1]},{$end[2]}\n";

 English