PHPackages                             vircom/apache-pdfbox - 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. vircom/apache-pdfbox

ActiveLibrary

vircom/apache-pdfbox
====================

PHP Apache PDFBox library wrapper

1.0.0(6y ago)27MITPHPPHP ^7.4CI failing

Since May 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/vircom/apache-pdfbox)[ Packagist](https://packagist.org/packages/vircom/apache-pdfbox)[ Docs](http://vircom.pl)[ RSS](/packages/vircom-apache-pdfbox/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

vircom/apache-pdfbox
====================

[](#vircomapache-pdfbox)

---

[![Build Status](https://camo.githubusercontent.com/fac9dd9bcb0d487ac9c7cdc6eb1de6e698f2cb27374a0b7971dc366bd0b1f3bb/68747470733a2f2f7472617669732d63692e6f72672f766972636f6d2f6170616368652d706466626f782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vircom/apache-pdfbox)[![Coverage Status](https://camo.githubusercontent.com/efa4eb191627cfbecd7e1a999a203a06a6cd87596e5ed64c098e76bef1da0fa3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f766972636f6d2f6170616368652d706466626f782f62616467652e737667)](https://coveralls.io/github/vircom/apache-pdfbox)[![Latest Stable Version](https://camo.githubusercontent.com/b187298d61cab2d7c91c68962a8c268df540722769e070756f6caaa77ba29ee4/68747470733a2f2f706f7365722e707567782e6f72672f766972636f6d2f6170616368652d706466626f782f762f737461626c652e706e67)](https://packagist.org/packages/vircom/apache-pdfbox)[![Total Downloads](https://camo.githubusercontent.com/17308722dbd1c5911d357a151e1e8d9bed6eeaf81a63a9d27366f889c4f0d4d9/68747470733a2f2f706f7365722e707567782e6f72672f766972636f6d2f6170616368652d706466626f782f646f776e6c6f6164732e706e67)](https://packagist.org/vircom/apache-pdfbox)[![License](https://camo.githubusercontent.com/effce53305e259136afc7b6ac43e9504c572493bf52dcf4918f1bb5755fe3022/68747470733a2f2f706f7365722e707567782e6f72672f766972636f6d2f6170616368652d706466626f782f6c6963656e73652e706e67)](https://packagist.org/packages/vircom/apache-pdfbox)

This package provides an implementation to wrap Apache PDFBox command line tool functionality.

Prerequisites
=============

[](#prerequisites)

- PHP 7.4+ with enabled at last on of these functions: `exec`, `system`, `passthru`, `shell_exec`
- Java JRE 1.8+
- [pdfbox-app-2.0.9.jar](https://archive.apache.org/dist/pdfbox/2.0.9/pdfbox-app-2.0.9.jar)

Installation
============

[](#installation)

Install by composer
-------------------

[](#install-by-composer)

To install vircom/apache-pdfbox with Composer, run the following command:

```
$ composer require vircom/apache-pdfbox
```

You can see this library on [Packagist](https://packagist.org/packages/vircom/apache-pdfbox).

Composer installs autoloader at `./vendor/autoloader.php`. If you use vircom/apache-pdfbox in your php script, add:

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

Usage:
======

[](#usage)

Creating instance of library
----------------------------

[](#creating-instance-of-library)

```
use VirCom\ApachePDFBox\ApachePDFBoxServiceFactory;

$service = (new ApachePDFBoxServiceFactory())
    ->createService(
        '/path/to/java/interpreter',
        '/path/to/apache/pdfbox/binary/file/pdfbox-app-2.0.9.jar'
    );
```

Decrypt
-------

[](#decrypt)

```
use VirCom\ApachePDFBox\Command\DecryptCommand;

$service->execute(
    (new DecryptCommand(
        '/path/to/input/pdf/file.pdf',
        '/path/to/output/pdf/file.pdf'
    ))
    ->setAlias('alias') // The alias of the key in the certificate file (mandatory if several keys are available)
    ->setKeyStore('/path/to/certificate/file') // The KeyStore that holds the certificate
    ->setPassword('password') // The password to open the certificate and extract the private key from it
);
```

Encrypt
-------

[](#encrypt)

```
use VirCom\ApachePDFBox\Command\EncryptCommand;

$service->execute(
    (new EncryptCommand(
        '/path/to/input/pdf/file.pdf',
        '/path/to/output/pdf/file.pdf'
    ))
    ->setOwnerPassword('owner password') // Set the owner password (ignored if cert is set)
    ->setUserPassword('user password') // Set the user password (ignored if cert is set)
    ->setCertFile('/path/to/certificate/file') // Path to X.509 certificate
    ->setCanAssemble() // Set the assemble permission
    ->setCanExtractContent() // Set the extraction permission
    ->setCanExtractForAccessibility() // Set the extraction permission
    ->setCanFillInForm() // Set the fill in form permission
    ->setCanModify() // Set the modify permission
    ->setCanModifyAnnotations() // Set the modify annots permission
    ->setCanPrint() //  Set the print permission
    ->setCanPrintDegraded() // Set the print degraded permission
    ->setKeyLength(40 / 128 / 256) // The length of the key in bits (valid values: 40, 128 or 256 default is 40)
);
```

Extract images
--------------

[](#extract-images)

```
use VirCom\ApachePDFBox\Command\ExtractImagesCommand;

$service->execute(
    (new ExtractImagesCommand(
        '/path/to/input/pdf/file.pdf'
    ))
    ->setPassword('password') // Password to decrypt document
    ->setPrefix('prefix') // Image prefix (default to pdf name)
    ->setDirectJPEG() // Forces the direct extraction of JPEG/JPX images regardless of colorspace or masking
);
```

Extract text
------------

[](#extract-text)

```
use VirCom\ApachePDFBox\Command\ExtractTextCommand;

$service->execute(
    (new ExtractTextCommand(
        '/path/to/input/pdf/file.pdf',
        '/path/to/output/pdf/file.pdf'
    ))
    ->setPassword('password') // Password to decrypt document
    ->setEncoding('encoding') // UTF-8 (default) or ISO-8859-1, UTF-16BE, UTF-16LE, etc.
    ->setConsole() // Send text to console instead of file
    ->setHtml() // Output in HTML format instead of raw text
    ->setSort() // Sort the text before writing
    ->setIgnoreBeads() // Disables the separation by beads
    ->setDebug() // Enables debug output about the time consumption of every stage
    ->setStartPage(page number) // The first page to start extraction(1 based)
    ->setEndPage(page number) // The last page to extract(inclusive)
);
```

Overlay
-------

[](#overlay)

```
use VirCom\ApachePDFBox\Command\OverlayPDFCommand;

$service->execute(
    (new OverlayPDFCommand(
        '/path/to/input/pdf/file.pdf',
        '/path/to/output/pdf/file.pdf',
        '/path/to/overlay/pdf/file.pdf'
    ))
    ->setOdd('/path/to/overlay/odd/file.pdf') // Overlay file used for odd pages
    ->setEven('/path/to/overlay/even/file.pdf') // Overlay file used for even pages
    ->setFirst('/path/to/overlay/first/file.pdf') // Overlay file used for first page
    ->setLast('/path/to/overlay/last/file.pdf') // Overlay file used for last page
    ->setUseAllPages('/path/to/overlay/use-all-pages/file.pdf') // Overlay file used for overlay, all pages are used by simply repeating them
    ->setPage('page number /path/to/overlay/specific-page/file.pdf') // Overlay file used for the given page number, may occur more than once
    ->setPosition('foreground / background') // Where to put the overlay file: foreground or background
);
```

Merge
-----

[](#merge)

```
use VirCom\ApachePDFBox\Command\PDFMergerCommand;

$service->execute(
    (new PDFMergerCommand(
        [
            '/path/to/input/pdf/file1.pdf',
            '/path/to/input/pdf/file2.pdf',
        ]
        '/path/to/overlay/pdf/file.pdf'
    ))
);
```

Split
-----

[](#split)

```
use VirCom\ApachePDFBox\Command\PDFSplitCommand;

$service->execute(
    (new PDFSplitCommand(
        '/path/to/input/pdf/file.pdf'
    ))
    ->setPassword('password') // Password to decrypt document
    ->setSplit(split pages number) // Split after this many pages (default 1, if startPage and endPage are unset)
    ->setStartPage(start page number) // Start page
    ->setEndPage(end page number) // End page
    ->setOutputPrefix('output prefix') // Filename prefix for splitted files
);
```

To image
--------

[](#to-image)

```
use VirCom\ApachePDFBox\Command\PDFToImageCommand;

$service->execute(
    (new PDFToImageCommand(
        '/path/to/input/pdf/file.pdf'
    ))
    ->setPassword('password') // Password to decrypt document
    ->setFormat('format') // Image format: JPG, jpg, tiff, bmp, BMP, gif, GIF, WBMP, png, PNG, JPEG, JBIG2, tif, TIF, TIFF, jpeg, wbmp, jbig2
    ->setPrefix('prefix') // Filename prefix for image files
    ->setPage(page number) // The only page to extract (1-based)
    ->setStartPage(page number) // The first page to start extraction (1-based)
    ->setEndPage(page number) // The last page to extract (inclusive)
    ->setColor('color') // The color depth (valid: bilevel, gray, rgb, rgba)
    ->setDpi(dpi) // The DPI of the output image
    ->setCropbox(leftTop rightTop leftBottom rightBotton) // The page area to export
    ->setTime() // Prints timing information to stdout
);
```

From text
---------

[](#from-text)

```
use VirCom\ApachePDFBox\Command\TextToPDFCommand;

$service->execute(
    (new TextToPDFCommand(
        '/path/to/input/text/file.txt',
        '/path/to/overlay/pdf/file.pdf'
    ))
    ->setStandardFont('standard font name') // One of: Helvetica (default), Courier-Bold, Courier-BoldOblique, Times-Roman, Helvetica-Oblique, Courier-Oblique, Symbol, Times-Italic, Helvetica, Helvetica-Bold, Times-BoldItalic, ZapfDingbats, Times-Bold, Helvetica-BoldOblique, Courier
    ->setTtf('/path/to/ttf/file.ttf') //  The TTF font to use
    ->setFontSize(font size) // Default: 10
    ->setPageSize('page size') // One of: Letter (default), Legal, A0, A1, A2, A3, A4, A5, A6
    ->setLandscape() // Sets orientation to landscape
);
```

To DOC
------

[](#to-doc)

```
use VirCom\ApachePDFBox\Command\WriteDecodedDocCommand;

$service->execute(
    (new WriteDecodedDocCommand(
        '/path/to/input/pdf/file.pdf',
        '/path/to/output/doc/file.doc'
    ))
    ->setPassword('password') // Password to decrypt document
    ->setSkipImages() // Don't uncompress images
);
```

ResultObject
------------

[](#resultobject)

```
use VirCom\ApachePDFBox\Command\Result\CommandResult;

/** @var CommandResult $result */
$result = $service->execute(...);

$result->getCommandLine(); // Executed command line
$result->isSuccessful(); // Checks if the process ended successfully
$result->getOutput(); // Executed process output
$result->getErrorOutput(); // Executed process error output
$result-getExitCode(); // Executed process exit code status
$result->getExitCodeText(); // Executed process exit code status text
```

About
=====

[](#about)

Submitting bugs and feature requests
------------------------------------

[](#submitting-bugs-and-feature-requests)

Bugs and feature request are tracked on [GitHub](https://github.com/vircom/apache-pdfbox/issues)

License
-------

[](#license)

Monolog is licensed under the MIT License - see the `LICENSE` file for details

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

2204d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

apachepdfbox

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vircom-apache-pdfbox/health.svg)

```
[![Health](https://phpackages.com/badges/vircom-apache-pdfbox/health.svg)](https://phpackages.com/packages/vircom-apache-pdfbox)
```

###  Alternatives

[vaites/php-apache-tika

Apache Tika bindings for PHP: extracts text from documents and images (with OCR), metadata and more...

1171.5M2](/packages/vaites-php-apache-tika)[dflydev/apache-mime-types

Apache MIME Types

701.9M35](/packages/dflydev-apache-mime-types)[packaged/thrift

Apache Thrift

168.8M29](/packages/packaged-thrift)

PHPackages © 2026

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