admin管理员组文章数量:1317915
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?
Share Improve this question edited May 18, 2018 at 8:13 Aniruddha Shevle asked May 18, 2018 at 8:07 Aniruddha ShevleAniruddha Shevle 4,9194 gold badges25 silver badges40 bronze badges 9-
If you requirements allow to use HTML5
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 - @OsmanTuran: Thanks for your suggestion, but we're not allowed zip files to get uploaded! – Aniruddha Shevle Commented May 20, 2018 at 6:44
- 2 Let me rephrase what I said at the user's PoV. The user selects documents and starts upload. Then JS code handles selected files and press them into a single ZIP file and uploads it to server. Then server depresses and uses files in the ZIP file. If you don't want to use ZIP in any way, you can upload each files by pressing with LZMA with JS. If you want to optimize PDF files and press them without introducing another format, it's still possible. But, it's hard to get done in the browser. Please look at Prep for repressing PDFs: github./schnaader/prep-cpp – Osman Turan Commented May 20, 2018 at 19:00
- @OsmanTuran: Yes right, we can do like that! – Aniruddha Shevle Commented Aug 27, 2018 at 6:24
- @AniruddhaShevle, How did you solve this? – Tanvi Agarwal Commented Mar 1, 2021 at 6:03
1 Answer
Reset to default 7I 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:
- PDFKit
- blob-stream
- FileSaver.js
- pdf.js
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).
本文标签: Can we compress PDF files using javascript If yeshow amp If nowhyStack Overflow
版权声明:本文标题:Can we compress PDF files using javascript? If yes, how & If no, why? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741044945a2329838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论