diff --git a/mod/assign/feedback/editpdf/classes/pdf.php b/mod/assign/feedback/editpdf/classes/pdf.php index 612d00007a9..baf5b954476 100644 --- a/mod/assign/feedback/editpdf/classes/pdf.php +++ b/mod/assign/feedback/editpdf/classes/pdf.php @@ -710,7 +710,7 @@ class pdf extends TcpdfFpdi { } /** - * Check to see if PDF is version 1.4 (or below); if not: use ghostscript to convert it + * Flatten and convert file using ghostscript then load pdf. * * @param string $tempsrc The path to the file on disk. * @return string path to copy or converted pdf (false == fail) @@ -718,28 +718,15 @@ class pdf extends TcpdfFpdi { public static function ensure_pdf_file_compatible($tempsrc) { global $CFG; - $pdf = new pdf(); - $pagecount = 0; - try { - $pagecount = $pdf->load_pdf($tempsrc); - } catch (\Exception $e) { - // PDF was not valid - try running it through ghostscript to clean it up. - $pagecount = 0; - } - $pdf->Close(); // PDF loaded and never saved/outputted needs to be closed. - - if ($pagecount > 0) { - // PDF is already valid and can be read by tcpdf. - return $tempsrc; - } - $temparea = make_request_directory(); $tempdst = $temparea . "/target.pdf"; $gsexec = \escapeshellarg($CFG->pathtogs); $tempdstarg = \escapeshellarg($tempdst); $tempsrcarg = \escapeshellarg($tempsrc); - $command = "$gsexec -q -sDEVICE=pdfwrite -dSAFER -dBATCH -dNOPAUSE -sOutputFile=$tempdstarg $tempsrcarg"; + $command = "$gsexec -q -sDEVICE=pdfwrite -dPreserveAnnots=false -dSAFER -dBATCH -dNOPAUSE " + . "-sOutputFile=$tempdstarg $tempsrcarg"; + exec($command); if (!file_exists($tempdst)) { // Something has gone wrong in the conversion.