|
1 | | -# Installation |
| 1 | +# Comprehensive Installation Guide |
2 | 2 |
|
3 | | -## Requirements |
| 3 | +This guide details how to install the necessary system dependencies for PDFLib v3.1 on **macOS**, **Ubuntu/Debian**, and **Windows**. |
4 | 4 |
|
5 | | -* **PHP**: 8.1 or higher |
6 | | -* **Composer** |
| 5 | +## 1. PHP & Extensions |
7 | 6 |
|
8 | | -### Driver Dependencies |
9 | | -PDFLib acts as a bridge to powerful system binaries. You only need to install the tools for the features you intend to use. |
| 7 | +**Requirement**: PHP >= 8.1 |
10 | 8 |
|
11 | | -| feature | Driver | Requirement | |
12 | | -| :--- | :--- | :--- | |
13 | | -| **Manipulation** (Merge, Split, Convert) | `GhostscriptDriver` | **Ghostscript** (v9.16+) | |
14 | | -| **HTML to PDF** | `ChromeHeadlessDriver` | **Google Chrome** or **Chromium** | |
15 | | -| **Digital Signatures** | `OpenSslDriver` | **PHP OpenSSL** & `tecnickcom/tcpdf` | |
16 | | -| **Form Filling** | `PdftkDriver` | **pdftk** (PDF Toolkit) | |
| 9 | +### macOS (Homebrew) |
| 10 | +```bash |
| 11 | +brew install php |
| 12 | +``` |
| 13 | + |
| 14 | +### Ubuntu / Debian |
| 15 | +```bash |
| 16 | +sudo apt update |
| 17 | +sudo apt install php8.1 php8.1-cli php8.1-mbstring php8.1-xml php8.1-zip |
| 18 | +``` |
| 19 | + |
| 20 | +### Windows |
| 21 | +1. Download the **Non-Thread Safe (NTS)** version from [windows.php.net](https://windows.php.net/download/). |
| 22 | +2. Extract to `C:\php`. |
| 23 | +3. Add `C:\php` to your System PATH environment variable. |
17 | 24 |
|
18 | 25 | --- |
19 | 26 |
|
20 | | -## 1. Install via Composer |
| 27 | +## 2. Driver Dependencies |
21 | 28 |
|
22 | | -```bash |
23 | | -composer require imal-h/pdf-box |
24 | | -``` |
| 29 | +You only need to install the tools for the drivers you intend to use. |
25 | 30 |
|
26 | | -## 2. Install System Binaries |
| 31 | +| Feature | Driver | Requirement | |
| 32 | +| :--- | :--- | :--- | |
| 33 | +| **Manipulation** | `GhostscriptDriver` | [Ghostscript](#21-ghostscript) | |
| 34 | +| **HTML to PDF** | `ChromeHeadlessDriver` | [Google Chrome](#22-google-chrome--chromium) | |
| 35 | +| **Form Filling** | `PdftkDriver` | [PDFtk](#23-pdftk-server) | |
| 36 | +| **OCR** | `TesseractDriver` | [Tesseract](#24-tesseract-ocr) | |
| 37 | +| **Signatures** | `OpenSslDriver` | OpenSSL (Built-in to PHP) | |
27 | 38 |
|
28 | | -### macOS (Homebrew) |
| 39 | +### 2.1 Ghostscript |
| 40 | +*Required for: Merge, Split, Convert, Compress, Flatten, Redact.* |
| 41 | + |
| 42 | +**Version**: 9.16 or higher |
| 43 | + |
| 44 | +#### macOS |
29 | 45 | ```bash |
30 | | -# Ghostscript |
31 | 46 | brew install ghostscript |
| 47 | +``` |
| 48 | + |
| 49 | +#### Ubuntu / Debian |
| 50 | +```bash |
| 51 | +sudo apt install ghostscript |
| 52 | +``` |
| 53 | + |
| 54 | +#### Windows |
| 55 | +1. Download `Ghostscript AGPL Release` from [ghostscript.com](https://www.ghostscript.com/releases/gsdnld.html). |
| 56 | +2. Install the package. |
| 57 | +3. **Critical**: Add the `bin` and `lib` folders to your PATH (e.g., `C:\Program Files\gs\gs9.55.0\bin`). |
| 58 | +4. PDFLib looks for `gswin64c.exe` automatically. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### 2.2 Google Chrome / Chromium |
| 63 | +*Required for: HTML to PDF conversion.* |
32 | 64 |
|
33 | | -# Chrome (usually already installed, or install Chromium) |
| 65 | +#### macOS |
| 66 | +```bash |
34 | 67 | brew install --cask google-chrome |
| 68 | +# OR |
| 69 | +brew install chromium |
| 70 | +``` |
| 71 | + |
| 72 | +#### Ubuntu / Debian |
| 73 | +```bash |
| 74 | +# Install stable Chrome |
| 75 | +wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb |
| 76 | +sudo apt install ./google-chrome-stable_current_amd64.deb |
| 77 | +``` |
35 | 78 |
|
36 | | -# PDFtk |
| 79 | +#### Windows |
| 80 | +Standard installation of Google Chrome is sufficient. PDFLib will auto-detect it in standard `Program Files` locations. |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +### 2.3 PDFtk Server |
| 85 | +*Required for: Form Filling and Inspection.* |
| 86 | + |
| 87 | +#### macOS |
| 88 | +```bash |
37 | 89 | brew install pdftk-java |
38 | 90 | ``` |
39 | 91 |
|
40 | | -### Ubuntu / Debian |
| 92 | +#### Ubuntu / Debian |
41 | 93 | ```bash |
42 | | -# Ghostscript |
43 | | -sudo apt-get update |
44 | | -sudo apt-get install ghostscript |
| 94 | +sudo apt install pdftk |
| 95 | +``` |
45 | 96 |
|
46 | | -# Chrome (install stable) |
47 | | -wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb |
48 | | -sudo apt install ./google-chrome-stable_current_amd64.deb |
| 97 | +#### Windows |
| 98 | +1. Download **PDFtk Server** from [pdflabs.com](https://www.pdflabs.com/tools/pdftk-server/). |
| 99 | +2. Run the installer. |
| 100 | +3. Ensure "Add application to your system path" is checked during installation. |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +### 2.4 Tesseract OCR |
| 105 | +*Required for: Text Extraction (OCR).* |
49 | 106 |
|
50 | | -# PDFtk |
51 | | -sudo apt-get install pdftk |
| 107 | +#### macOS |
| 108 | +```bash |
| 109 | +brew install tesseract |
52 | 110 | ``` |
53 | 111 |
|
54 | | -### Windows |
55 | | -* **Ghostscript**: Download installer from [ghostscript.com](https://www.ghostscript.com/download.html). Add `gswin64c.exe` to your PATH. |
56 | | -* **Chrome**: Standard installation. |
57 | | -* **PDFtk**: Download from [pdflabs.com](https://www.pdflabs.com/tools/pdftk-server/). |
| 112 | +#### Ubuntu / Debian |
| 113 | +```bash |
| 114 | +sudo apt install tesseract-ocr |
| 115 | +``` |
| 116 | + |
| 117 | +#### Windows |
| 118 | +1. Download the installer from the [UB-Mannheim Tesseract Wiki](https://github.com/UB-Mannheim/tesseract/wiki). |
| 119 | +2. Install and add the install directory to your PATH. |
58 | 120 |
|
59 | 121 | --- |
60 | 122 |
|
61 | | -## 3. Configuration |
| 123 | +## 3. Configuration (Optional) |
62 | 124 |
|
63 | | -By default, PDFLib attempts to autodetect binaries in common paths. If your environment uses custom paths, pass them to the Driver constructor. |
| 125 | +PDFLib tries to find these binaries automatically. If you have installed them in non-standard locations, you can explicitly configure paths in `config/pdflib.php` (for Laravel) or pass them to the Driver. |
64 | 126 |
|
65 | 127 | ```php |
66 | | -use ImalH\PDFLib\Drivers\GhostscriptDriver; |
67 | | -use ImalH\PDFLib\PDF; |
68 | | - |
69 | | -// Custom Path Example |
70 | | -$driver = new GhostscriptDriver('/custom/path/to/gs'); |
71 | | -$pdf = new PDF($driver); |
| 128 | +// Manual Driver Configuration |
| 129 | +$driver = new \ImalH\PDFLib\Drivers\GhostscriptDriver( |
| 130 | + binaryPath: '/custom/path/to/gs' |
| 131 | +); |
72 | 132 | ``` |
0 commit comments