react-native-pdf-lib icon indicating copy to clipboard operation
react-native-pdf-lib copied to clipboard

adding 5+ pages crashes the app

Open tepho opened this issue 6 years ago • 5 comments

i played a little with the example given, them when i increased the number of pages to 5, it completely crashed the app

  • this picture is with 4 pages( 4x pages[0])

works

  • this picture is with 5 pages( 5x pages[0]) DoesntWork

tepho avatar Jun 14 '19 20:06 tepho

Same problem here (on Android only, iOS is fine). I think it is related to the number of text boxes drawn instead of the pages added. Memory usage of the PDF generator seems to be proportional to the number of drawText() calls. Creating a single-page PDF file with 66 lines where each line is ~75 characters long caused the app's memory usage to increase from ~75 mb (before write() method is called) to ~330 mb.

Another thing that caught my attention is that the output file is ~1.2 mb, which I thought was kind of high considering this is only a single-page text file.

ghost avatar Jun 17 '19 17:06 ghost

same issue come...

appa3151 avatar Sep 17 '19 10:09 appa3151

We've worked around this for the time being by creating every page as a separate PDF, then stitching them together at the end.

We first noticed a memory problem on iOS actually, so note that if you put enough content in it'll face similar issues. I imagine that PRs would be welcome to solve this, but I'm not the maintainer, so can't say for sure.

thekevinbrown avatar Oct 25 '19 06:10 thekevinbrown

We've worked around this for the time being by creating every page as a separate PDF, then stitching them together at the end.

We first noticed a memory problem on iOS actually, so note that if you put enough content in it'll face similar issues. I imagine that PRs would be welcome to solve this, but I'm not the maintainer, so can't say for sure.

Hi @thekevinbrown how do you go about stitching the separate PDFs created together at the end?

tioluwani94 avatar Jan 12 '21 21:01 tioluwani94

I created a native module which uses com.tom_roush.pdfbox.multipdf.PDFMergerUtility on Android, and Core Graphics on iOS.

thekevinbrown avatar Jun 26 '21 02:06 thekevinbrown