Skip to content
Snippets Groups Projects
Commit 5708cc9c authored by anisa kusumadewi's avatar anisa kusumadewi
Browse files

bug fix: extern pic without heigt/width

parent e4cf3694
Branches
No related tags found
No related merge requests found
......@@ -642,7 +642,6 @@ if ($action === 'getCommentsToPrint') {
$newdata = $templatable->export_for_template($myrenderer);// Viewcontroller takes model's data and arranges it for display.
echo json_encode(['status' => 'success', 'pdfannotatorid' => $documentid, 'newdata' => $newdata]);
}
}
......@@ -64,7 +64,7 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
// Load and execute the javascript files.
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/pdf.js?ver=00002"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/textclipper.js"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/index.js?ver=00034"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/index.js?ver=00035"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00005"));
// Pass parameters from PHP to JavaScript.
......@@ -227,21 +227,22 @@ function pdfannotator_split_content_image($content, $res, $itemid, $context=null
$data['filepath'] = $tempinfo['filepath'];
$data['filesize'] = $tempinfo['filesize'];
$data['imagestorage'] = 'intern';
preg_match('/height=[0-9]+/', $imgstr, $height);
$data['imageheight'] = str_replace("\"", "", explode('=', $height[0])[1]);
preg_match('/width=[0-9]+/', $imgstr, $width);
$data['imagewidth'] = str_replace("\"", "", explode('=', $width[0])[1]);
} else if (!str_contains($CFG->wwwroot, $url[0])){
$data['imagestorage'] = 'extern';
$data['format'] = $format[0];
$imagemetadata = getimagesize($url[0]);
$data['image'] = 'data:image/' . $format[0] . ";base64," . base64_encode(file_get_contents($url[0]));
// $data['image'] = $url[0];
$data['imagewidth'] = $imagemetadata[0];
$data['imageheight'] = $imagemetadata[1];
} else {
$data['success'] = "error";
$data['message'] = "cannot load image";
}
preg_match('/height=[0-9]+/', $imgstr, $height);
$data['imageheight'] = str_replace("\"", "", explode('=', $height[0])[1]);
preg_match('/width=[0-9]+/', $imgstr, $width);
$data['imagewidth'] = str_replace("\"", "", explode('=', $width[0])[1]);
$res[] = $firststr;
$res[] = $data;
$content = $laststr;
......
......@@ -857,15 +857,10 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
function printImage(data) {
var url;
var image;
// if (data['imagestorage'] === 'extern') {
// url = data['image'];
// image = document.createElement("img");
// image.setAttribute('crossOrigin', 'anonymous');
// image.src = url;
// } else {
if (data['success'] !== 'error') {
image = data['image'];
var height = data['imageheight'] * 0.264583333333334; // Convert pixel into mm.
// }
// Reduce height and witdh if its size more than a4height.
while ( height > (a4height-(2*contentTopBottomMargin) )) {
height = height - (height*0.1);
......@@ -880,6 +875,10 @@ function startIndex(Y,_cm,_documentObject,_contextId, _userid,_capabilities, _to
}
doc.addImage(image, data['format'], contentRightMargin, count, width, height); // image data, format, offset to the left, offset to the top, width, height
count += (5 + height);
} else {
let item = `<p>${data['message']}</p>`;
printTextblock(null, null, item);
}
}
/**
* Take an image, calculate its height in millimeters and print it on the pdf
......
......@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_pdfannotator';
$plugin->version = 2022110700;
$plugin->version = 2022110900;
$plugin->release = 'PDF Annotator v1.4 release 11';
$plugin->requires = 2021051700;
$plugin->maturity = MATURITY_STABLE;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment