PHPackages                             antradar/gspdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. antradar/gspdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

antradar/gspdf
==============

High-performance PDF generation library with streaming architecture, O(1) memory usage, and 33-153x faster HTML rendering than TCPDF

v1.0.1(5mo ago)21.3k↓22.7%2MITPHPPHP &gt;=7.3

Since Nov 23Pushed 5mo agoCompare

[ Source](https://github.com/antradar/gspdf-php)[ Packagist](https://packagist.org/packages/antradar/gspdf)[ Docs](https://github.com/antradar/gspdf-php)[ RSS](/packages/antradar-gspdf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

GSPDF - High-Performance Streaming PDF Generation Library
=========================================================

[](#gspdf---high-performance-streaming-pdf-generation-library)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/972b840d9163498d88f90dbadd724a8de7bd81f38b94703db3faae0448d61c4d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e332532422d626c75652e737667)](https://www.php.net/)

**GSPDF** is a high-performance PDF generation library for PHP with streaming architecture that achieves **O(1) memory usage** and delivers **5-153x faster performance** than TCPDF.

🚀 Key Features
--------------

[](#-key-features)

- ✅ **Streaming Architecture** - O(1) memory usage, handles unlimited pages
- ✅ **33-153x Faster** than TCPDF for HTML rendering
- ✅ **5-10x Faster** for basic PDF operations
- ✅ **TCPDF-Compatible Coordinates** - Top-left origin (Y=0 at top, Y increases downward)
- ✅ **HTML Module** - Streaming HTML-to-PDF with SAX parser
- ✅ **PCS Support** - Import and insert PDF content streams with transformations
- ✅ **Placeholder Strategy** - Two-pass generation with configurable storage
- ✅ **Minimal Dependencies** - Core library has zero dependencies
- ✅ **Font Subsetting** - Automatic font subsetting for reduced file sizes
- ✅ **QR Code Support** - Generate QR codes with custom styling
- ✅ **Image Support** - JPEG-only (PNG deliberately disabled for performance)
- ✅ **Production Ready** - Memcache/Redis storage backends for distributed systems

📦 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

- PHP 7.3+ (tested on 7.3, 7.4, 8.x)
- No required extensions for core functionality
- Optional: php-memcached for Memcache storage backend
- Optional: php-xml (XMLReader) for HTML module (usually included by default)
- Optional: phpqrcode library for QR code generation

### Option 1: Composer (Recommended)

[](#option-1-composer-recommended)

```
composer require antradar/gspdf
```

Then use Composer's autoloader:

```
require_once 'vendor/autoload.php';

use GSPDF\GSPDF;

$pdf = new GSPDF();
```

### Option 2: Manual Installation (No Composer Required)

[](#option-2-manual-installation-no-composer-required)

We maintain full support for non-Composer installations, as many libraries only offer Composer options.

1. Clone or download this repository
2. Include the required files manually:

```
require_once 'gspdf-php/src/StreamWriter.php';
require_once 'gspdf-php/src/ObjectTracker.php';
require_once 'gspdf-php/src/PageBuilder.php';
require_once 'gspdf-php/src/GSPDF.php';

use GSPDF\GSPDF;
```

**Note:** Manual installation gives you full control and zero dependency on Composer infrastructure.

🎯 Quick Start
-------------

[](#-quick-start)

### Hello World

[](#hello-world)

```
use GSPDF\GSPDF;

$pdf = new GSPDF();
$pdf->addPage();
$pdf->SetFont('helvetica', '', 12);
$pdf->text(50, 50, 'Hello, World!');
$pdf->output('hello.pdf', 'F');
```

### HTML Rendering

[](#html-rendering)

```
use GSPDF\GSPDF;
use GSPDF\HTML\HTMLModule;

$pdf = new GSPDF();
$htmlModule = new HTMLModule($pdf);
$pdf->loadHTMLModule($htmlModule);

$pdf->addPage();

$html = 'Welcome to GSPDF
This is bold and italic text.

    Fast performance
    Low memory usage
    Easy to use
';

$pdf->writeHTML($html);
$pdf->output('document.pdf', 'F');
```

### QR Code Generation

[](#qr-code-generation)

```
// Download phpqrcode from: http://phpqrcode.sourceforge.net/

$pdf = new GSPDF([
    'qr_lib_path' => '/path/to/phpqrcode.php'
]);

$pdf->addPage();
$pdf->write2DBarcode(
    'https://github.com/your-repo/gspdf',
    'QRCODE,M',
    50, 50, 100, 100,
    ['border' => true, 'padding' => 2]
);
$pdf->output('qrcode.pdf', 'F');
```

📚 Documentation
---------------

[](#-documentation)

- **[PHP README](src/README.md)** - Comprehensive PHP library documentation
- **[HTML Module](src/HTML/README.md)** - HTML rendering documentation
- **[Barcode Module](src/Barcode/README.md)** - QR code generation guide
- **[Examples](examples/)** - Code examples and demos

🎨 Features
----------

[](#-features)

### Streaming Architecture

[](#streaming-architecture)

GSPDF uses a streaming architecture that writes PDF content directly to output as it's generated:

- **O(1) Memory Usage** - Memory usage stays constant regardless of document size
- **Immediate Flushing** - Pages are written immediately, not stored in memory
- **Scalable** - Generate documents with thousands of pages without memory issues

### HTML Support

[](#html-support)

The HTML module provides streaming HTML-to-PDF conversion:

- Supported tags: `p`, `br`, `b`, `i`, `u`, `strong`, `em`, `h1-h6`, `ul`, `ol`, `li`, `table`, `tr`, `td`, `th`, `div`, `span`
- CSS support: `font-family`, `font-size`, `color`, `background-color`, `text-align`, `font-weight`, `font-style`
- Streaming parser: SAX-style parsing with O(1) memory
- **33-153x faster** than TCPDF for HTML rendering

### Font Subsetting

[](#font-subsetting)

Automatic font subsetting reduces PDF file sizes:

- Only embeds glyphs that are actually used
- Range-based character tracking with O(log n) memory
- Supports Unicode fonts (CJK, Arabic, etc.)
- Typical savings: 50-95% depending on character usage

### Image Embedding: JPEG-Only by Design

[](#image-embedding-jpeg-only-by-design)

GSPDF **deliberately supports JPEG only** and disables PNG embedding. This design decision reflects our relentless focus on performance:

- **Direct Compression** - JPEG data is embedded directly using PDF's DCTDecode filter (no re-encoding)
- **Zero Processing** - JPEG files are copied byte-for-byte into the PDF stream
- **Optimal Performance** - No decompression, no pixel manipulation, no memory overhead
- **Smaller Files** - JPEG compression is ideal for photos and complex images

**Why not PNG?**

- PNG requires decompression and re-encoding for PDF
- Adds processing overhead and memory usage
- Increases generation time significantly
- For web graphics and screenshots, convert to JPEG first

**Recommendation:** Use JPEG for all images. For logos/graphics that require transparency, consider SVG or vector graphics instead.

### Placeholder Strategy

[](#placeholder-strategy)

Two-pass PDF generation for dynamic content:

- First pass: Generate draft PDF with placeholders
- Second pass: Replace placeholders with actual values
- Storage backends: Filesystem, Memcache, Redis
- Perfect for page numbers, totals, cross-references

📊 Performance
-------------

[](#-performance)

Benchmark results (GSPDF vs TCPDF):

OperationGSPDFTCPDFSpeedupSimple text (100 pages)0.15s0.75s**5x faster**HTML rendering (complex)0.12s18.4s**153x faster**HTML rendering (simple)0.09s3.0s**33x faster**Memory usageO(1)O(n)**Constant**🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit pull requests or open issues.

📄 License
---------

[](#-license)

MIT License

Copyright (c) 2025 Antradar Software Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

👤 Author
--------

[](#-author)

**Schien Dong**
Antradar Software Inc.

🙏 Acknowledgments
-----------------

[](#-acknowledgments)

- Inspired by TCPDF and FPDF
- Uses phpqrcode library for QR code generation (optional dependency)
- Font subsetting based on TrueType specification

📞 Support
---------

[](#-support)

For issues, questions, or feature requests, please open an issue on GitHub.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance70

Regular maintenance activity

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

177d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c2a543cc7684eda6bee9443ba5fcf639a9fab2ac5290f2acd95b7fc1bcb0324?d=identicon)[schien-dong](/maintainers/schien-dong)

---

Top Contributors

[![schien-dong](https://avatars.githubusercontent.com/u/7111291?v=4)](https://github.com/schien-dong "schien-dong (8 commits)")

---

Tags

qr codepdfstreamingbarcodehigh-performancehtml-to-pdfpdf-generationlow-memoryfont-subsetting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/antradar-gspdf/health.svg)

```
[![Health](https://phpackages.com/badges/antradar-gspdf/health.svg)](https://phpackages.com/packages/antradar-gspdf)
```

###  Alternatives

[imal-h/pdf-box

The most advanced, driver-based PDF manipulation library for PHP v3.0. Supports Ghostscript, Chrome Headless (HTML to PDF), OpenSSL/FPDI (Signing), and PDFtk (Forms).

60403.9k](/packages/imal-h-pdf-box)[cangelis/pdf

Yet another HTML to PDF Converter based on wkhtmltopdf

5363.7k1](/packages/cangelis-pdf)[yetiforce/yetiforcepdf

Library that generate pdf files from html.

13127.8k1](/packages/yetiforce-yetiforcepdf)[cangelis/l4pdf

Yet another HTML to PDF Converter for Laravel4

548.2k](/packages/cangelis-l4pdf)[wemersonjanuario/laravelpdf

Another HTML to PDF Converter for Laravel

2912.9k1](/packages/wemersonjanuario-laravelpdf)[tarfin-labs/easy-pdf

Makes pdf processing easy.

1718.3k](/packages/tarfin-labs-easy-pdf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
