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

234
Visualizações
How to chop up a large canvas that has image drawn on it into a multipage HORIZONTALLY and VERTICALLY pdf file?

So far I have tried many different variations of this code

function printCanvas(canvasId,title){
var canvas = document.getElementById(canvasId); 
var imgData = canvas.toDataURL('image/png');
//var imgWidth = 210; 
// var masterWidth = canvas.width;
// var imgWidth = 210;
// var pageHeight = 295;  
// var imgHeight = canvas.height * imgWidth / canvas.width;
// var masterHeight = canvas.height * imgWidth / canvas.width;
// var heightLeft = imgHeight;
// var doc = new jsPDF('p', 'pt');
// pageWidth = 595;
// pageHeight = 852;
var doc = new jsPDF("p", "mm", [317.5,396.875]);
var pageWidth = 317.5;
var pageHeight = 396.875;
var position = 0;

// doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
// heightLeft -= pageHeight;

// while (heightLeft >= 0) {
//   position = heightLeft - imgHeight;
//   doc.addPage();
//   doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
//   heightLeft -= pageHeight;
// }
addP = 0;
for (var y=0;y<Math.ceil(canvas.height/pageHeight);y++){
    for (var x=0;x<Math.ceil(canvas.width/pageWidth);x++){
        if (addP == 1){
            doc.addPage();
        }
        doc.addImage(imgData,'PNG',x*pageWidth,y*pageHeight,pageWidth,pageHeight)
        addP = 1;
    }
}
doc.save( 'pattern.pdf');
}

and nothing seems to work so far I want it so that each page of the pdf shows an image of 1200 pixels width by 1500pixels height but not fit to page so that it stays with right squared pixels ratios (not stretched). and it would go across per crop until right edge of image is reached and then it loops downward until the whole image is shown (or can be assembled when the pdf is printed).

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