Open Babbiorsetto opened 2 years ago
I fixed this problem in the next version 0.2.x. But it's not over the full migration.
async functions is the solution,
@Babbiorsetto Try this typescript example (another/testing package):
$ npm i pdfkit-table-ts
Sample here https://github.com/natancabral/pdfkit-table-ts
By converting the example code to an async function, it does seem to work, although this happens at the page break The title is split from content and a row is missing(!)
Sorry, my bad. Try now:
$ npm i pdfkit-table-ts@latest
I'm glad to see you're sorting things out. I'll make sure to try it when it's ready for release. I think I'll stick with my solution for now since it works decently and I can't convert all my code right now.
To fix this on new version:
// calc if header + first line fit on last space page
this.titleAndHeaderAndFirstLineHeightCalc = (
this.titleHeight +
this.subtitleHeight +
this.headerHeight + // + header height
this.firstLineHeight + // + first line height
(this.pdfkitTableCache.distanceCorrection * 2); // space between titles and lines
)
Is there any news on this? Is using pdfkit-table-ts instead of pdfkit-table still the recommended solution? :)
I'm generating multiple tables on one page, one after the other. When reaching the end of the page, I expect the next table to move to a new page, instead what happens is it's placed on top of the same page, thereby overwriting the tables that were placed before.
I have created a minimal reproducible example recreating this issue
example
```javascript const PDFDocument = require("pdfkit-table"); const path = require("path"); const fs = require("fs"); const doc = new PDFDocument({layout: "landscape"}); const tables = [ { title: "One", headers: ["Hello"], rows: [["World"]], }, { title: "Two", headers: ["Hello"], rows: [["World"]], }, { title: "Three", headers: ["Hello"], rows: [["World"]], }, { title: "Four", headers: ["Hello"], rows: [["World"]], }, { title: "Five", headers: ["Hello"], rows: [["World"]], }, { title: "Six", headers: ["Hello"], rows: [["World"]], }, { title: "Seven", headers: ["Hello"], rows: [["World"]], }, { title: "Eight", headers: ["Hello"], rows: [["World"]], }, { title: "Nine", headers: ["Hello"], rows: [["World"]], }, { title: "Ten", headers: ["Hello"], rows: [["World"]], }, ]; for (const table of tables) { doc.table(table); } doc.end() const file = fs.createWriteStream(path.join(process.cwd(), "out.pdf"), {flags: "w"}) doc.pipe(file) ```For now I'm circumventing the issue with the equivalent of this code replaced in the previous snippet
Let me know if you find a better solution.