Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda