Open PDF in new browser full window

后端 未结 4 768
日久生厌
日久生厌 2020-12-13 14:16

How do I open PDF document in new browser window?

The window should be full and withouth menu.

Just a PDF document in a clean full window with native Javasc

4条回答
  •  抹茶落季
    2020-12-13 14:50

    To do it from a Base64 encoding you can use the following function:

    function base64ToArrayBuffer(data) {
      const bString = window.atob(data);
      const bLength = bString.length;
      const bytes = new Uint8Array(bLength);
      for (let i = 0; i < bLength; i++) {
          bytes[i] = bString.charCodeAt(i);
      }
      return bytes;
    }
    function base64toPDF(base64EncodedData, fileName = 'file') {
      const bufferArray = base64ToArrayBuffer(base64EncodedData);
      const blobStore = new Blob([bufferArray], { type: 'application/pdf' });
      if (window.navigator && window.navigator.msSaveOrOpenBlob) {
          window.navigator.msSaveOrOpenBlob(blobStore);
          return;
      }
      const data = window.URL.createObjectURL(blobStore);
      const link = document.createElement('a');
      document.body.appendChild(link);
      link.href = data;
      link.download = `${fileName}.pdf`;
      link.click();
      window.URL.revokeObjectURL(data);
      link.remove();
    }
    

提交回复
热议问题