bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.63k stars 2.04k forks source link

Performance issue with bulk records #342

Closed vsnpavan closed 7 years ago

vsnpavan commented 9 years ago

I am making use of pdfmake to download a tabluar data which has nearly 10,000 rows and i am unable to download the content in the form of pdf using pdfmake. Till 1000 records i am able to download, if i provide more than 1000 records the browser is getting hanged.

Please provide some solution on how to get rid of this issue and increase the performance of pdfmake.

jthoenes commented 9 years ago

Which browser are you using? Can you provide details what is slowing down pdfmake? Memory issues? CPU issues?

vsnpavan commented 9 years ago

I tried in IE,mozilla and chrome as well. Seems the issue is with memory. In IE i am getting an error like "localhost is not responding due to long running script" and in mozilla the browser is getting crashed after few mins.

vsnpavan commented 9 years ago

@jthoenes Please help me on the above issue.

jthoenes commented 9 years ago

I can only help you if you spend time to answer my question.

vsnpavan commented 9 years ago

@jthoenes I already answered to your question. Below is my answer once again.

I tried in IE,mozilla and chrome as well. Seems the issue is with memory. In IE i am getting an error like "localhost is not responding due to long running script" and in mozilla the browser is getting crashed after few mins.

jthoenes commented 9 years ago

That's not giving me any clue what might cause your issue. Please spend some time with the developer tools to find out, if we have a CPU or a memory issue.

regexti commented 9 years ago

@jthoenes

It is memory leak in my case. The function "LayoutBuilder.prototype.processNode" is where it occurs. I can not generate a 1000 pages on the server.

jthoenes commented 9 years ago

Thanks for the info @regexti.

It guess that is going to be hard to tackle, as pdfmake is actually creating a lot of information and only afterwards it is generating the pdf. So the "memory leak" behaviour is kind of necessary.

Refactoring that is going to be hard. So don't hope for a quick fix ...

regexti commented 9 years ago

I am studying the source to help improve it, the tool is wonderful.

Thanks @jthoenes

raj-mehta commented 9 years ago

Hi , commendable work for exposing such a library . But when i try to print 5000 rows of data in table using pdfmake and browser is FF. we are getting script error.

mikehuebner commented 8 years ago

I'm a bit late to this issue and I've been looking around for a solution, but so far all I have is a chrome solution and that is download the PDF. It takes about 3 to 5 seconds for 12k+ lines of JSON data which is fair, but I am trying to write a solution to do a fake button click download for the others. I'm generating a 1.3mb PDF so it does take a while to construct, I just figured this out. Figured I would share since we are all on the same boat. The memory leak thing seems unavoidable for now, but I did increase generation time with this on lines 22126 to 22136. It seems dirty but its working to save some generation time.

flow(engine);

function flow(stream) {
       var state = stream._readableState;
       debug('flow', state.flowing);
       if (state.flowing) {
         do {
           var chunk = stream.read(Number.MAX_SAFE_INTEGER); // grab MAX_SAFE_INTEGER bytes
         } while (null !== chunk && state.flowing);
       }
      }

I have the data in an issue #420 (heh, terrible tired humor) I opened up and I'll be continuously fighting with this I'm sure.

The idea of adding this seems to help, but probably effects other parts of the system I don't understand yet. I'm willing lend a helping hand if you need, just not sure where to begin. Thanks for an awesome product!

venhels commented 8 years ago

waaaaaaaaaaaaaaaaaaaaaattttttt??? from 6min of rendering to 12 SECONDS!!!! THANK YOU VERY MUCH SIR!!!! +1 +1 +1 this was my issue #423 I even made a video to show its really 6mins of waiting time! hahah Thank you very much sir @mikehuebner your answer was really right on timing! I wished I had read this earlier! by the way I didnt included the

 flow(engine); 
because its giving me undefine error. :+1: :100: :1234:

and in my file it was on line 20117-20125, anyways just find the function flow(stream) word then replace the whole function with

function flow(stream) {
       var state = stream._readableState;
       debug('flow', state.flowing);
       if (state.flowing) {
         do {
           var chunk = stream.read(Number.MAX_SAFE_INTEGER); // grab MAX_SAFE_INTEGER bytes
         } while (null !== chunk && state.flowing);
       }
      }
ivanbulanov commented 8 years ago

+1 This must be improved. Performance in the browser really suffers badly because of this piece of code.

Adhara3 commented 8 years ago

I am struggling with 628 rows..... neverending

TyraelElDruin commented 8 years ago

Surprised that this hasn't been fixed yet! I have 1,194 rows on my current table (72 pages in PDF form). Using @mikehuebner 's code, I was able to get it to export without freezing. Just wanted to say thank you!

tneil commented 8 years ago

I'm not sure if the following will help you at all for in-browser performance, but we found that the following dramatically sped up our performance on the server using node.js to generate the PDFs by updating the code to turn on compression by default.

We were writing the PDF out to file and the compression made a huge difference.

Issue #622

timematcher commented 8 years ago

+1 In opera it seems to work great even with a few thousand records and columsn > 5 maybe because opera has a really fast JS engine (debatable). However it is really slow in chrome and Firefox for a few thousand records (though works great to a few hundred records and 5-8 columns). Please improve it. Thanks

Btw , Great library, I am using it in a couple of projects and really love it.

needforspeed commented 8 years ago

Is there any plan to merge the solution to release?

liborm85 commented 7 years ago

I tried to fix performance, details in comment https://github.com/bpampuch/pdfmake/issues/280#issuecomment-267255835.

liborm85 commented 7 years ago

New version released.

kriskarthik commented 7 years ago

Hi,

I am also facing the same issue of downloading the 10k records from browser using the pdfmake.min.js.

Browser - Chrome - 57.0 Records - 10000 Number of Columns - 8

Query-1 -- I didn't get where the above method need to be added as am new to this js usage. Query-2 -- Latest version of pdfmake.min.js is directing to different sites, can you share me the appropriate link.

Thanks Kris