c++cimagepdflibharu

Explicitly set image compression filter


According to PDF format spec, it has various image compression filters including CCITTFaxDecode.

I'm using libharu and need to explicitly set compression filter to CCITTFaxDecode for all images in the generated PDF.

How can I tell libHaru to use CCITT compression for images in PDF?

Below is the where I am currently.

From the libHaru documentation, it has HPDF_SetCompressionMode() function which has the argument named mode. The argument has the HPDF_COMP_IMAGE option enabling images compression. But it's not clear how to choose which compressor to use.

Another thing, among libHaru source files there is CCITT compressor (hpdf_image_ccitt.c), but I can't figure out how to explicitly set it as the compressor for images.

Any help is greatly appreciated.


Solution

  • My read of the source in hpdf_image_ccitt.c is that the CCITT G4 encoder is selected automatically for eligible instances if HPDF_COMP_IMAGE is enabled. See https://github.com/libharu/libharu/blob/d84867ebf9f3de6afd661d2cdaff102457fbc371/src/hpdf_image_ccitt.c#L779 for where this looks to be the case.

    Note that only black & white (1 bit per pixel) images can be CCITT encoded.