Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda