在itext中缩小PDF文件大小(java) [英] Reduce PDF file size in itext (java)

查看:307
本文介绍了在itext中缩小PDF文件大小(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于Web的标签打印系统。对于每个标签,应该有一个唯一的s / n。因此,当用户决定创建1000个标签(具有相同数据)时,所有标签都应具有唯一的s / n,因此pdf将具有1000个页面,这会增加文件大小。

I'm creating a Web-based label printing system. For every label, there should be a unique s/n. So when a user decided to create 1000 labels (with the same data), all of it should have unique s/n, therefore the pdf will have 1000 pages, which increases the file size.

我的问题是,当用户决定创建更多副本时,文件大小会变大。

My problem is when the user decided to create more copies, the file size will get bigger.

有什么方法可以减少文件大小使用Itext的pdf?或者有什么方法可以生成pdf并将其输出到浏览器中而不将其保存到服务器/客户端的硬盘上?

Is there any way that I can reduce the file size of the pdf using Itext? Or is there any way that I can generated the pdf and output it in the browser without saving it neither to server/client's HDD?

感谢您的帮助!

推荐答案

如果除了s / n之外的所有内容对于数千个标签都是相同的,那么您只需要将相同的内容添加一次作为模板并将s / n文本放在其上。

If everything except the s/n is the same for the thousands of labels, you only have to add the equal things one time as a template and put the s/n text on top of it.

看看 PDFTemplate 。如果我没记错的话,为重复绘图/标签/图像创建了XObject,并且每次使用时它都是完全相同的对象。

Take a look at PDFTemplate in itext. If I recall correctly that creates and XObject for the recurring drawing/label/image.... and it is exactly the same object every time you use it.

即使成千上万的标签,唯一增加文档大小的是s / n(和每个页面),但'label'的图形或文本只添加一次。这应该会减少你的文件大小。

Even with thousands of labels, the only thing that grows your document size is the s/n (and every page) but the graphics or text of the 'label' is only added once. That should reduce your file size.

这篇关于在itext中缩小PDF文件大小(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆