I've implemented upload documents functionality on browser where a user can upload around 4-5 documents at a time. However, when we upload the documents having file size around 5MB and having slow internet connection(set slow 3G network in the browser's dev tools), we can not upload all the files due to internet timeout!
To upload documents successfully having large size and slow internet connection, I've pressed the images and it solves my issue. But the user can also upload PDF files of large size. How can we press PDF files and then upload?
I've implemented upload documents functionality on browser where a user can upload around 4-5 documents at a time. However, when we upload the documents having file size around 5MB and having slow internet connection(set slow 3G network in the browser's dev tools), we can not upload all the files due to internet timeout!
To upload documents successfully having large size and slow internet connection, I've pressed the images and it solves my issue. But the user can also upload PDF files of large size. How can we press PDF files and then upload?
FileReader
API, there are several JavaScript libraries (such as stuk.github.io/jszip) for creating ZIP files at browser. Then you can upload it after creating with JavaScript.
– Osman Turan
Commented
May 19, 2018 at 19:17
I was asking myself the same question (can you reduce the size of a PDF client side only?) and it turns out that someone did it:
https://github./OpenToolKit/CompressPDF.
The script is working client-side only and is able to repress the pictures of a PDF and even join different PDFs.
However, there is a known limitation: the text in a PDF is rendered as an image first and then pressed, resulting in a quality loss.
It uses a bination of:
Another path to the solution, that I discoved while playing with WebAssembly, is to pile a library that does it in C/C++ into WASM with enscripten. For example, GhostScript can be piled to WASM.
Someone did it here and I piggy back on his work to achieve pressing in browser only (demo).