技术分享 Centos 7 源代码安装 pdf2htmlEX 避免遇坑

kakax · 2023年11月25日 · 最后由 kaka.hu 回复于 2023年11月25日 · 104 次阅读

因为官方提供安装包是支持 Ubuntu、Alpine 系统,Centos 需要手动编译进行安装,我安装版本 pdf2htmlEX v0.18.8

安装依赖包

pdf2htmlEX v0.18.8 版本依赖两个重要库, Poppler 0.89.0 版本,FontForge 20200314 版本,依赖库版本很重,需要看官方文档确认版本

yum install  cmake gcc gcc-c++ gnu-getopt java-1.8.0-openjdk libpng-devel fontforge-devel cairo-devel poppler-devel libspiro-devel   poppler-data libjpeg-turbo-devel git fontconfig-devel glibc-static glibc-devel libtool-ltdl-devel zlib-devel   poppler-glib-devel   mk-configure.noarch libjpeg-turbo libtiff  giflib-devel libXt-devel  automake  bzip2  libuninameslist-devel libspiro dbus-python-devel pango-devel chrpath uuid-c++ uuid uthash-devel.noarch jpackage-utils.noarch gettext  libxml2-python27 libxml2-python26 python27-python-devel  libxslt-python26 libxslt  libxslt-devel python-devel python-javapackages.noarch –nogpgcheck  poppler-cpp poppler-cpp-devel libstdc++48-static openjpeg-devel  libjpeg libjpeg-devel libpng  freetype freetype-devel libxml2 libxml2-devel zlib  glibc glib2 glib2-devel  bzip2-devel  ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel libtool  libtool-libs libevent-devel libevent openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool-ltdl  bison vim wget  make crontabs mlocate ntp lrzsz autoconf libx* qt-*  qt4-devel libtiff libopen* gtk2 gtk2-devel gtk2-devel-docs  kernel-devel gtk-doc cjkuni-uming-fonts cjkuni-ukai-fonts

Poppler 安装

  • 进行解压
tar -xvf  poppler-0.89.0.tar.xz
  • 编译并安装
mkdir build
cd build
cmake .. -DBUILD_SHARED_LIBS=OFF
make
sudo make install
  • 指定环境变量,告诉编译器从哪里找头部文件 可以在~/.bashrc~/.bash_profile 设置环境变量
export CPLUS_INCLUDE_PATH=~/poppler-0.89.0:~/poppler-0.89.0/poppler:$CPLUS_INCLUDE_PATH
  • 重新载入环境变量
source ~/.bashrc  或  source ~/.bash_profile

FontForge

  • 编译并安装
mkdir build
cd build
cmake .. -DBUILD_SHARED_LIBS=OFF
make
sudo make install

pdf2htmlEX 安装

  • 将依赖库链接到项目目录下
ln -s   ~/pdf2htmlEX/poppler ~/poppler-0.89.0
ln -s   ~/pdf2htmlEX/fontforge ~/fontforge-20200314    
  • 编译并安装
cd ~/pdf2htmlEX/pdf2htmlEX

cmake .

安装 poppler 有可能遇到错误

  • libstdc++.so.6: error adding symbols: DSO missing from command line

    解决方案:通过排查是是执行 cmake -E cmake_link_script CMakeFiles/poppler-glib-demo.dir/link.txt LDFLAGS="-L/usr/lib64/libstdc++.so.6" 是CMakeFiles/poppler-glib-demo.dir/link.txt 文件添加-lstdc++ 指定库解决

  • glib/tests/pdfdrawbb.c:69:28: error: ‘optind’ undeclared (first use in this function)

    解决方法:poppler-0.89.0/glib/tests/pdfdrawbb.c 在文件头部添加 #include <getopt.h>解决

  • 如果找不到 libfontforge.a、libpoppler.a 文件,需要 cmake 需要关闭动态库构建-DBUILD_SHARED_LIBS=OFF

需要 登录 后方可回复