Generate a pdf table with the jspdf library

i managed to make simple pdf pages with some text and images on the “page”, but now comes the hard thing.
I stored some data in a tiny_db asset and whanna make a grid on the paper.

I see this example code on the jspdf page, but do not know how to handle those “vectors” to pass to the pdf generation code … lists?:

var generateData = function (amount) {
var result = [];
var data =
    coin: "100",
    game_group: "GameGroup",
    game_name: "XPTO2",
    game_version: "25",
    machine: "20485861",
    vlt: "0"
for (var i = 0; i < amount; i += 1) { = (i + 1).toString();
    result.push(Object.assign({}, data));
return result;

function createHeaders(keys) {
    var result = [];
    for (var i = 0; i < keys.length; i += 1) {
        'id' : keys[i],
            'name': keys[i],
            'prompt': keys[i],
            'width': 65,
            'align': 'center',
            'padding': 0
    return result;

var headers = createHeaders(["id", "coin", "game_group", "game_name", "game_version", "machine", "vlt"]);

var doc = new jsPDF({ putOnlyUsedFonts: true, orientation: 'landscape' });
doc.table(1, 1, generateData(100), headers, { autoSize: true });


Context ?

For tables you should use the jspdf-autotable library

the question is:
how could i “simulate a vector” in ai2?
are lists the way ai2 manage an “amount” of items?

if i use your autotable example (thanks for this <3) how con i merge the features of “genpdf.html” with those of genpdftable?

I need to generate pages with text mixed with tables, not pages of only tables :frowning:

i replied by myself … for the question if autotable is able to add plain text to the pages and not only tables, i tested adding a line to your example:
doc.text(‘This is some text.’, 20, 20);

and setting the table Y coordinate like that: doc.autoTable({startY: 30,

PS: remember always to add a ; ath the end of all jspdf “commands” (the last one do not care).

now testing images

Keep at it, you seem to be solving your own problems, and will be the forum’s jspdf expert by the time you have done :+1:

1 Like

see also this tutorial

you can also purchase the example including descriptions, see here


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.


but real differences from appy builder and app inventor? … some time i’ll try to search commands and procedures on AI2 i think are present and then i realize i can have dreamt of them :smiley:

like a sort of “got to scree” instead of “open screen” or a way to know if a screen is already opened

The recommended method of switching screens in App Inventor


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.