Hi @bpampuch I am facing issue in generating document through PDFmake. I tried switching to new version i.e 0.1.22 but still its way slow. Can I get any resolution or answer to this issue?
Thanks in advance
Version 0.1.22 includes fix for performance from issue https://github.com/bpampuch/pdfmake/issues/280. I do not know how large is your document. Partially should reduce time to generate document from previous version pdfmake. It is possible that your document contains a performance problem about which we know nothing yet.
Hi @liborm85 , my document size is around 75-100 pages one containing image and rest containing tables. I tried to use the new version 0.1.22 but it was slower than the 0.1.20. I tried to use this in 0.1.20
function flow(stream) {
var state = stream._readableState;
debug('flow', state.flowing);
if (state.flowing) {
do {
var chunk = stream.read(Number.MAX_SAFE_INTEGER); // add this here in stream.read(xxx);
} while (null !== chunk && state.flowing);
}
}
yet it takes around one minute to generate. In word document generation, it takes just 3-5seconds.
I am really in need of some help/
Kindly help me out in some or the other way.
My document containes dynamically generated tables from json.
So around 75 - 80 tables are generated dynamically from a function and then these are printed in the document.
There was one thing that I noticed was if the document was 40pages, it was printing in 3seconds, but as soon as it became 44pages, it took 23seconds. Is there any method that is having restriction or something?
40 pages means one image and around 10 tables.
@jthoenes Any help or input that you could share??
I have seen this , for 40pages or some amount of pages, this works fine, as soon as one page increases, the performance degrades immediately by large fraction of seconds.
Any guidance/help/assistance will be highly appreciated sir...
Pdfmake 0.1.22+ use the newer lodash 4.17.2 and not only that (see https://github.com/bpampuch/pdfmake/commit/91be970ea3241bc1a09b47adb5e4263909bd523d). Maybe it has some influence on it.
Ok sir, but what is the actual relation of number of pages? how can increase in one page degrade the performance?
I do not know. Maybe someone else comes up with an idea to solve this problem.
What browser are you having these issues in? If you're using IE11 you will have to make sure to polyfill the Number.MAX_SAFE_INTEGER constant.
@liborm85 Thanks alot for your valuable time
@Bazze Hi , IE11 is slow to download, is there any piece of code or reference that you could share? thanks in advance.
@Dannybrown2710 Have you tried your code in another browser? Is it equally slow in e.g. Chrome? If not, it's probably the missing constant in IE11 as I mentioned. Try polyfilling it yourself or use a service like polyfill.io to do it.
Released version does not use a constant Number.MAX_SAFE_INTEGER, but equivalent number 9007199254740991 for compatibility with IE.
(webpack replacer: https://github.com/bpampuch/pdfmake/blob/98ab6a34d1b98309e7415a0524af8a3220402eaf/webpack.config.js#L46)
Aha! Then I'm clueless.
I tried to use 0.1.22 , but it is for no reason slower . As @liborm85 stated , it might be because of loadash. Previous version with 9007199254740991 works well in Chrome but not in IE 11. @Bazze Can you share the tweaked js which you used for printing pdf faster in your application?
@Dannybrown2710 I haven't really done any other changes that should affect performance, but I'm using the code found here: https://github.com/Bazze/pdfmake/tree/feature/wide-tables-without-filesaver-2093de79
On that branch I've implemented a feature which splits tables that becomes wider than the page width plus that I've removed the bundled FileSaver since I include it separately on a global scope.
@Bazze I have tried your file , its amazing. I just have a small doubt, is it possible to fit one table in one page without getting it cropped? Auto-sizing , or something?
I'm not sure if I understand you @Dannybrown2710 but if you set your column widths to * (auto column size) pdfmake will make best effort to fit the table on the page. However, if it doesn't manage to keep the table width within the page boundaries my changes will kick in and split the table.
We're kind of getting off topic in this issue, are you still having the performance issues?
@Bazze the height is what I am talking about.
for performance bit I have tried using the number itself 9007199254740991, but it seems not to work,for chrome the performance is good, and I am sticking to version 0.1.20 not 0.1.22.
IE still takes alot of time or breaks in between stating long script is not responding.
@Dannybrown2710 Alright, I'm not sure about the height since that haven't been an issue for my use case. Maybe the dontBreakRows or keepWithHeaderRows settings could help you?
Regarding the performance issues you probably need to get some profiling done in IE to narrow down where the issue resides.
We also face some performance issues for out HTML to PDF parser. The HTML to Json document which works for PDFmake works in less than seconds, but the actual PDF generation consumes quite some time. On a beefy machine, creating 20 Pages takes on average 10 seconds in latest chrome and PdfMake 1.24
firefox usually needs 21 seconds for the same document.
(time grows perfectly linear according to the number of pages, we use text only)
Anything known?
pdfmake.1.2.4-performance.pdf
I gonna paste our JSON string we use for testing somewhere.
https://paste.kde.org/pmkpttzig
there is also the whole Roboto-font in Base64 included.
I used definition from previous post and I did some performance tests. I tried different versions of pdfkit.
| pdfmake version | Chrome | Firefox | Edge | IE11 |
|--------------------|----------|--------|-------|------|
| master (using pdfkit 0.8.0) | 13 s | 32 s | 130 s | ca. 200 s |
| master (build with pdfkit 0.7.1) | 3 - 4 s | 4 s | 11 s | 14 s |
| 0.1.20 + speed hack https://github.com/bpampuch/pdfmake/issues/280#issuecomment-267255835 (using pdfkit 0.7.1) | 3 - 4 s | 6 s | 19 s | 13 s |
According to this table must have a performance problem especially with pdfkit.
I added tests for Edge and IE to the table.
I'm created issue in pdfkit - https://github.com/devongovett/pdfkit/issues/615
Merged a performance optimization for kerning in fontkit. https://github.com/devongovett/fontkit/pull/70 Please re-install and try again.
New tests:
| pdfmake version | Chrome | Firefox | Edge | IE11 |
|----------------------------------|---------|---------|-------|-----------|
| (NEW) pdfmake master with pdfkit 0.8.0 and fontkit 1.5.4 | 12 s | 18 s | 80 s | 96 s |
| pdfmake master with pdfkit 0.8.0 and old fontkit 1.5.2 | 13 s | 32 s | 130 s | ca. 200 s |
| pdfmake master with pdfkit 0.7.1 | 3 - 4 s | 4 s | 11 s | 14 s |
Test scripts:
performance-test.zip
@devongovett Generate PDF file is faster, but still slow compared to pdfkit version 0.7.1. Another idea for fix?
Hi @liborm85 what are the main differences between version 0.8.0 and 0.7.1 ?
I'm thinking about going back ... I'll use the library included in the zip you just posted.
Hi @awoywood
There are release notes for version 0.8.0: https://github.com/devongovett/pdfkit/releases/tag/v0.8.0
Version 0.8.0 adds many new things, and primarily adds support for other font formats.
Library in zip with pdfkit 0.7.1 to generate basic texts works, but fails many tests. It is not intended for everyday use. I hope that @devongovett will solve the performance problem.
Released new version (0.1.27) with fontkit 1.5.4 which contanins this partly performance fix.
Just implemented a cache around fontkit in PDFKit: https://github.com/devongovett/pdfkit/commit/6e9e58f5d2c9c0c8b9aa9cfe3076f381310d80c5. This should improve performance significantly. It is released in PDFKit v0.8.2.
In order to increase cache efficiency, it splits up text by words and makes a separate fontkit call for each one, then caches the results. Please let me know if you see any bugs because of that. Particularly, any fonts with GSUB or GPOS adjustments around space characters won't be triggered anymore, though this should be rare.
New tests:
| pdfmake version | Chrome | Firefox | Edge | IE11 |
|----------------------------------|---------|---------|-------|-----------|
| (NEW) pdfmake master with pdfkit 0.8.2 | 4 - 5 s | 6 s | 16 s | 19 s |
| pdfmake master with pdfkit 0.8.0 and fontkit 1.5.4 | 12 s | 18 s | 80 s | 96 s |
| pdfmake master with pdfkit 0.8.0 and old fontkit 1.5.2 | 13 s | 32 s | 130 s | ca. 200 s |
| pdfmake master with pdfkit 0.7.1 | 3 - 4 s | 4 s | 11 s | 14 s |
Test scripts:
performance-test.zip
@devongovett Great work. Thanks.
New version pdfmake 0.1.29 with new pdfkit released.
Performance problem solved.
Thanks all for the fix! :+1: