title: How to to convert string response to ArrayBuffer?
body: <p>From server I am getting the pdf response as string format, Now on client side, I want to convert it into ArrayBuffer, So that we can change again in pdf.</p>
  
  <p>I am converting it into pdf, like following, <strong>but is not pdf is getting corrupted.</strong> </p>
  
  <pre><code>function str2ab(str) {
            var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
            var bufView = new Uint8Array(buf);
            for (var i=0, strLen=str.length; i &lt; strLen; i++) {
              bufView[i] = str.charCodeAt(i);
            }
            return buf;
      }
  </code></pre>
  
  <p>Above function I got from <a href="https://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers">stackover flow</a>, I change Uint16Array to Uint8Array, pdfkit uses utf-8 uncode formate..</p>
  
  <pre><code>service.getAddress(reqData).then(function(response){
                  if(response.data.error ===1){
                      toastr.error(response.data.message ,"Unsuccessful");
                  }else{
  
  
  
                      var uintStr = str2ab(response.data);
                      var file = new Blob([uintStr], {
                          type : 'application/pdf'
                      });
                      //trick to download store a file having its URL
                      var fileURL = URL.createObjectURL(file);
                      var a         = document.createElement('a');
                      a.href        = fileURL;
                      a.target      = '_blank';
                      a.download    = envelopeObj.customer_name+'_'+ 'envId_'+envelopeObj.envelope_id+'.pdf';
                      document.body.appendChild(a);
                      a.click();
                  }
              });
  </code></pre>
  
  <p>To using pdf kit to convert it into string format.</p>
  
  <pre><code>add_str = render_to_string(address_template_path , {"address_dict": address_dict})
  pdfkit.from_string(add_str, file_location)
  
  address_pdf = open(file_location)
  response = HttpResponse(address_pdf.read(), content_type='application/pdf')  # Generates the response as pdf response.
  response['Content-Disposition'] = 'inline;filename= %s' % envelope_id
  </code></pre>