I am new to Python programming but have over 5 years of coding experience.
I have to split large PDFs into smaller ones less than 20Mb. I have currently written code with the following logic.
- Find the file size. Divide the file size by 20 and round the number, lets call this number partitions. Ex: File Size 45 then I divide 45 by 20 and round the value from 2.25 to 3.
- Find the number of pages. Let's say there are around 500 pages.
- Divide the number of pages by the partitions (3). So there will be 3 sets, from Pages 1 to 171, 172 to 343 and 344 to 515.
- I split the PDF into number of partitions as mentioned above.
The challenge I am facing is that all the pages are not of the same size so some PDFs become really small and some might exceed the 20Mb limit.
Can someone suggest any solution to this? Even a better approach is welcome.