Skip to content

ghostscript

Imal Perera edited this page Jan 2, 2026 · 1 revision

Ghostscript Driver

The GhostscriptDriver is the workhorse of PDFLib. It handles almost all manipulation tasks.

Usage

use ImalH\PDFLib\PDF;

// Initialize
$pdf = PDF::init()->driver(PDF::DRIVER_GHOSTSCRIPT);

Features

1. Convert to Image

Convert a PDF page (default: Page 1) to an image.

$pdf->from('doc.pdf')
    ->to('output.jpg')
    ->convert();

2. Merge PDFs

Combine multiple PDF files into one.

$pdf->merge([
    'cover.pdf',
    'content.pdf',
    'appendix.pdf'
], 'full_report.pdf');

3. Encrypt (Password Protect)

Add User/Owner passwords and restrict permissions.

$pdf->from('sensitive.pdf')
    ->encrypt('userPass123', 'ownerRules!', 'locked.pdf');

4. Compress

Optimize file size using Ghostscript's presets (screen, ebook, printer, prepress, default).

$pdf->compress('heavy.pdf', 'light.pdf', 'ebook');

Other Methods

  • rotate(int $degrees, string $dest): Rotate pages.
  • watermark(string $text, string $dest): Add text watermark.
  • split($range, string $dest): Extract pages (e.g., '1-5').
  • getFormFields / fillForm: Not Supported (Use PdftkDriver).

Clone this wiki locally