KAPOW

Would you like to react to this message? Create an account in a few clicks or log in to continue.
KAPOW

Welcome to the Kapow forum. Here you can get help, use your skills to help others and enjoy hanging out in the company of other Kapow Robot Developers.


4 posters

    PDF saved as byte array - converting back to PDF

    avatar
    MikkelKristensen


    Posts : 1
    Points : 1145
    Join date : 2019-12-12

    PDF saved as byte array - converting back to PDF Empty PDF saved as byte array - converting back to PDF

    Post by MikkelKristensen Thu Feb 04, 2021 3:05 pm

    Hi, 
    I get a JSON-stream and in this stream there is some PDF-documents saved as byte arrays, that I need to download.

    So I need to convert the array back to a PDF.
    I think I've tried almost everything, but it doesn't work for me. So I'm probably missing the obvious.

    Can you help me?

    The JSON:
    PDF saved as byte array - converting back to PDF Docume11


    Part of the byte array:
    PDF saved as byte array - converting back to PDF Docume10
    avatar
    mikko_k


    Posts : 2
    Points : 1584
    Join date : 2018-09-28

    PDF saved as byte array - converting back to PDF Empty Re: PDF saved as byte array - converting back to PDF

    Post by mikko_k Wed Feb 24, 2021 8:06 pm

    If you manage to extract the whole bytearray to a long text variable (without commas) it should allready be a binary content you can just assign to pdf variable
    jking
    jking


    Posts : 103
    Points : 3395
    Join date : 2014-03-01
    Location : USA

    PDF saved as byte array - converting back to PDF Empty Re: PDF saved as byte array - converting back to PDF

    Post by jking Thu Apr 01, 2021 9:22 pm

    You may need to Decode FileContent.  I have an API that contains the content in Bytes.  I have a Convert Variables step to convert contentBytes to PDF Variable with a Base64 decode Converter.
    avatar
    sathishmail89


    Posts : 2
    Points : 1196
    Join date : 2019-10-23

    PDF saved as byte array - converting back to PDF Empty Re: PDF saved as byte array - converting back to PDF

    Post by sathishmail89 Wed May 18, 2022 5:37 pm

    Create the longText variable and Extract the data into longText Variable.
    Use Execute Javascript step and custom javascript with expression.

    >>           
    function byte2base64( buffer ) {
        var binary = '';
        var bytes = new Uint8Array( buffer );
        var len = bytes.byteLength;
        for (var i = 0; i < len; i++) {
            binary += String.fromCharCode( bytes[ i ] );
        }
        return window.btoa( binary );
    }
    var bytes = byte2base64(<<+longText+>>);
    var pdfUrl = "data:application/pdf;base64,"+bytes;
    window.open(pdfUrl);<<

    Sponsored content


    PDF saved as byte array - converting back to PDF Empty Re: PDF saved as byte array - converting back to PDF

    Post by Sponsored content


      Current date/time is Fri Jan 27, 2023 6:06 pm