| Línea 1031... |
Línea 1031... |
| 1031 |
* @param int|\assign $assignment Assignment
|
1031 |
* @param int|\assign $assignment Assignment
|
| 1032 |
* @param int $userid User ID
|
1032 |
* @param int $userid User ID
|
| 1033 |
* @param int $attemptnumber Attempt Number
|
1033 |
* @param int $attemptnumber Attempt Number
|
| 1034 |
* @param \stored_file $file file to save
|
1034 |
* @param \stored_file $file file to save
|
| 1035 |
* @param null|array $size size of image
|
1035 |
* @param null|array $size size of image
|
| 1036 |
* @return \stored_file
|
1036 |
* @return null|\stored_file
|
| 1037 |
* @throws \file_exception
|
1037 |
* @throws \file_exception
|
| 1038 |
* @throws \stored_file_creation_exception
|
1038 |
* @throws \stored_file_creation_exception
|
| 1039 |
*/
|
1039 |
*/
|
| 1040 |
private static function save_jpg_to_pdf($assignment, $userid, $attemptnumber, $file, $size=null) {
|
1040 |
private static function save_jpg_to_pdf($assignment, $userid, $attemptnumber, $file, $size=null) {
|
| 1041 |
// Temporary file.
|
1041 |
// Temporary file.
|
| Línea 1057... |
Línea 1057... |
| 1057 |
$pdf->setPrintFooter(false);
|
1057 |
$pdf->setPrintFooter(false);
|
| 1058 |
$pdf->setPrintHeader(false);
|
1058 |
$pdf->setPrintHeader(false);
|
| 1059 |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
1059 |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
| 1060 |
$pdf->AddPage($orientation);
|
1060 |
$pdf->AddPage($orientation);
|
| 1061 |
$pdf->SetAutoPageBreak(false);
|
1061 |
$pdf->SetAutoPageBreak(false);
|
| - |
|
1062 |
try {
|
| 1062 |
// Width has to be define here to fit into A4 page. Otherwise the image will be inserted with original size.
|
1063 |
// Width has to be defined here to fit into an A4 page, otherwise the image will be inserted with original size.
|
| 1063 |
if ($orientation == 'P') {
|
1064 |
if ($orientation == 'P') {
|
| 1064 |
$pdf->Image('@' . $file->get_content(), 0, 0, 210);
|
1065 |
$pdf->Image('@' . $file->get_content(), 0, 0, 210);
|
| 1065 |
} else {
|
1066 |
} else {
|
| 1066 |
$pdf->Image('@' . $file->get_content(), 0, 0, 297);
|
1067 |
$pdf->Image('@' . $file->get_content(), 0, 0, 297);
|
| - |
|
1068 |
}
|
| - |
|
1069 |
$pdf->setPageMark();
|
| - |
|
1070 |
$pdf->save_pdf($tempfile);
|
| - |
|
1071 |
} catch (\Exception $e) {
|
| - |
|
1072 |
// Trim off the binary image data in the exception message for debugging output.
|
| - |
|
1073 |
$exceptionmsg = strstr($e->getMessage(), '@', true) ?: $e->getMessage();
|
| - |
|
1074 |
debugging("Could not convert {$file->get_contenthash()} jpg to pdf: {$exceptionmsg}", DEBUG_ALL);
|
| - |
|
1075 |
return null;
|
| 1067 |
}
|
1076 |
}
|
| 1068 |
$pdf->setPageMark();
|
- |
|
| 1069 |
$pdf->save_pdf($tempfile);
|
- |
|
| 1070 |
$filearea = self::TMP_JPG_TO_PDF_FILEAREA;
|
1077 |
$filearea = self::TMP_JPG_TO_PDF_FILEAREA;
|
| 1071 |
$pdffile = self::save_file($assignment, $userid, $attemptnumber, $filearea, $tempfile);
|
1078 |
$pdffile = self::save_file($assignment, $userid, $attemptnumber, $filearea, $tempfile);
|
| 1072 |
if (file_exists($tempfile)) {
|
1079 |
if (file_exists($tempfile)) {
|
| 1073 |
unlink($tempfile);
|
1080 |
unlink($tempfile);
|
| 1074 |
rmdir($tmpdir);
|
1081 |
rmdir($tmpdir);
|