简体   繁体   English

使用Java进行PDF,barcode4j压缩

[英]PDF, barcode4j compression with java

I am using Apache Fop 1.0 to create PDF documents. 我正在使用Apache Fop 1.0创建PDF文档。 By default it uses the FlateFilter to compress the content. 默认情况下,它使用FlateFilter压缩内容。 The FOP uses the DeflaterOutputStream DEFAULT_COMPRESSION under the cover. FOP在封面下使用DeflaterOutputStream DEFAULT_COMPRESSION。 I have not found any possibility to set it to BEST_COMPRESSION. 我找不到将其设置为BEST_COMPRESSION的任何可能性。

The pdf contains some barcodes as well generated by Barcode4j 2.1. pdf包含由Barcode4j 2.1生成的一些条形码。 As I see the generated image is quite huge and I have not found any info how compress it: 正如我所看到的,生成的图像非常庞大,我还没有找到任何如何压缩的信息:

<fo:instream-foreign-object height="25pt" width="101pt">
   <barcode:barcode xmlns:barcode="http://barcode4j.krysalis.org/ns" message="xxxxxxxx">
     <barcode:code128>
       <barcode:height>37pt</barcode:height>
       <barcode:module-width>0.9pt</barcode:module-width>
       <barcode:human-readable>
         <barcode:placement>none</barcode:placement>
       </barcode:human-readable>
     </barcode:code128>
   </barcode:barcode>
</fo:instream-foreign-object>

If I generate the PDFs (using flate in fop and using the barcode injections written above), then I could decrease the pdf size with simple winzip by 30 percent. 如果生成PDF(使用fop中的flat并使用上面编写的条形码注入),则可以使用简单的Winzip将PDF大小减小30%。

Is there any way to use a better compression algorithm by my process? 有没有办法在我的过程中使用更好的压缩算法? The pdf should be openable in Acrobat Reader, so it is not an option to zip at server side and unzip it on the client side. pdf应该可以在Acrobat Reader中打开,因此不能选择在服务器端压缩并在客户端解压缩。

I think the barcode4j generated image could be compressed, but I can not see how to do it. 我认为条形码4j生成的图像可以压缩,但是我看不到该怎么做。

Update1: The generated barcode seems to be too big. Update1:​​生成的条形码似乎太大。 The pdf contains 3 pages and 3 barcodes. pdf包含3页和3个条形码。 The 3 barcode is about the 50% of the whole pdf size. 3条码约占整个pdf尺寸的50%。

Thanks 谢谢

Zoltan 佐尔坦

There is no big difference between the default compression setting and the max. 默认压缩设置与最大压缩设置之间没有太大差异。 If you know ZLib, you can write some test code to see - probably much less than you expected. 如果您了解ZLib,则可以编写一些测试代码来查看-可能比您预期的要少得多。 The reason that you get 30% smaller in size is that compression is applied on the whole file - in PDF only streams are compressed. 之所以将尺寸减小30%,是因为对整个文件进行了压缩-在PDF中,仅流被压缩。

You can substantially reduce the size by using compressed object streams. 您可以通过使用压缩的对象流来大幅减小大小。 FOP does not support it but many tools do. FOP不支持它,但是许多工具都支持。 See here if you need more information. 如果需要更多信息,请参见此处

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

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