diff --git a/action.php b/action.php
index 5edbb9e47bcafabc73c102cf872853822b9fef72..2ad2957d6e69f45782e50427524fdc142c2f871e 100644
--- a/action.php
+++ b/action.php
@@ -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]);
-
}
}
diff --git a/locallib.php b/locallib.php
index 0bbd5bc3f4508fe535c6cbc0550fcca88f53799a..c9534c004b66e7be99d2f589f021822a180b07ca 100644
--- a/locallib.php
+++ b/locallib.php
@@ -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;
diff --git a/shared/index.js b/shared/index.js
index b37df0b71b9ed01969f5d6962ee927b9b1c4abbe..0b885d02dec669bb3d8de08262a47059015f623b 100644
--- a/shared/index.js
+++ b/shared/index.js
@@ -857,29 +857,28 @@ 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);
- }
- var width = data['imagewidth'] * 0.264583333333334;
- while ( width > (a4width-(contentLeftMargin+contentRightMargin)) ) {
- width = width - (width*0.1);
- }
- if ( (count+height) >= a4height ) {
- doc.addPage();
- count = contentTopBottomMargin;
+ // Reduce height and witdh if its size more than a4height.
+ while ( height > (a4height-(2*contentTopBottomMargin) )) {
+ height = height - (height*0.1);
+ }
+ var width = data['imagewidth'] * 0.264583333333334;
+ while ( width > (a4width-(contentLeftMargin+contentRightMargin)) ) {
+ width = width - (width*0.1);
+ }
+ if ( (count+height) >= a4height ) {
+ doc.addPage();
+ count = contentTopBottomMargin;
+ }
+ 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);
}
- 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);
}
/**
* Take an image, calculate its height in millimeters and print it on the pdf
diff --git a/version.php b/version.php
index 3364f24d1ff45880b6b682ecc2d6ea4ad4df274a..1790e6aaeb2cd8f238ef7441a155d665abc7b724 100644
--- a/version.php
+++ b/version.php
@@ -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;