PHPackages                             rafaelcecchin/cups-printer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rafaelcecchin/cups-printer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rafaelcecchin/cups-printer
==========================

Simple CUPS printer

v1.0.0(1y ago)1111[3 issues](https://github.com/RafaelCecchin/cups-printer/issues)PHP

Since Jul 29Pushed 1y ago3 watchersCompare

[ Source](https://github.com/RafaelCecchin/cups-printer)[ Packagist](https://packagist.org/packages/rafaelcecchin/cups-printer)[ RSS](/packages/rafaelcecchin-cups-printer/feed)WikiDiscussions master Synced yesterday

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

cups-printer 🖨️
===============

[](#cups-printer-️)

After spending a lot of time searching for a simple solution to print files directly from PHP, I decided to create my own Composer library. 🚀

```
composer require rafaelcecchin/cups-printer
```

Initially, I thought it would be easier to find a solution that fits different environments, but I was mistaken. Many of the existing solutions for printing with CUPS + PHP are outdated, involve a lot of code, and overlook the fact that many developers use Windows for development and Linux for production environments. 🖥️➡️🐧

This project utilizes the CUPS command:

```
lp -h [printerServer] -d [printerName] [fileLocation]
```

"Okay, but what about the cases you mentioned, where I work with a Windows development environment and a Linux production environment?" 🌐

It will work too, and the solution is simpler than you might think. I'll explain more about this below. 👇

How to Use
----------

[](#how-to-use)

Here’s a code snippet demonstrating the functions of the library. 📜

```
use RafaelCecchin\CupsPrinter\CupsPrinter;

$printerServer = '192.168.0.100';
$printerName = 'L8360CDW-Rafael';

$printer = new CupsPrinter($printerServer, $printerName);

/* Print an existing file */
$fileLocation = '/var/docs/test.pdf';
$printer->printFile($fileLocation);

/* Save the content to a temporary file before printing */
$output = $pdf->output();
$printer->printData($output);

/* Save the buffer content to a temporary file before printing */
$print = $printer->obPrint(function () use ($pdf) {
    $pdf->stream("dompdf_out.pdf", array("Attachment" => false));
});
```

The only requirement is that the host must have cups-client installed. 🛠️

On Linux, you can run:

```
sudo apt-get update
sudo apt-get install cups-client
```

On Windows, one solution is to download Linux from the Windows Store. Yes, this is now possible through WSL technology. Just access the Windows Store, search for the Linux distribution you want, and install `cups-client` inside it.

In your project, you should create a class that extends `CupsPrinter` and, using polymorphism principles, override the `cmdPrintCommand` function. Here’s an example of how I did it. 🧩

```
use RafaelCecchin\CupsPrinter\CupsPrinter;

class Printer extends CupsPrinter
{
    function __construct(String $printerServer, String $printerName)
    {
        parent::__construct($printerServer, $printerName);
    }

    public function cmdPrintCommand(String $fileLocation)
    {
        $env = getenv('APP_ENV');
        $cmd = '';

        if ($env == 'DEV') {
            $cmd .= "ubuntu run ";
            $fileLocation = $this->convertWindowsPathToUnix($fileLocation);
        }

        $cmd .= "lp -h $this->printerServer -d $this->printerName $fileLocation";

        return $cmd;
    }

    private function convertWindowsPathToUnix(String $fileLocation)
    {
        $fileLocation = str_replace('\\', '/', $fileLocation);
        $fileLocation = preg_replace_callback(
            '/^([a-zA-Z]):/',
            function ($matches) {
                return '/mnt/' . strtolower($matches[1]);
            },
            $fileLocation
        );

        return $fileLocation;
    }
}
```

In this case, I downloaded Ubuntu from the Windows Store. To run a command inside it, I prepend `ubuntu run ` before the `lp` command and also adjust the file path to the Unix format, adding `/mnt/` before the drive letter.

Simple, right? 😎

I hope this solution makes sense to you! 😊

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

704d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/54079682?v=4)[Rafael Francisco Cecchin](/maintainers/RafaelCecchin)[@RafaelCecchin](https://github.com/RafaelCecchin)

---

Top Contributors

[![RafaelCecchin](https://avatars.githubusercontent.com/u/54079682?v=4)](https://github.com/RafaelCecchin "RafaelCecchin (7 commits)")

### Embed Badge

![Health badge](/badges/rafaelcecchin-cups-printer/health.svg)

```
[![Health](https://phpackages.com/badges/rafaelcecchin-cups-printer/health.svg)](https://phpackages.com/packages/rafaelcecchin-cups-printer)
```

PHPackages © 2026

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