0

I generate a pdf using FPDF/FPDI from 2 PDFs, and I use ghostscript to always convert to version 1.4 my pdf, because users download and sign the pdf locally, thus changing the version (FPDF works with version up to 1.4). The problem is that it overwrites my first page, after i added 13 records (allways at 13 record). I post bellow my function. Please help.

$pdfI = new \setasign\Fpdi\Fpdi();
//$pdfI->SetMargins(0,0,0);
$pdfI->SetAutoPageBreak(false);
file_put_contents("C:/xampp/htdocs/survey_v1/temp/tempInstruireSuplimentara.pdf",$row['file']);
                
shell_exec( 'gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile="C:/xampp/htdocs/survey_v1/temp/temp2InstruireSuplimentara.pdf" "C:/xampp/htdocs/survey_v1/temp/tempInstruireSuplimentara.pdf"');
$pageCount = $pdfI->setSourceFile("C:/xampp/htdocs/survey_v1/temp/temp2InstruireSuplimentara.pdf");
CBroe
  • 91,630
  • 14
  • 92
  • 150
  • You are going to have to supply the original PDF file to look at, before it is sent through Ghostscript, you should also supply the back channel output (and turn **off*** -dQUIET so that Ghostscript tells you if there is a problem). You'll probably have to remove -dBATCH as well in order to even see the back channel. – KenS Jul 27 '22 at 07:05
  • thanks, i will try it and text you here – georgelaurentiu Jul 27 '22 at 09:14
  • The error is like that: "The following error were encountered at least once while processing this file: error executing PDF token **** This file had errors that where repaired or ignored. **** The file was produced by: **** >>>> FPDF 1.84 <<<< **** Please notify the author of the software that produced this **** file that it does not conform to Adobe's publised PDF **** specification. – georgelaurentiu Jul 27 '22 at 09:27
  • I checked it for version 1.4 of the file it works just fine, the problem is when converting last PDF from database (that has version >1.4) – georgelaurentiu Jul 27 '22 at 11:59
  • Well Ghostscript is telling you the PDF file it has been given as input is broken. That could be a bug in the PDF interpreter, or it could be that the file genuinely is broken. Without seeing the original PDF there's no way to tell. – KenS Jul 27 '22 at 13:22
  • I bypassed this message by installing a lower version of ghostscript gs9.18, but now gswin64 command does not have write permissions to folder temp to write the concatenated PDF. The message is like that "Failed to open stream no such file or directory in ..." – georgelaurentiu Jul 27 '22 at 20:47
  • I put a folder on the desktop and tried to give it write rights for everyone, still not get it working, also edited httpd-vhosts.conf, Options Indexes FollowSymLinks MultiViews AllowOverride all Order Deny,Allow Allow from all Require all granted – georgelaurentiu Jul 27 '22 at 21:07
  • $permissions = fileperms("C:/xampp/htdocs/survey_v1/temp"); $perm_value = sprintf("%o", $permissions); // Clearing the File Status Cache clearstatcache(); $myfile = "C:/xampp/htdocs/survey_v1/temp"; // checking whether the file is writable or not if(is_writable($myfile)) { echo ("$myfile file is writable and it has the following file permissions : $perm_value"); } else { echo ("$myfile file is not writable and it has the following file permissions : $perm_value"); } // Clearing the File Status Cache clearstatcache(); – georgelaurentiu Jul 28 '22 at 05:26
  • The script above return C:/xampp/htdocs/survey_v1/temp file is writable and it has the following file permissions : 40777 – georgelaurentiu Jul 28 '22 at 05:26
  • I very much doubt that permissions are a problem. "Failed to open stream no such file or directory" does not sound like a permissions problem, that would result in an invalidfileaccess error. Since you have not quoted the entire back channel text, and still have not provided a PDF file to inspect, there's really nothing more that can be said. You could also use the command shell instead of running a shell exec, and see what Ghostscript says then. – KenS Jul 28 '22 at 08:00
  • I solved using this line of code shell_exec('"C:/Program Files/gs/gs9.18/bin/gswin64c.exe" -sDEVICE=pdfwrite -dCompatibilityLevel="1.4" -dNOPAUSE -sOutputFile=C:/xampp/htdocs/survey_v1/temp/temp2InstruireSuplimentara.pdf C:/xampp/htdocs/survey_v1/temp/tempInstruireSuplimentara.pdf'.' 2>&1'); – georgelaurentiu Jul 28 '22 at 09:36

0 Answers0