Search code examples
javascripthtmlcssfunctionembed

changing the size of embedded PDF in javascript


noob here, I want the embedded PDF to appear with 100% width and 97,5% height but i cant figure it out

  <style>.size {
      width:100%;
      height:97.5%;
    }
  </style>
    <button type="button" id="show" onclick="PDFshow(this); classadd()" >PDF anzeigen</button>
    <div id="pdfsize"> 
    <script>
      function PDFshow(x) {
        x.style.visibility = 'hidden';      
        var x = document.createElement("EMBED");
        x.setAttribute("src", "Doku.pdf");
        document.body.appendChild(x); 
      }
    </script>
    </div>
  

    <script>
      function classadd() {
        var element = document.getElementById("pdfsize");
        element.classList.add("size");
      }
    </script>

Solution

  • <button type="button" id="show" onclick="showPDF(this)" >PDF anzeigen</button>
    
    <script>
      function showPDF(x) {
        x.style.display = "none";
        var x = document.createElement("EMBED");
        x.setAttribute("src", "Doku.pdf");
        x.classList.add("size");
        document.body.appendChild(x);
      }
    </script>