Advertisement
toribio

pdfblob.html

Jul 29th, 2020
1,669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.84 KB | None | 0 0
  1. <html>
  2.  
  3.   <head>
  4.     <style>
  5.       body {
  6.         margin: 0;
  7.         overflow: hidden;
  8.       }
  9.       iframe {
  10.         overflow: auto;
  11.         border: none;
  12.         width: 100%;
  13.         height: 100%;
  14.       }
  15.     </style>
  16.   </head>
  17.  
  18.   <body>
  19.     <div id="pdf">
  20.       <iframe src="" type="application/pdf">
  21.       </iframe>
  22.     </div>
  23.  
  24.     <script>
  25.       var xhr = new XMLHttpRequest();
  26.       xhr.open("GET", "https://cors-anywhere.herokuapp.com/https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", true);
  27.       xhr.responseType = "blob";
  28.       xhr.onload = function (e) {
  29.         if (this.status === 200) {
  30.           var file = window.URL.createObjectURL(this.response);
  31.           document.querySelector("#pdf>iframe").src = file;
  32.         }
  33.       };
  34.       xhr.send();
  35.     </script>
  36.   </body>
  37.  
  38. </html>
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement