Home > other >  changing the size of embedded PDF in javascript
changing the size of embedded PDF in javascript

Time:08-08

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>

CodePudding user response:

Add this after x.setAttribute("src", "images/application-form.pdf"); :

x.setAttribute("width", "100%");
x.setAttribute("height", "97.5%");

you can delete the css code of .size and add height on the body tag of 100vh.

CodePudding user response:

i figured out a way to have the size inside a seperate css file

for anyone interested:

    <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>
  • Related