На основе http://www.infoconic.com/blog/trick-for-fpdi-pdf-parser-that-supports-pdf-version-above-1-4/
Сделал вот так:
function convert_to_1_4($srcfile)
{
// Report all errors
error_reporting(E_ALL);
ini_set('display_errors', true);
$temp="C:/VirtHoshs/temp/files";
if (!file_exists($temp)) mkdir($temp);
// Generate random number and store in $random variable
$random = rand(1,10000);
// new path of new pdf file created by ghostscript if file above 1.4
$srcfile_new = $temp.'/'.$random.basename($srcfile);
// read pdf file first line because pdf first line contains pdf version information
$handle = fopen($srcfile, 'r');
if (!$handle) {
die("Не удалось открыть файл: $srcfile");
}
$line_first = fgets($handle);
fclose($handle);
// extract number such as 1.4,1.5 from first read line of pdf file
if (!preg_match('/%PDF-(\d\.\d)/', $line_first, $matches)) {
die("Не удалось определить версию PDF.");
}
$pdfversion = (float)$matches[1];
// compare that number from 1.4(if greater than proceed with ghostscript)
if($pdfversion > 1.4){
// USE GHOSTSCRIPT IF PDF VERSION ABOVE 1.4 AND SAVE ANY PDF TO VERSION 1.4 , SAVE NEW PDF OF 1.4 VERSION TO NEW PATH
$cmd = "gswin64c.exe -dBATCH -dNOPAUSE -q -dCompatibilityLevel=1.4 -sDEVICE=pdfwrite -sOutputFile=\"$srcfile_new\" \"$srcfile\" 2>&1";
$output = shell_exec($cmd);
if (!file_exists($srcfile_new)) {
error_log("Ghostscript failed: $output");
die("Не удалось конвертировать PDF. Проверьте логи.");
}
$srcfile=$srcfile_new;
}
return($srcfile);
}
$pagecount = $mpdf->SetSourceFile($this->convert_to_1_4($realFilePath));