Install jbig2enc encoder

I’m using ocrmypdf that recommends the jbig2 encoder. It says that, on Fedora, it can be installed with sudo dnf install jbig2enc but the package is missing. On the web, the only versions that I found were the source code on github or on the snap store.
Is there a way to install it on Fedora while avoiding snap or compiling it from source?

Looks to me like it is available on F37 if you use the right package name.

# dnf list *jbig*
Last metadata expiration check: 2:53:06 ago on Mon 09 Jan 2023 07:25:40 AM CST.
Installed Packages
jbig2dec-libs.x86_64                                                  0.19-7.fc37                                                 @fedora
jbigkit-libs.i686                                                     2.1-24.fc37                                                 @fedora
jbigkit-libs.x86_64                                                   2.1-24.fc37                                                 @fedora
Available Packages
jbig2dec.x86_64                                                       0.19-7.fc37                                                 fedora 
jbig2dec-devel.i686                                                   0.19-7.fc37                                                 fedora 
jbig2dec-devel.x86_64                                                 0.19-7.fc37                                                 fedora 
jbig2dec-libs.i686                                                    0.19-7.fc37                                                 fedora 
jbigkit.x86_64                                                        2.1-24.fc37                                                 fedora 
jbigkit-devel.i686                                                    2.1-24.fc37                                                 fedora 
jbigkit-devel.x86_64                                                  2.1-24.fc37                                                 fedora 

It seems there is the jbig2 Decoder but not the Encoder. I’m not sure of this but ocrmypdf complains that “The program ‘jbig2’ could not be executed or was not found on your
system PATH.”

Apparently ocrmypdf expects to find jbig2 program.

Looing at Installing OCRmyPDF — ocrmypdf 14.0.2.dev18+gf072e911 documentation
I see this note

OCRmyPDF for Fedora currently omits the JBIG2 encoder due to patent issues. 
OCRmyPDF works fine without it but will produce larger output files. 
If you build jbig2enc from source, ocrmypdf 7.0.0 and later will automatically 
detect it on the PATH. To add JBIG2 encoding, see Installing the JBIG2 encoder.

which leads to Installing the JBIG2 encoder — ocrmypdf 14.0.2.dev18+gf072e911 documentation
I find there that this is the way to install the encoder

git clone https://github.com/agl/jbig2enc
cd jbig2enc
./autogen.sh
./configure && make
[sudo] make install

That seems a very easy way to install it for your needs.

After installing the dependencies and running the above commands, I got stuck in the last command with the following errors:

make[1]: g++: No such file or directory
make[1]: *** [Makefile:482: jbig2.o] Error 127
make[1]: Leaving directory '/home/user/Apps/jbig2enc/src'
make: *** [Makefile:476: install-recursive] Error 1

Do you have the gcc-c++ package installed? That contains the compiler that seems missing according to that error.

# dnf provides */g++
gcc-c++-12.2.1-2.fc37.x86_64 : C++ support for GCC
Repo        : fedora
Matched from:
Filename    : /usr/bin/g++

gcc-c++-12.2.1-4.fc37.x86_64 : C++ support for GCC
Repo        : @System
Matched from:
Filename    : /usr/bin/g++

I installed gcc-c++ but now I am getting the following errors:

/usr/bin/install: cannot stat '.libs/libjbig2enc.so.0.0.28': No such file or directory
make[2]: *** [Makefile:435: install-libLTLIBRARIES] Error 1
make[2]: Leaving directory '/home/user/Apps/jbig2enc/src'
make[1]: *** [Makefile:616: install-am] Error 2
make[1]: Leaving directory '/home/user/Apps/jbig2enc/src'
make: *** [Makefile:476: install-recursive] Error 1

I will try compiling it and see what happens.

At first glance the README.md file says you need leptonica and configure fails when leptonica is not installed. If configure fails then make cannot successfully succeed.

What I wound up doing for a successful compile was

  1. sudo dnf install leptonica leptonica-devel. Both those packages are available in the fedora repo.

  2. in the jbig2enc directory I ran ./autogen.sh and waited for it to complete.

  3. I then ran ./configure and watched the output of configure to verify that everything completed successfully.

3.5 You might wish to add a step with make clean between steps 3 and 4 to remove any files created with the failed compile effort before doing a new compile with step 4.

  1. I then ran make and watched for a successful completion.

  2. Following the completion of step 4 I ran sudo make install and the jbig2 program was installed as /usr/bin/jbig2

If you see that steps 3 or 4 do not successfully complete then going forward is not possible. The errors that caused the failure must be solved first.