简体   繁体   English

我们可以使用 javascript 压缩 PDF 文件吗? 如果是,怎么做?如果不是,为什么?

[英]Can we compress PDF files using javascript? If yes, how & If no, why?

I've implemented upload documents functionality on browser where a user can upload around 4-5 documents at a time.我已经在浏览器上实现了上传文档功能,用户一次可以上传大约 4-5 个文档。 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但是,当我们上传文件大小约为 5MB 且网络连接速度较慢的文档时(在浏览器的开发工具中设置慢速 3G 网络),由于网络超时,我们无法上传所有文件

To upload documents successfully having large size and slow internet connection, I've compressed the images and it solves my issue.为了成功上传具有大尺寸和慢速互联网连接的文档,我压缩了图像并解决了我的问题。 But the user can also upload PDF files of large size.但用户也可以上传大尺寸的 PDF 文件。 How can we compress PDF files and then upload?我们如何压缩 PDF 文件然后上传?

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:我问自己同样的问题(你能减少 PDF 客户端的大小吗?),结果有人做到了:

https://github.com/OpenToolKit/CompressPDF . https://github.com/OpenToolKit/CompressPDF

The script is working client-side only and is able to recompress the pictures of a PDF and even join different PDFs.该脚本仅在客户端工作,能够重新压缩 PDF 的图片,甚至可以加入不同的 PDF。

However, there is a known limitation : the text in a PDF is rendered as an image first and then compressed, resulting in a quality loss.但是,有一个已知的限制:PDF 中的文本先渲染为图像然后压缩,导致质量损失。

It uses a combination of:它使用以下组合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM