Java 我们可以使用 iText 压缩 PDF 文件大小吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20278902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can we compress PDF file size using iText?
提问by MaheshVarma
I am using iText to read and manipulating PDF files(reports). I read a PDF report using iText and I make each page as separate PDF file. But I am unable to reduce the size of the generated pdf. Is there any compression technique or any other way to reduce the size of pdf? does pdfbox
help in this way?
我正在使用 iText 阅读和操作 PDF 文件(报告)。我使用 iText 阅读了一份 PDF 报告,并将每一页作为单独的 PDF 文件。但我无法减小生成的 pdf 的大小。是否有任何压缩技术或任何其他方法来减小 pdf 的大小?确实pdfbox
帮助这种方式?
回答by Jk1
You can try to set a compression level when using iText:
您可以尝试在使用 iText 时设置压缩级别:
Document document = ...
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
writer.setCompressionLevel(9);
Level 9 is slowest, but gives you the best compression available in iText.
级别 9 最慢,但为您提供 iText 中可用的最佳压缩。