Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ declare module 'pdfkit-table'

class PDFDocumentWithTables extends PDFDocument {
public table(table: Table, options?: Options): Promise<void>;
public queueRenderOnAddPage(section: (doc: PDFDocumentWithTables) => void)
public addBackground(rect: Rect, fillColor: string, fillOpacity: number);
}

// export = PDFDocumentWithTables;
Expand Down
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ const PDFDocument = require("pdfkit");
// const EventEmitter = require('events').EventEmitter;

class PDFDocumentWithTables extends PDFDocument {
rendersOnAddPage;

constructor(option) {
super(option);
this.opt = option;
this.rendersOnAddPage = []
// this.emitter = new EventEmitter();
}

/**
* queueRenderOnAddPage
* @param {(doc: PDFDocumentWithTables) => void} section
*/
queueRenderOnAddPage(section, callback) {
this.rendersOnAddPage.push(section)
typeof callback === 'function' && callback(this);
}


logg(...args) {
// console.log(args);
}
Expand Down Expand Up @@ -196,6 +208,7 @@ class PDFDocumentWithTables extends PDFDocument {
size: this.page.size,
margins: this.page.margins,
});
this.rendersOnAddPage.forEach(section => section(this))
lockAddHeader || addHeader();
//addHeader();
};
Expand Down Expand Up @@ -483,7 +496,7 @@ class PDFDocumentWithTables extends PDFDocument {
this.logg('CRAZY! This a big text on cell');
} else if(calc > maxY) { // && !lockAddPage
// lockAddHeader = false;
lockAddPage = true;
lockAddPage = false;
onFirePageAdded(); // this.emitter.emit('addPage'); //this.addPage();
return;
}
Expand Down Expand Up @@ -657,6 +670,7 @@ class PDFDocumentWithTables extends PDFDocument {
// For safety, consider 3 rows margin instead of just one
// if (startY + 2 * rowHeight < maxY) startY = rowBottomY + columnSpacing + rowDistance; // 0.5 is spacing rows
// else this.emitter.emit('addPage'); //this.addPage();
console.log('plugin datas', this.y, this.y + safelyMarginBottom + rowHeight)
if(options.useSafelyMarginBottom && this.y + safelyMarginBottom + rowHeight >= maxY && !lockAddPage) onFirePageAdded(); // this.emitter.emit('addPage'); //this.addPage();

// calc position
Expand Down