PHPackages                             redocmx/client-php - 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. redocmx/client-php

ActiveLibrary

redocmx/client-php
==================

Converción de CFDI a PDF.

0.0.2(2y ago)013MITPHPPHP &gt;=5.6.0

Since Apr 9Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Converting CFDI to PDF
======================

[](#converting-cfdi-to-pdf)

redocmx/client-php
------------------

[](#redocmxclient-php)

The `redocmx/client-php` module is a PHP client for interacting with the [redoc.mx](https://redoc.mx) REST API to convert CFDIs (Comprobante Fiscal Digital por Internet) to PDFs.

This client simplifies the process of sending XML data and retrieving the converted PDF, along with transaction details and metadata.

Requirements
------------

[](#requirements)

PHP 5.6.0 and later.

Installation
------------

[](#installation)

To install the module, run:

```
composer require redocmx/client-php
```

To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):

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

Usage
-----

[](#usage)

First, import the module and create an instance of the Redoc client.

You can optionally pass your API key as an argument, or the client will attempt to load it from the REDOC\_API\_KEY environment variable.

```
  use Redocmx\RedocmxClient;

  # Create a Redoc instance
  $redoc = new RedocmxClient('your_api_key_here');
```

### Converting CFDI to PDF

[](#converting-cfdi-to-pdf-1)

The `redocmx/client-php` provides two options for loading CFDI data: from a file or directly from a string.

#### Option 1: Load XML from the File System

[](#option-1-load-xml-from-the-file-system)

```
$cfdi = $redoc->cfdi()->fromFile('./path/to/your/file.xml');
```

#### Option 2: Use an XML Content String

[](#option-2-use-an-xml-content-string)

```
$cfdi = $redoc->cfdi()->fromString('');
```

### Generating the PDF

[](#generating-the-pdf)

To convert the loaded CFDI to a PDF:

```
  try {
    # Create the PDF
    $pdf = $cfdi->toPdf();

    echo("Transaction ID: " . $pdf->getTransactionId() . "\n");
    echo("Total Pages: " . $pdf->getTotalPages() . "\n");
    echo("Total Time: " .$pdf->getTotalTimeMs() . "\n");
    print_r($pdf->getMetadata());

    # Save in file system
    file_put_contents('./result.pdf', $pdf->toBuffer());

  } catch (Exception $e) {
    echo "An error occurred during the conversion: " . $e->getMessage();
  }
```

Examples
--------

[](#examples)

- [Basic example](https://github.com/redocmx/cfdi-a-pdf-ejemplos)
- [Custom logo and colors](https://github.com/redocmx/cfdi-a-pdf-ejemplos)
- [Change language to English](https://github.com/redocmx/cfdi-a-pdf-ejemplos)
- [Add additional rich content](https://github.com/redocmx/cfdi-a-pdf-ejemplos)

API Reference
-------------

[](#api-reference)

### RedocmxClient

[](#redocmxclient)

The `$redoc` object is an instance of `RedocmxClient`, created using `new RedocmxClient(api_key)`.

MethodDescription$redoc-&gt;cfdi()-&gt;**fromFile(filePath)**Returns: **Cfdi** - **Instance**
Loads file content from the file system for converting a CFDI to PDF. The file should be valid XML for a CFDI.
It returns an instance of the Cfdi class, which can be used to obtain the PDF.$redoc-&gt;cfdi()-&gt;**fromString(fileContent)**Returns: **Cfdi** - **Instance**
Uses a CFDI as a string for converting the CFDI to PDF. The string should be valid XML for a CFDI.
It returns an instance of the Cfdi class, which can be used to obtain the PDF.### Cfdi

[](#cfdi)

The `$cfdi` object is an instance of `Cfdi`, created using `$redoc->cfdi()->fromFile(filePath)` or `$redoc->cfdi()->fromString(fileContent)`.

MethodDescription$cfdi()-&gt;**setAddenda(str)**Params: **String**
Allows the use of a [redoc addenda](https://redoc.mx/docs/addenda) for full control over the design of the final PDF.$cfdi()-&gt;**toPdf(options)**Params: **Object** - [PdfOptions](#pdfoptions)
Returns: **Pdf** - **Instance**
An instance of the Pdf class, which, when invoked, converts the CFDI into a PDF and stores it, along with the generated data from the conversion request.##### PdfOptions

[](#pdfoptions)

```
[
	"style_pdf"=>"John"
]
```

### Pdf

[](#pdf)

The `$pdf` object is an instance of `Pdf`, created from `$cfdi->toPdf(options)`.

MethodDescription$pdf-&gt;**toBuffer()**Returns: **Buffer**
The PDF document as a buffer, ready for storage in the file system or to be sent back in an HTTP request.$pdf-&gt;**getTransactionId()**Returns: **String - UUID**
A unique ID for the transaction request to the redoc service.$pdf-&gt;**getTotalPages()**Returns: **Integer**
The total number of pages generated for the PDF file.$pdf-&gt;**getTotalTimeMs()**Returns: **Integer**
Time in milliseconds taken to convert the CFDI to PDF.$pdf-&gt;**getMetadata()**Returns: **Object** - CfdiMetadata
General information from the converted CFDI.##### CfdiMetadata

[](#cfdimetadata)

```
[
    TDB...
]
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs, features, or improvements.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

769d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cbeaa1458652cd9a7d2da4953ac3517532aba6618c2be6bbcc9ffbfda4d9025f?d=identicon)[redocmx](/maintainers/redocmx)

---

Top Contributors

[![danioso](https://avatars.githubusercontent.com/u/1430937?v=4)](https://github.com/danioso "danioso (1 commits)")[![daviosoo](https://avatars.githubusercontent.com/u/80079750?v=4)](https://github.com/daviosoo "daviosoo (1 commits)")[![trf-aosorio](https://avatars.githubusercontent.com/u/131190835?v=4)](https://github.com/trf-aosorio "trf-aosorio (1 commits)")

---

Tags

cfdimexicocfdi a pdfcfdi to pdfconversión cfdi a pdfsat mexico

### Embed Badge

![Health badge](/badges/redocmx-client-php/health.svg)

```
[![Health](https://phpackages.com/badges/redocmx-client-php/health.svg)](https://phpackages.com/packages/redocmx-client-php)
```

###  Alternatives

[eclipxe/cfdiutils

PHP Common utilities for Mexican CFDI 3.2, 3.3 &amp; 4.0

141129.9k6](/packages/eclipxe-cfdiutils)[phpcfdi/cfdi-sat-scraper

Web Scraping para extraer facturas electrónicas desde la página del SAT

9018.0k](/packages/phpcfdi-cfdi-sat-scraper)[phpcfdi/cfditopdf

Create a generic PDF file from a CFDI 3.3 &amp; 4.0 (CLI included)

4144.3k4](/packages/phpcfdi-cfditopdf)[phpcfdi/sat-ws-descarga-masiva

Librería para usar el servicio web del SAT de Descarga Masiva

16663.6k3](/packages/phpcfdi-sat-ws-descarga-masiva)[phpcfdi/cfdi-to-json

Convert CFDI to JSON

3120.0k2](/packages/phpcfdi-cfdi-to-json)[phpcfdi/credentials

Library to use eFirma (fiel) and CSD (sellos) from SAT

83152.0k7](/packages/phpcfdi-credentials)

PHPackages © 2026

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