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

148
Visualizações
created pdf using html2cavas and jsPDF get the width right only on desktop?

I have the following code the issue the implementation is like the following generated items go in to a div that has a fixed width of 1100, using mui btw, when creating the pdf on desktop the results are as they should be how ever when creating the pdf from mobile phone the width of the created pdf is small I could say only 400 of the 1100 div is showing, when creating from chrome responsive it is working as it should, how to what is the right options to make jspdf created a pdf with the right width I think jsPdf is confusing iphone screen size ?

html2canvas(
      document.getElementById('pdfItems')!,
      {
        onclone: function (clonedDoc) {
          // none ! hidden show !!
          clonedDoc.getElementById('pdfItems')!.style.display = 'flex';
        },
        // TO INCREASE QUALITY !!!!!!!!!!
        scale: /*3*/ 2,
        //width: document.getElementById('pdfItems')!.clientWidth,
      }
      /* {
      allowTaint: false,
      width: window.innerWidth,
      height: window.innerHeight,
      scrollX: window.pageXOffset,
      scrollY: window.pageYOffset,
      x: window.pageXOffset,
      y: window.pageYOffset,
      imageTimeout: 1500,
    }*/
    ).then((canvas) => {
      //document.body.appendChild(canvas); // if you want see your screenshot in body.
      const imgData = canvas.toDataURL('image/png');

      //A4
      var imgWidth = 210;
      //var pageHeight = 295;
      var imgHeight = (canvas.height * imgWidth) / canvas.width;
      //var heightLeft = imgHeight;
      // A4
      var doc = new jsPDF('p', 'mm' /*pt*/, 'a4', true);
    
      doc.addPage([imgWidth, imgHeight]);
      doc.addImage(imgData, 'PNG', 0,0 , imgWidth, imgHeight);
      doc.deletePage(1);
      const fileName = 'test'
      doc.save(`${fileName}.pdf`);
    });
  };
  
  
  // PDF DIV STYLE 
  <div
      id='pdfItems'
      style={{
        display: 'flex',
        flexDirection: 'column',
        margin: 0,
        padding: 0,
        textAlign: 'center',
        width: 1100,
       
      
      }}
    >
    // Itemes
    </div>

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