Kareadita / Kavita

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
http://www.kavitareader.com
GNU General Public License v3.0
5.88k stars 300 forks source link

Kavita on Alpine can't open PDFs #1507

Open RealStickman opened 2 years ago

RealStickman commented 2 years ago

When running Kavita on Alpine Linux, PDF files can't be read, have a length of 0 and are without a cover.

To Reproduce Steps to reproduce the behavior:

  1. Run Alpine linux
  2. Download latest kavita-linux-musl-x64 release
  3. Install dependencies on alpine (noted below)
  4. Add library with PDF file

Error message
Error messages when a library with a PDF file is scanned (first warning) and Kavita tries to generate a cover (second warning)

warn: API.Services.BookService[0]
      [BookService] There was an exception getting number of pages, defaulting to 0
      System.DllNotFoundException: Unable to load shared library 'pdfium' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libpdfium: No such file or directory
         at Docnet.Core.Bindings.fpdf_view.__Internal.FPDF_InitLibrary()
         at Docnet.Core.Bindings.fpdf_view.FPDF_InitLibrary()
         at Docnet.Core.DocLib..ctor()
         at Docnet.Core.DocLib.get_Instance()
         at API.Services.BookService.GetNumberOfPages(String filePath) in C:\Users\josep\Documents\Projects\KavitaOrg\Kavita\API\Services\BookService.cs:line 485
info: API.Services.Tasks.Scanner.ProcessSeries[0]
      [ScannerService] Finished series update on Sanders, Rob in 436 ms
warn: API.Services.BookService[0]
      [BookService] There was a critical error and prevented thumbnail generation on /tmp_alpine_kavita/pdf/Sanders, Rob/Total War_ Lords of Chaos/Total War_ Lords of Chaos - Rob Sanders.pdf. Defaulting to no cover image
      System.DllNotFoundException: Unable to load shared library 'pdfium' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libpdfium: No such file or directory
         at Docnet.Core.Bindings.fpdf_view.__Internal.FPDF_InitLibrary()
         at Docnet.Core.Bindings.fpdf_view.FPDF_InitLibrary()
         at Docnet.Core.DocLib..ctor()
         at Docnet.Core.DocLib.get_Instance()
         at API.Services.BookService.GetPdfCoverImage(String fileFilePath, String fileName, String outputDirectory) in C:\Users\josep\Documents\Projects\KavitaOrg\Kavita\API\Services\BookService.cs:line 911
info: API.Services.MetadataService[0]
      [MetadataService] Updated covers for Sanders, Rob in 28 milliseconds

Expected behavior The PDF should be readable and have a cover

Screenshots Looks like this in the web interface
image The file can't be opened, with an error that Kavita can't read the archive
image

Desktop (please complete the following information):

Additional repositories were enabled to get all dependencies (pretty much copied from Ubuntu Dockerfile).
Here's the /etc/apk/repositories file

http://eu.edge.kernel.org/alpine/v3.16/main
http://eu.edge.kernel.org/alpine/v3.16/community
@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing

Installing dependencies:

apk add icu-dev libssl1.1 curl libgdiplus@testing

Additional context I did try the method of removing libvips.so.42 as noted in this issue here
The vips package was installed to provide the library instead. No change.
Alpine uses musl libc instead of glibc.

The CPU I use to run alpine supports sse4_2 (marked with stars)

alpine-test:/kavita# cat /proc/cpuinfo | grep sse4_2
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 **sse4_2** x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero arat overflow_recov succor

OS Release output

alpine-test:/kavita# cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.2
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
RealStickman commented 2 years ago

Since I'd already pretty much finalized a container image for Kavita on Alpine, I'll share it here.
It's modified to launch you into the interactive shell instead of starting Kavita for easier poking around.
Alpine doesn't use bash, so I modified entrypoint.sh to use /bin/sh as shebang. No other changes were necessary.

https://gist.github.com/RealStickman/41beffac2e973378ce319ab9d15eeb4c

majora2007 commented 1 year ago

I put this as on-hold for myself, but opening it up to the community to help out here.

rufanov commented 1 year ago

See @docnet/issues/7 - it's issue of docnet - they bundle pdfium library compiled not against musl..

So i see to ways to overcome this:

  1. Make fork of docnet that will be bundled with musl-based pdfium.
  2. Use something else for rendering pdf to images on linux/osx(for example - any bindings of ghostpdf or imagemagick)
RedKage commented 1 month ago

Yo, I'm from the future

Here's what I did to make this work

apk add vips apk add gcompat apk add libspng

Then deleted the libvips.so from the Kavita folder. Then replaced the pdfium.so from the Kavita folder with a musl build from https://github.com/bblanchon/pdfium-binaries. I renamed the libpdfium.so to pdfium.so and replaced the one in Kavita. Then force scan in Kavita

Seems to work. I can now read PDFs, and I get to see the cover image as well.

This means, a proper pdfium binary could be included in the Kavita musl build now I think, to save us the trouble