Posted 11 July 2023, 1:21 pm EST
Gcpdfviewer is it possible to open a base64 string as a file pdf?
Forums Home / Document Solutions / Document Solutions for PDF
Posted by: nsilva on 11 July 2023, 1:21 pm EST
Posted 11 July 2023, 1:21 pm EST
Gcpdfviewer is it possible to open a base64 string as a file pdf?
Posted 12 July 2023, 3:40 am EST
Hi,
The issue is that the GcPdfViewer does not accept the base64 string. This should be converted to the Uint8Array. Please use the following working code snippet to test if it is working at your end or not.
let _base64 = base64_string;
window.onload = function(){
//GcPdfViewer.LicenseKey = "***key***";
let viewer = new GcPdfViewer("#viewer", {});
viewer.addDefaultPanels();
viewer.open(base64ToArrayBuffer(_base64));
}
function base64ToArrayBuffer(base64) {
var binaryString = atob(base64);
var bytes = new Uint8Array(binaryString.length);
for (var i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}
Regards,
Manish Gupta