pdf-generator
pdf-generator copied to clipboard
Long table does not split into pages
Hello,
I'm using the following code snippet to generate pdf from an existing html table.
var _options = { documentSize: 'A4', type: 'share', fileName: 'report.pdf' };
pdf.fromData($('#myPdf').html(), _options)
.then((base64) => 'ok')
.catch((err) => console.err(err));
But whatever the table row length is, the output is always one paged PDF. As PDF file is only page, the rest of the table rows are not drawn.
I've already used some css tricks (like page-break-inside, page-break-after etc) with no luck.
As I can not determine the number of rows to be displayed on A4 page, I can not manually insert page-break:always.
How can I enable the plugin to paginate automatically?
regards, B.
The plugin basically will render your HTML in an internal browser, if your table grow downward the internal browser will take care of the pagination automatically. Try drawing that $('#myPdf').html()
in the browser and see if the table is growing as expected.
Here is an example with pagination: https://github.com/cesarvr/pdf-generator-example
Hello Cesar,
Thanks for the immediate reply.
I'm here attaching the screenshots and the generated PDF file from the cordova app .
As you can see, the table contains 148 rows and the generated PDF has only one page, ending with the 53rd line.
If it helps, the html table is generated by google visualization api and the generated table html is also attached.
Hope these helps to clarify,
best regards, B.
Hello Cesar,
Did you have any chance to check the table above? regards, B.
What happen in your case is that you are trying to transform just one page (of your pagination) to a PDF, you should build your PDF with a collection of all the rows (it should come from the server as an array for example) not just the current pagination.
Cesar hi,
I have just one table with 150 rows. I couldn't understand what you meant by "you should build your PDF with a collection of all the rows".
When I call the method, it only creates a pdf with one single page. (truncated at line 53 for example).
As I do not know/estimate the exact number of rows per page, I can not spesify css page breaks either.
I believe I'm missing something very simple, but couldn't figure it out.
any help will be appreciated.
best regards, B.