react-pdf: "Cannot enlarge memory arrays" error when document is big.

OS: MacOS 10.13.6

React-pdf version: 1.0.0-alpha.17

Description: Hello! I’m using react-pdf to generate payment reports for a website I’m working on. The reports can often get really big, 400+ pages long. But I can only generate about 450 pages on my machine. If I try to render more, it hangs and finally crashes with the following error:

Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 134217728, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or (4) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0

I’m rendering the pdf reports in browser with PDFViewer.

How to replicate issue including code snippet (if applies):

I made a reproducible demo here (almost same code as in pageWrap example but rendering the same Don Quijote page content 1600 times): https://github.com/binchik/react-pdf-crash-example

It loads for about 5-10 minutes then crashes with the “Cannot enlarge memory arrays” error.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 28 (2 by maintainers)

Most upvoted comments

Ok. I just discovered that My Issue is a little different. I have a View that has wrap=false. The problem is that the view contains dynamic content. when the content grows to a point that is bigger than can fit on a page, then I am guessing react-pdf keeps wrapping the whole view to the next page, hoping that the view will fit on the next page, until finally it has generated XXX number of pages and then runs out of memory.

When wrap=true, the the view contents are split, which might be ok, except when it wraps, the first part of the View contents get compressed together. as seen in this picture. image

I should probably create a separate issue for this.

Same problem here. Rendering a large amount of views and texts to display data tables. After about 25 pages, it crashes.

experiencing the same behavior for large documents.

I had this issue and found it was because I had wrap={false} around components which were getting bigger than 1 page. I removed the wrap={false} and the problem stopped

@diegomura , I’m using the default page size. Or do you mean wrapping chunks of content in a <Page> component? I think the largest pdf I was able to print without crashing was ~40 pages. Here’s a screenshot of the error message in the browser:

screen shot 2018-09-25 at 6 18 39 pm

Thanks and let me know how I can help you address this

This was helpful. I realized that one page component will fail to render if the dynamic content being rendered inside is too big. Some people said ~45 pages. So I tried wrapping the dynamic content inside <Page> tags separately and it worked!!

Basically, if you’re rendering dynamically, you’ll probably have an array of data that you map to create your Views. In my case I divided the initial array of 400 objects into 10 arrays of 40 and wrapped a Page component around each array.

Theses numbers are not fixed, it depends on how many elements are on your initial array and how much memory they need. The point is: there seems to be a memory limit on the Page component and the workaround is to generate more Page components instead of relying entirely on page wrap functionality.

@diegomura This issue, or one similar to it still exists and is replicable in a unit test. react-pdf struggles to render large pieces of text. See the unit test and result

Unit test image

Result image

I’m not sure if this is going to make it back to the git thread as I’m responding via email. Initially I was storing all this data in one giant jsonobject that had arrays holding all of my data as values and specific keys as keys. I swapped it to a regular array and refactored code and didn’t get the error anymore.

On Fri, Apr 12, 2019, 8:38 AM Leandro Lima notifications@github.com wrote:

Did you find any solution?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/diegomura/react-pdf/issues/314#issuecomment-482558777, or mute the thread https://github.com/notifications/unsubscribe-auth/AINV_WJVPafUprDtfPby-yZuZVeQ7d9yks5vgH4_gaJpZM4W1nat .

Same problem here. Rendering a large amount of views and texts to display data tables. After about 25 pages, it crashes.

I am trying to generate a pdf of about 100 pages(all text) and facing the same issue. Using 2.0.0-beta.6.

I’ve managed to produce this recently in 1.6.8 although we’re using it with PDFs that are 80+ pages long, and sometimes contain images. If I figure it out I’ll come back to this thread.