Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Zoom in & zoom out an iframe with PDF by clicking zoom buttons with JavaScript?

I'm trying to zoom in and out of an iFrame with a PDF using two buttons. The problem is that the zoom in/out applies only to the area around the PDF, and the PDF remains intact.

The one thing i am not getting is: There is three types of zoom on my page.

  1. The zoom in/out using my buttons, that does apply to something because i can see the element changing width with clientWidth function.
  2. If i leave my mouse right at the PDF and use my mouse wheel UP/DOWN, the zoom in/out works PERFECTLY - It does zoom in/out the PDF.
  3. The browser zoom - If i leave my mouse outside the PDF region, it does the browser zoom (110%, etc. Chrome zoom...)

Below is my HTML and my JS. No CSS used for this.

HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>O que é HTML?</title>
    <script type="text/javascript" src="./O que é HTML.js"></script>
  </head>
  <body>
    <div id="titulo">
      <h1>PDF sem opção de download - HTML</h1>
    </div>
    <div id="pdfViewer">
      <iframe
        src="./pdfs/Apostila HTML.pdf#toolbar=0&navpanes=0&statusbar=0&messages=0"
        width="100%"
        height="500px"
      >
      </iframe>
    </div>
    <div id="zoom">
      <button type="button" onclick="maisZoom()">Aumentar zoom</button>
      <button type="button" onclick="menosZoom()">Diminuir zoom</button>
    </div>
  </body>
</html>

JavaScript:

function maisZoom() {
    var myPDF = document.getElementById("pdfViewer");
    var zoomAtual = myPDF.clientWidth;
    if (zoomAtual == 2500) return false;
    else {
        myPDF.style.width = (zoomAtual + 100) + "px";
    }
  }
  
  function menosZoom() {
    var myPDF = document.getElementById("pdfViewer");
    var zoomAtual = myPDF.clientWidth;
    if (zoomAtual == 100) return false;
    else {
        myPDF.style.width = (zoomAtual - 100) + "px";
    }
  }

Below is a GIF showing exactly what i said above. Gif explained:

  1. First zoom using buttons.
  2. Second zoom using mouse wheel with my mouse on the PDF region.
  3. Third zoom using mouse wheel with my mouse outside PDF region, which does the browser zoom.

I want to replicate the second zoom - Zoom in/out of the PDF using the buttons.

Zoom GIF

Any help is appreciate it! Thank you.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!