4 Replies Latest reply on Dec 22, 2017 2:42 AM by amirtha_rajan

    Generate pdf from a blob data




      with my PhoneGap app I make an ajax call to a backend service that generates a pdf file and returns a stream of these binary data . It is possible generate and save a pdf file on my device with this data. There is a special plugin ?




        • 1. Re: Generate pdf from a blob data
          VectorP Level 4

          Do you really want to re-generate a pdf locally, if the server already creates a pdf file?

          You can download it from the server using the Download method of cordova-plugin-file-transfer

          • 2. Re: Generate pdf from a blob data
            likusoft Level 1



            This ajax call:


            var xhr = new XMLHttpRequest();

            xhr.open('GET', appPb.proxyUrl+"stampaaltro?idLancio="+id+"&isXls="+isXls+"&rpt="+tipo_report, true);


            // Hack to pass bytes through unprocessed.

            xhr.overrideMimeType('text/plain; charset=x-user-defined');


            xhr.onreadystatechange = function(e) {

              if (this.readyState == 4 && this.status == 200) {

                var binStr = this.responseText;


                for (var i = 0, len = binStr.length; i < len; ++i) {

                  var c = binStr.charCodeAt(i);

                  //String.fromCharCode(c & 0xff);


                   result = c & 0xff;  // byte at offset i









            returns the following binary data like (like a pdf)


            IT IS POSSIBLE create a file with the extension pdf






            5 0 obj

            <</Length 6 0 R/Filter /FlateDecode>>


            xWM6 WR@ l3>&m"[d7n/E lUl %Q )n7 = 4! K)K B{[/P5C ["C  ! _* Br}_TO|V wbWq.8   Rm5 k} `J (|[ _ H/\0bjW\<_

            Jn6 ab

            p[ +&9 wCZy g.

            4 2z Z 'lu}t)'UuSC! a S


            q VH"ba^Cs<m m=m?4w] xl 6]n Mst5

            S  [  Z r  )9I @Q 1  S 4dJ    e2E`1\gN(P Cz 

            LAl 0

            hM n2? R IZhG{SN(  

            +<_oH  ^ c)^

            E0X9CR  1$ ,aa;X7qH :.7u.]q?yP 9SKz rDPv   r RJ 2wa'WW E`  5))T5k dRq=Y- GPjw+fM

            3 lY<K    i+= I{KoJ H  > /b1`W_T1h `T1=   B8+{\*68dgFI [g(J  cX4uL" .

            • 3. Re: Generate pdf from a blob data
              VectorP Level 4

              Well, you could store the stream data using the File plugin (not as pdf, but simply as raw data), then display the data using a data URI.

              See for instance: jquery - How to build PDF file from binary string returned from a web-service using javascript - Stack Overflow

              • 4. Re: Generate pdf from a blob data

                have the same problem, did you get any solution ??