How to build PDF file from binary string returned from a web-service using javascript

后端 未结 8 1638
悲哀的现实
悲哀的现实 2020-11-22 14:33

I am trying to build a PDF file out of a binary stream which I receive as a response from an Ajax request.

Via XmlHttpRequest I receive the following da

相关标签:
8条回答
  • 2020-11-22 15:14

    The answer of @alexandre with base64 does the trick.

    The explanation why that works for IE is here

    https://en.m.wikipedia.org/wiki/Data_URI_scheme

    Under header 'format' where it says

    Some browsers (Chrome, Opera, Safari, Firefox) accept a non-standard ordering if both ;base64 and ;charset are supplied, while Internet Explorer requires that the charset's specification must precede the base64 token.

    0 讨论(0)
  • 2020-11-22 15:18

    I work in PHP and use a function to decode the binary data sent back from the server. I extract the information an input to a simple file.php and view the file through my server and all browser display the pdf artefact.

    <?php
       $data = 'dfjhdfjhdfjhdfjhjhdfjhdfjhdfjhdfdfjhdf==blah...blah...blah..'
    
       $data = base64_decode($data);
        header("Content-type: application/pdf");
        header("Content-Length:" . strlen($data ));
        header("Content-Disposition: inline; filename=label.pdf");
        print $data;
        exit(1);
    
    ?>
    
    0 讨论(0)
提交回复
热议问题