Fix FPDF error: Change PDF version using Ghostscript through PHP

Jerry Chen
3 min readMar 20, 2020

--

As the number of PDF versions increases, using PHP to merge PDFs results in the error message “FPDF error: This document PDF probably uses a compression technique which is not supported by the free parser shipped with FPDI.” This means that the PDF Plugin cannot parse FPDI and needs to convert the PDF version through Ghostscript to solve the problem.

Installation Steps

1. Download Ghostscript.
2. Install Ghostscript.
3. On Windows, set the environment variable PATH to “C:\gs\gs9.50\bin\gswin64c”.
4. In CMD, input “gs”, “gswin32c”, or “gswin64c” (varies by downloaded version) to test for successful installation.
5. You can package Ghostscript commands on your own or use composer to install the PHP package (ordinary9843/ghostscript).

ordinary9843/ghostscript (Recommend)

use Ordinary9843\Ghostscript;

$binPath = '/usr/bin/gs';
$tmpPath = sys_get_temp_dir();
$ghostscript = new Ghostscript($binPath, $tmpPath);
$ghostscript->convert($file, 1.4);

Linux

/usr/local/bin/gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new.pdf old.pdf

Windows

C:\gs\gs9.50\bin\gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new.pdf old.pdf

--

--

Jerry Chen
Jerry Chen

No responses yet