pdf2image的poppler-Linux支持安装教程

2024-01-12 16:44

本文主要是介绍pdf2image的poppler-Linux支持安装教程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 使用目的
    • 下载源码
    • 安装依赖
      • 直接安装的依赖
      • 需要编译的依赖
        • 1、libassuan
        • 2、gpgme
        • 3、libb2
        • 4、pcre2
        • 5、Qt6
    • 命令行编译命令-poppler
    • 测试
    • 小结

使用目的

我想要解决的问题是以最快的速度抽取PDF中的图片,再和对应文本进行关联,最终适配到LangChain上
经过调研pdf2image的covert_from_byte的sthread_count 参数,可以启动多线程会大大加快转换速度

我的系统是openEuler,命令使用和CentOS一样

下载源码

https://poppler.freedesktop.org/
我选择的是 poppler-24.01.0.tar.xz

安装依赖

直接安装的依赖

sudo yum install nss-devel fontconfig-devel libfreetype6-dev libtiff-devel mesa-libGL-devel ninja-build systemd-devel pcre2 pcre2-devel glib2 glib2-devel autoconf automake libtool harfbuzz-devel lcms2-devel libcurl-devel poppler-cpp-devel

需要编译的依赖

1、libassuan
wget https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.5.tar.bz2
tar xjf libassuan-2.5.5.tar.bz2
cd libassuan-2.5.5
./configure --prefix=/usr/local
make -j4
sudo make install
2、gpgme
wget https://www.gnupg.org/ftp/gcrypt/gpgme/gpgme-1.19.0.tar.bz2
tar xjf gpgme-1.19.0.tar.bz2
cd gpgme-1.19.0
./configure --prefix=/usr/local
make -j4
sudo make install
3、libb2
git clone https://github.com/BLAKE2/libb2.git
cd libb2
autoreconf -fi
./configure
make
sudo find / -name libb2.pc 2>/dev/null
# /home/HwHiAiUser/work/pdf_to_sql/BLAKE2/libb2/libb2.pc
export PKG_CONFIG_PATH=/path/to/libb2:$PKG_CONFIG_PATH
4、pcre2
rm /home/anaconda3/cmake/pcre2-config.cmake
rm /home/anaconda3/cmake/pcre2-config-version.cmake # 删除虚拟环境中的,防止后面干扰
rpm -ql pcre2-devel # 查看pcre2的安装位置,方便后面设置路径,参考:
# -DPCRE2_INCLUDE_DIRS=/usr/include -DPCRE2_LIBRARY=/usr/lib64/libpcre2.so
5、Qt6

下载qt-everywhere-src-6.2.4.tar.xz

tar xf qt-everywhere-src-6.2.4.tar.xz
cd qt-everywhere-src-6.2.4
vim CMakeLists.txt
# 在第4行开始加入
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;/usr/lib64;/usr/lib;/home/anaconda3/lib")
# 保存后运行
./configure -DPCRE2_INCLUDE_DIRS=/usr/include -DPCRE2_LIBRARY=/usr/lib64/libpcre2.so -DPCRE2_FIND_COMPONENTS="8BIT;16BIT"
# 运行成功后显示
# -- Build files have been written to: /home/HwHiAiUser/work/pdf_to_sql/qt-everywhere-src-6.2.4
cmake --build . --parallel
make

命令行编译命令-poppler

我无法编译成功QT,五花八门的报错
所以只能关闭QT特性

cd poppler-24.01.0.tar.xz
vim CMakeCache.txt
ENABLE_QT5:BOOL=OFF 
ENABLE_QT6:BOOL=OFF

一共4个全部从NO改为OFF

mkdir build
cd build 
cmake .. 
make 
make install

最终成功安装

export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH

添加一下路径

pdfinfo

查看版本输出

pdfinfo version 24.01.0
Copyright 2005-2024 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011, 2022 Glyph & Cog, LLC
Usage: pdfinfo [options] <PDF-file>-f <int>             : first page to convert-l <int>             : last page to convert-box                 : print the page bounding boxes-meta                : print the document metadata (XML)-custom              : print both custom and standard metadata-js                  : print all JavaScript in the PDF-struct              : print the logical document structure (for tagged files)-struct-text         : print text contents along with document structure (for tagged files)-isodates            : print the dates in ISO-8601 format-rawdates            : print the undecoded date strings directly from the PDF file-dests               : print all named destinations in the PDF-url                 : print all URLs inside PDF objects (does not scan text content)-enc <string>        : output text encoding name-listenc             : list available encodings-opw <string>        : owner password (for encrypted files)-upw <string>        : user password (for encrypted files)-v                   : print copyright and version info-h                   : print usage information-help                : print usage information--help               : print usage information-?                   : print usage information

测试

import pdfplumber
import PyPDF2
import pdf2image
from pdf2image import convert_from_path,convert_from_bytes
import tempfile
from pdf2image.exceptions import PDFInfoNotInstalledError, PDFPageCountError, PDFSyntaxError
import osfile_path = r'xxx.pdf' # PDF 文件路径
dir_path = r'output' # 存放图片的文件夹def pdf2image2(file_path, dir_path):images = convert_from_path(file_path, dpi=300)for image in images:if not os.path.exists(dir_path):os.makedirs(dir_path)image.save(dir_path + f'\img_{images.index(image)}.png', 'PNG')pdf2image2(file_path, dir_path)

小结

也许直接安装poppler-cpp-devel就可以成功,但是我是最后才安装的
pdf2image就是需要libpoppler.so.133,我现在也不清楚/usr/local/lib64中的libpoppler.so.133是poppler-cpp-devel安装的,还是编译poppler安装的了

sudo find / -name libpoppler.so.133
/usr/local/lib64/libpoppler.so.133
/home/HwHiAiUser/work/pdf_to_sql/poppler-24.01.0/build/libpoppler.so.133
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/HwHiAiUser/work/pdf_to_sql/poppler-24.01.0/build:$LD_LIBRARY_PATH

如果上述命令无效

vim /etc/ld.so.conf
# 添加:/usr/local/lib64
sudo ldconfig

编译QT6时出现了报错error: macro names must be identifiers
意义:宏名称必须是标识符,C++和C中命名变量时不能以数字开头,定义宏时也不能
在qt-everywhere-src-6.2.4/qtbase/src/3rdparty这个文件这里,就是数字开头,我尝试修改,无效
还有的报错是说磁盘空间不够,xxx包不支持等,依赖太多了

这篇关于pdf2image的poppler-Linux支持安装教程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/598504

相关文章

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

Centos7安装Mongodb4

1、下载源码包 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz 2、解压 放到 /usr/local/ 目录下 tar -zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgzmv mongodb-linux-x86_64-rhel70-4.2.1/

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

Centos7安装JDK1.8保姆版

工欲善其事,必先利其器。这句话同样适用于学习Java编程。在开始Java的学习旅程之前,我们必须首先配置好适合的开发环境。 通过事先准备好这些工具和配置,我们可以避免在学习过程中遇到因环境问题导致的代码异常或错误。一个稳定、高效的开发环境能够让我们更加专注于代码的学习和编写,提升学习效率,减少不必要的困扰和挫折感。因此,在学习Java之初,投入一些时间和精力来配置好开发环境是非常值得的。这将为我

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal