简体   繁体   中英

PDF, barcode4j compression with java

I am using Apache Fop 1.0 to create PDF documents. By default it uses the FlateFilter to compress the content. The FOP uses the DeflaterOutputStream DEFAULT_COMPRESSION under the cover. I have not found any possibility to set it to BEST_COMPRESSION.

The pdf contains some barcodes as well generated by 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.

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.

I think the barcode4j generated image could be compressed, but I can not see how to do it.

Update1: The generated barcode seems to be too big. The pdf contains 3 pages and 3 barcodes. The 3 barcode is about the 50% of the whole pdf size.

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. The reason that you get 30% smaller in size is that compression is applied on the whole file - in PDF only streams are compressed.

You can substantially reduce the size by using compressed object streams. FOP does not support it but many tools do. See here if you need more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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