Hello! So, I need to assign a value to a variable inside a JS.
I have this script:
// JavaScript Document
function decode() {
// The Base64 string of a simple PDF file
var b64decode = 'WAPPLER VARIABLE'
// Decode Base64 to binary and show some information about the PDF file (note that I skipped all checks)
var bin = atob(b64decode);
console.log('File Size:', Math.round(bin.length / 1024), 'KB');
console.log('PDF Version:', bin.match(/^.PDF-([0-9.]+)/)[1]);
console.log('Create Date:', bin.match(/<xmp:CreateDate>(.+?)<\/xmp:CreateDate>/)[1]);
console.log('Modify Date:', bin.match(/<xmp:ModifyDate>(.+?)<\/xmp:ModifyDate>/)[1]);
console.log('Creator Tool:', bin.match(/<xmp:CreatorTool>(.+?)<\/xmp:CreatorTool>/)[1]);
// Embed the PDF into the HTML page and show it to the user
var obj = document.createElement('object');
obj.style.width = '100%';
obj.style.height = '842pt';
obj.type = 'application/pdf';
obj.data = 'data:application/pdf;base64,' + b64decode;
document.body.appendChild(obj);
// Insert a link that allows the user to download the PDF file
var link = document.createElement('a');
link.innerHTML = 'Download PDF file';
link.download = 'file.pdf';
link.href = 'data:application/octet-stream;base64,' + b64decode;
document.body.appendChild(link);
}
I need to set the b64decode variable from a binding.
I tried using flow (using global and assign) but it doesn’t work at all.
// JavaScript Document
function decode() {
// The Base64 string of a simple PDF file
var b64decode = dmx.parse("b64decode")
// Decode Base64 to binary and show some information about the PDF file (note that I skipped all checks)
var bin = atob(b64decode);
console.log('File Size:', Math.round(bin.length / 1024), 'KB');
console.log('PDF Version:', bin.match(/^.PDF-([0-9.]+)/)[1]);
console.log('Create Date:', bin.match(/<xmp:CreateDate>(.+?)<\/xmp:CreateDate>/)[1]);
console.log('Modify Date:', bin.match(/<xmp:ModifyDate>(.+?)<\/xmp:ModifyDate>/)[1]);
console.log('Creator Tool:', bin.match(/<xmp:CreatorTool>(.+?)<\/xmp:CreatorTool>/)[1]);
// Embed the PDF into the HTML page and show it to the user
var obj = document.createElement('object');
obj.style.width = '100%';
obj.style.height = '842pt';
obj.type = 'application/pdf';
obj.data = 'data:application/pdf;base64,' + b64decode;
document.body.appendChild(obj);
// Insert a link that allows the user to download the PDF file
var link = document.createElement('a');
link.innerHTML = 'Download PDF file';
link.download = 'file.pdf';
link.href = 'data:application/octet-stream;base64,' + b64decode;
document.body.appendChild(link);
}
decode-b64.js:7 Uncaught (in promise) DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
at decode (http://localhost:8888/liquidador/js/decode-b64.js:7:15)
at n.runJS (http://localhost:8888/liquidador/dmxAppConnect/dmxAppConnect.js:7:80925)
at n._execStep (http://localhost:8888/liquidador/dmxAppConnect/dmxAppConnect.js:7:37201)
at http://localhost:8888/liquidador/dmxAppConnect/dmxAppConnect.js:7:36691
The b64 code works fine when copied inside the JS directly.