Base64 file

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;
    }


    Here are the accepted datatypes for the Open() method for GcPdfViewer.

    https://www.grapecity.com/documents-api-pdfviewer/api/classes/gcpdfviewer.html#open

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels