Skip to content
Snippets Groups Projects
Commit 4ed4386b authored by Damyan Mitev's avatar Damyan Mitev :beach:
Browse files

Add new constructor to ImageData

parent 3019a9ba
No related branches found
No related tags found
1 merge request!90ability to attach visual signature on pdf document
......@@ -1495,6 +1495,9 @@ export class ImageData {
this.content = null; // Uint8Array: decoded content
this.contentBase64 = null; // string: base64 encoded content
if (typeof parameters === "string" || parameters instanceof String) {
this.fromDataURL(parameters);
} else
if (typeof parameters === "object") {
this.fromParameters(parameters);
}
......@@ -1517,13 +1520,24 @@ export class ImageData {
this.getContentBase64();
}
//fromDataURL()
fromDataURL(dataURL) {
if (dataURL.startsWith("data:")) {
const idx = dataURL.indexOf(";base64,");
if (idx > 0) {
this.contentType = dataURL.substring(5, idx); // 5 = len("data:")
this.contentBase64 = dataURL.substring(idx + 8); // 8 = len(";base64,")
}
}
}
//fromContentTypeAndContentAsByteArray()
toDataURL() {
return "data:" + this.contentType + ";base64," + this.getContentBase64();
}
/**
* @returns {ByteArray}
*/
getContent() {
if (!this.content) {
if (this.contentBase64) {
......@@ -1533,6 +1547,9 @@ export class ImageData {
return this.content;
}
/**
* @returns {String}
*/
getContentBase64() {
if (!this.contentBase64) {
if (this.content) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment