首页 > 解决方案 > 使用 javascript 将字节转换为 PDF

问题描述

我有一个 WSDL,它向我发送字节格式的 PDF,我想用 javascript 在新窗口中打开这个 PDF。问题是我无法将编码字节转换为 PDF。我尝试了这段代码,但它不起作用我不知道是不是因为我的 PDF 中有一张图片和一些行,或者这个版本适用于旧版浏览器。

var getReleveDoc = function(i) {
  var datas = {
    'service': 'relevePrest',
    'i': $('#idNumPersonne').val(),
    'n': $('#numRlv_td' + i).text(),
    'b': $('#numBatch_td' + i).text(),
    'e': $('#codeEntite').val()
  };

  $.get('./download',
    datas,
    function(data) {
      if (data.security) {
        location.reload();
      } else if (data.erreur) {
        erreur(data.erreur);
      } else {
        var blob = new Blob([data], {
          type: "application/pdf"
        });
        var link = window.URL.createObjectURL(blob);
        window.open(link, '', 'height=650,width=840');
      }

      ready();
    });
};

这是我生成的字节的一小部分

1.4
%����
1 0 obj
<<
/Keywords ()
/Creator (BdocPDF V5.3)
/Producer (Apache FOP Version svn-trunk)
/CreationDate (D:20200120134322+00'00')
>>
endobj
2 0 obj
<<
  /N 3
  /Length 3 0 R
  /Filter /FlateDecode
>>
stream
x���wTS��Ͻ7�P����khRH
�H�.*1  J�� "6DTpDQ��2(���C��"��Q��D�qp�Id�߼y�͛��~k����g�}ֺ ����LX  ��X��ň��g`� l �p��B�F�|،l���� ��*�?�� ����Y"1 P������\�8=W�%�Oɘ�4M�0J�"Y�2V�s�,[|��e9�2�&lt;�s��e���'��9���`���2�&amp;c�tI�@�o��|N6 (��.�sSdl-c�(2�-�y �H�_��/X������Z.$��&\S�������M����07�#�1ؙY�r f��Yym�";�8980m-m�(�]����v�^��D���W~�

标签: javascriptjquery

解决方案


推荐阅读