Jspdf-autotable: page break with image is not working correctly

Created on 16 Apr 2020  路  3Comments  路  Source: simonbengtsson/jsPDF-AutoTable

I am trying to create rows with image and description if the element have. When I insert the image, the cell does not fit the image to fit, I am using the didParseCell hook but this causes me problems when doing page breaks or maybe I'm doing something wrong.

I'm using 1.5.3 version of jsPDF and 3.2.4 version of autoTable-jsPDF.

Captura

Code example:

https://codepen.io/cplaiuu/pen/JjYXGVR

question

Most helpful comment

If you want image to fit correctly and page-break work automatically, you need to manually set cell width & height according to image dimensions.

You can do that in the definition of each image cell using cellWidth & minCellHeight properties under styles, or you could set it later using didParseCell hook by updating data.cell.styles.cellWidth & data.cell.styles.minCellHeight.

But you shouldn't update other dimensions in didParseCell hook like row.height because that gets calculated based on cell later after didParseCell.

Also note you could use padding instead of cellWidth & minCellHeight if your cell has text content and you want to add an image next to that.

All 3 comments

When drawing something with the didParseCell hook you need to check that it fits the page and cell yourself and if not add a new page or increase the cell dimensions.

If you want image to fit correctly and page-break work automatically, you need to manually set cell width & height according to image dimensions.

You can do that in the definition of each image cell using cellWidth & minCellHeight properties under styles, or you could set it later using didParseCell hook by updating data.cell.styles.cellWidth & data.cell.styles.minCellHeight.

But you shouldn't update other dimensions in didParseCell hook like row.height because that gets calculated based on cell later after didParseCell.

Also note you could use padding instead of cellWidth & minCellHeight if your cell has text content and you want to add an image next to that.

@mmghv Thanks you for help.
I change row.height inside of didParseCell to data.cell.styles.cellWidth & data.cell.styles.minCellHeight and I set pageBreak: 'auto ' & rowPageBreak: 'avoid'. Now it is working properly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webdream-fr picture webdream-fr  路  6Comments

dnlbaldwin picture dnlbaldwin  路  6Comments

matsumeri picture matsumeri  路  7Comments

sirishasd picture sirishasd  路  4Comments

simonbengtsson picture simonbengtsson  路  4Comments