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

246
Visualizações
Writing to A4 pdf giving wrong size image

I am trying to write to an A4 PDF

form = document.querySelector("#theform");

    html2canvas(form).then(function(canvas) {   
          doc = new jsPDF({   
            unit: 'pt',  
            format: 'a4',  
            });
            
            for (var i = 0; i <= form.clientHeight/842; i++) {
            //! This is all just html2canvas stuff
                var srcImg  = canvas;
                var sX      = 0;
                var sY      = 842*i; 
                var sWidth  = 595;
                var sHeight = 842;
                var dX      = 0;
                var dY      = 0;
                var dWidth  = 595;
                var dHeight = 842;

                window.onePageCanvas = document.createElement("canvas");
                onePageCanvas.setAttribute('width', 595);
                onePageCanvas.setAttribute('height', 842);
                var ctx = onePageCanvas.getContext('2d');
                
                ctx.drawImage(srcImg,sX,sY,sWidth,sHeight,dX,dY,dWidth,dHeight);

                var canvasDataURL = onePageCanvas.toDataURL("image/png",  wid = canvas.width, hgt = canvas.height);
                var hratio = hgt/wid
                
                const pdfWidth = doc.internal.pageSize.width;
                const TheHeight = doc.internal.pageSize.width;                  
                const pdfHeight = TheHeight
                
            
                if (i > 0) {
                     doc.addPage(595, 842); 
                }
                //! now we declare that we're working on that page
                doc.setPage(i+1);
                
                
                doc.addImage(canvasDataURL, 'PNG', 10, 10, pdfWidth, pdfHeight);

            }
            doc.autoPrint();
            
            window.open(doc.output('bloburl'), '_blank'); 
          }

But the it is only creating a PDF for part of the left hand side and I can't see anything wrong.. It is as though what it is writing to the PDF is twice the size it should be.

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