How to do dynamic positioning JsPDF

-1

I'm using the jsPDF plugin to generate a PDF. In my created method, I get an array, scroll through it, try to write and position dynamically in the PDF, however I have no idea how to do it.

 $scope.gerarPdf = function (item) {
        var doc = new jsPDF();

        for (var i = 0; i < item.length; i++) {
            doc.text(item[i].nome, x, y);
            doc.text(item[i].validade,  x, y);
            doc.text(item[i].saldoParcial,  x, y);
        }
        doc.save('teste.pdf');
        return doc;
    };

Where I have: 'x', 'y', is where I wanted to dynamically define the positioning.

    
asked by anonymous 16.07.2018 / 19:26

1 answer

2

You're on the right track, it's just a matter of calculation. Look at this example:

var x = 15;
var y = 20;

for (var i = 0; i < item.length; i++) {
    doc.text(item[i].nome, x, y);
    doc.text(item[i].validade,  x, y+6);
    doc.text(item[i].saldoParcial,  x, y+12);
    y = y + 20
}

Doing this would already put all the data one below the other in the same column. To change columns, just edit X as well.

    
17.07.2018 / 14:20