Pdf2Image 库无法读取使用 DocuSign 签名的 pdf

Kar*_*B.G 8 poppler docusignapi pdftoppm

我正在尝试将使用 DocuSign 签名的 pdf 转换为图像格式。我们在 Convert_from_path 方法中遇到错误。代码及错误如下所示:

import pdf2image

data=pdf2image.convert_from_path('name.pdf')

PDFPageCountError: Unable to get page count.
Syntax Error: Gen inside xref table too large (bigger than INT_MAX)
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Invalid XRef entry
Syntax Error: Invalid XRef entry
Syntax Error: Top-level pages object is wrong type (null)
Command Line Error: Wrong page range given: the first page (1) can not be after the last page (0).
Run Code Online (Sandbox Code Playgroud)

Gab*_*les 10

我在这里请求 poppler 添加 Ubuntu 的安装说明,即使只是链接到这个答案。我的请求很快被拒绝并关闭。如果您希望看到 poppler 更好地支持在世界上至少第四大最受欢迎的操作系统(Ubuntu)上安装和构建自己的产品,请投票支持此请求以表示您的支持。

pdftoppm/Poppler 需要更新。看这里:

  1. 由@thijs123 回答
  2. https://gitlab.freedesktop.org/poppler/poppler/-/issues/1014(感谢@Bohumir Zamecnik 的评论

如何pdftoppm在 Linux Ubuntu 上安装/升级到最新版本的 Poppler/(撰写本文时版本 22.11.0):

在 Ubuntu 20.04 上测试:

1. 首先,尝试从最新的 Linux Ubuntu 发行版进行安装:

# check current version
# Mine shows: "pdftoppm version 0.86.1"
pdftoppm -v

# try to update it
sudo apt update
sudo apt install poppler-utils

# check current version again
pdftoppm -v

# Now run the `pdftoppm` command again to convert a PDF to a bunch of TIF files,
# for example:
pdftoppm "My PDF Password" -tiff -r 300 "in.pdf" "path/to/output/dir"
# OR (if you don't have a password on the PDF):
pdftoppm -tiff -r 300 "in.pdf" "path/to/output/dir"

# If it works, you're done! Otherwise, upgrade poppler by building it from
# source, as shown below.
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 20.04 上,我的输出中的一行sudo apt install poppler-utils显示:

poppler-utils is already the newest version (0.86.1-0ubuntu1).
Run Code Online (Sandbox Code Playgroud)

这意味着它没有为我升级 poppler,而且我仍然拥有旧版本。所以,我必须继续前进。

如果上述方法对您有效(例如,因为您使用的是 Ubuntu 22.04 或更高版本),请停止。但是,上面的过程对我来说不起作用。所以,我们需要从源代码安装。

2.从源代码安装以获取最新版本的poppler并pdftoppm

以下是有关如何从源代码安装 poppler 的说明。看起来很多,但是非常重复,并且一次又一次地遵循相同的模式来手动安装一堆依赖项aptitude,所以不要害怕。只需阅读说明即可轻松完成。

1.下载源码

poppler-utils is already the newest version (0.86.1-0ubuntu1).
Run Code Online (Sandbox Code Playgroud)

2.安装依赖

# First, check your current version. 
# Mine shows: "pdftoppm version 0.86.1"
pdftoppm -v

# Now go here and look for the latest download link and see what URL it points
# to: https://poppler.freedesktop.org/ 
# Under the "Download" section I see: 
#
#       The latest stable release is poppler-22.11.0.tar.xz, released on
#       November 1, 2022:
#
# Hovering my mouse over the download link shows it to be the link below. 
# **Update the link and version in all commands below.**

# Download it
wget https://poppler.freedesktop.org/poppler-22.11.0.tar.xz
# Extract the compressed file and cd into the extracted dir
tar -xf poppler-22.11.0.tar.xz
cd poppler-22.11.0


# Build and install it. See the "INSTALL" file in this dir for *some* level of 
# help. Most of my instructions below are NOT in there :(.

mkdir -p build
cd build
git clone git://git.freedesktop.org/git/poppler/test
Run Code Online (Sandbox Code Playgroud)

3. 构建 poppler 并重新测试pdftoppm以确保它已升级并且现在可以工作

sudo apt update

# Install the "easy" dependencies first:
# I expect these dependencies to install on Ubuntu 20.04 without issue
sudo apt install \
    libfreetype-dev \
    libfontconfig-dev \
    libboost-dev \
    libpng-dev \
    zlib1g-dev \
    liblcms2-dev \
    libcurl4 \
    libcurl4-gnutls-dev

# Install the "hard" dependencies second:
# Try this too, but this may not work for you. If it fails, see below. I expect
# these dependencies to NOT install on Ubuntu 20.04 without issue. If they fail
# to install, you will use `aptitude` to install the failed ones instead, as I
# explain and do below.
sudo apt install \
    libjpeg-dev \
    libcairo-dev \
    libopenjp2-7-dev \
    libtiff-dev \
    libcurl4-gnutls-dev \
    libnss3-dev

# When I run `sudo apt install libjpeg-dev` alone, for instance, I see the
# following output errors:
#
#       Reading package lists... Done
#       Building dependency tree       
#       Reading state information... Done
#       Some packages could not be installed. This may mean that you have
#       requested an impossible situation or if you are using the unstable
#       distribution that some required packages have not yet been created
#       or been moved out of Incoming.
#       The following information may help to resolve the situation:
#       
#       The following packages have unmet dependencies:
#        libjpeg-dev : Depends: libjpeg8-dev but it is not going to be installed
#       E: Unable to correct problems, you have held broken packages.

# So, we will use the `aptitude` package installer tool to to solve that.
# First, install aptitude.
sudo apt install aptitude

# Install `libjpeg-dev` via `aptitude`:
sudo aptitude install libjpeg-dev
#
# Assuming your output looks the same as mine, and the options it gives you are
# the same and in the same order, choose **no** then **yes** to downgrade
# `libjpeg-turbo8`, thereby allowing `libjpeg-dev` to install. See the arrows
# (<=========================) below which I use to indicate where I make my
# selections in the interactive prompts during the installation process via
# the 'aptitude' installation tool:
#
#
#       $ sudo aptitude install libjpeg-dev
#       The following NEW packages will be installed:
#         libjpeg-dev libjpeg-turbo8-dev{ab} libjpeg8-dev{a} 
#       0 packages upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
#       Need to get 238 kB/241 kB of archives. After unpacking 1,041 kB will be used.
#       The following packages have unmet dependencies:
#        libjpeg-turbo8-dev : Depends: libjpeg-turbo8 (= 2.0.3-0ubuntu1) but 2.0.3-0ubuntu1.20.04.3 is installed
#       The following actions will resolve these dependencies:
#       
#            Keep the following packages at their current version:
#       1)     libjpeg-dev [Not Installed]                        
#       2)     libjpeg-turbo8-dev [Not Installed]                 
#       3)     libjpeg8-dev [Not Installed]                       
#       
#       
#       
#       Accept this solution? [Y/n/q/?] n           <=========================
#       The following actions will resolve these dependencies:
#       
#            Downgrade the following packages:                                        
#       1)     libjpeg-turbo8 [2.0.3-0ubuntu1.20.04.3 (now) -> 2.0.3-0ubuntu1 (focal)]
#       
#       
#       
#       Accept this solution? [Y/n/q/?] y           <=========================
#       The following packages will be DOWNGRADED:
#         libjpeg-turbo8 
#       The following NEW packages will be installed:
#         libjpeg-dev libjpeg-turbo8-dev{a} libjpeg8-dev{a} 
#       0 packages upgraded, 3 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
#       Need to get 356 kB/359 kB of archives. After unpacking 1,040 kB will be used.
#       Do you want to continue? [Y/n/?] y          <=========================
#       Get: 1 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libjpeg-turbo8 amd64 2.0.3-0ubuntu1 [118 kB]
#       Get: 2 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libjpeg-turbo8-dev amd64 2.0.3-0ubuntu1 [238 kB]
#       Fetched 356 kB in 1s (490 kB/s)             
#       dpkg: warning: downgrading libjpeg-turbo8:amd64 from 2.0.3-0ubuntu1.20.04.3 to 2.0.3-0ubuntu1
#       (Reading database ... 474322 files and directories currently installed.)
#       Preparing to unpack .../libjpeg-turbo8_2.0.3-0ubuntu1_amd64.deb ...
#       Unpacking libjpeg-turbo8:amd64 (2.0.3-0ubuntu1) over (2.0.3-0ubuntu1.20.04.3) ...
#       Selecting previously unselected package libjpeg-turbo8-dev:amd64.
#       Preparing to unpack .../libjpeg-turbo8-dev_2.0.3-0ubuntu1_amd64.deb ...
#       Unpacking libjpeg-turbo8-dev:amd64 (2.0.3-0ubuntu1) ...
#       Selecting previously unselected package libjpeg8-dev:amd64.
#       Preparing to unpack .../libjpeg8-dev_8c-2ubuntu8_amd64.deb ...
#       Unpacking libjpeg8-dev:amd64 (8c-2ubuntu8) ...
#       Selecting previously unselected package libjpeg-dev:amd64.
#       Preparing to unpack .../libjpeg-dev_8c-2ubuntu8_amd64.deb ...
#       Unpacking libjpeg-dev:amd64 (8c-2ubuntu8) ...
#       Setting up libjpeg-turbo8:amd64 (2.0.3-0ubuntu1) ...
#       Setting up libjpeg-turbo8-dev:amd64 (2.0.3-0ubuntu1) ...
#       Setting up libjpeg8-dev:amd64 (8c-2ubuntu8) ...
#       Setting up libjpeg-dev:amd64 (8c-2ubuntu8) ...
#       Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

# Install `libcairo-dev` the same way and with the same selections:
sudo aptitude install libcairo-dev
#
#       $ sudo aptitude install libcairo-dev
#       Note: selecting "libcairo2-dev" instead of the virtual package "libcairo-dev"
#       The following NEW packages will be installed:
#         libcairo-script-interpreter2{a} libcairo2-dev libice-dev{a} libpixman-1-dev{a} libpthread-stubs0-dev{a} libsm-dev{a} libx11-dev{ab} libxau-dev{a} libxcb-render0-dev{a} libxcb-shm0-dev{a} libxcb1-dev{a} 
#         libxdmcp-dev{a} libxext-dev{a} libxrender-dev{a} x11proto-core-dev{a} x11proto-dev{a} x11proto-xext-dev{a} xorg-sgml-doctools{a} xtrans-dev{a} 
#       0 packages upgraded, 19 newly installed, 0 to remove and 0 not upgraded.
#       Need to get 2,569 kB of archives. After unpacking 10.5 MB will be used.
#       The following packages have unmet dependencies:
#        libx11-dev : Depends: libx11-6 (= 2:1.6.9-2ubuntu1) but 2:1.6.9-2ubuntu1.2 is installed
#       The following actions will resolve these dependencies:
#       
#            Keep the following packages at their current version:
#       1)     libcairo2-dev [Not Installed]                      
#       2)     libx11-dev [Not Installed]                         
#       3)     libxext-dev [Not Installed]                        
#       4)     libxrender-dev [Not Installed]                     
#       
#       
#       
#       Accept this solution? [Y/n/q/?] n       <=========================
#       The following actions will resolve these dependencies:
#       
#            Downgrade the following packages:                                
#       1)     libx11-6 [2:1.6.9-2ubuntu1.2 (now) -> 2:1.6.9-2ubuntu1 (focal)]
#       
#       
#       
#       Accept this solution? [Y/n/q/?] y       <=========================
#       The following packages will be DOWNGRADED:
#         libx11-6 
#       The following NEW packages will be installed:
#         libcairo-script-interpreter2{a} libcairo2-dev libice-dev{a} libpixman-1-dev{a} libpthread-stubs0-dev{a} libsm-dev{a} libx11-dev{a} libxau-dev{a} libxcb-render0-dev{a} libxcb-shm0-dev{a} libxcb1-dev{a} 
#         libxdmcp-dev{a} libxext-dev{a} libxrender-dev{a} x11proto-core-dev{a} x11proto-dev{a} x11proto-xext-dev{a} xorg-sgml-doctools{a} xtrans-dev{a} 
#       0 packages upgraded, 19 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
#       Need to get 3,141 kB of archives. After unpacking 10.5 MB will be used.
#       Do you want to continue? [Y/n/?] y      <=========================

# Install `libopenjp2-7-dev` the same way and with the same selections:
sudo aptitude install libopenjp2-7-dev
#
#       $ sudo aptitude install libopenjp2-7-dev
#       The following NEW packages will be installed:
#         libopenjp2-7-dev{b} 
#       0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
#       Need to get 26.7 kB of archives. After unpacking 168 kB will be used.
#       The following packages have unmet dependencies:
#        libopenjp2-7-dev : Depends: libopenjp2-7 (= 2.3.1-1ubuntu4) but 2.3.1-1ubuntu4.20.04.1 is installed
#       The following actions will resolve these dependencies:
#       
#            Keep the following packages at their current version:
#       1)     libopenjp2-7-dev [Not Installed]                   
#       
#       
#       
#       Accept this solution? [Y/n/q/?] n       <=========================
#       The following actions will resolve these dependencies:
#       
#            Downgrade the following packages:                                      
#       1)     libopenjp2-7 [2.3.1-1ubuntu4.20.04.1 (now) -> 2.3.1-1ubuntu4 (focal)]
#       
#       
#       
#       Accept this solution? [Y/n/q/?] y       <=========================
#       The following packages will be DOWNGRADED:
#         libopenjp2-7 
#       The following NEW packages will be installed:
#         libopenjp2-7-dev 
#       0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
#       Need to get 168 kB of archives. After unpacking 168 kB will be used.
#       Do you want to continue? [Y/n/?] y      <=========================

# Install `libtiff-dev` the same way and with the same selections:
sudo aptitude install libtiff-dev
#
#       $ sudo aptitude install libtiff-dev
#       The following NEW packages will be installed:
#         libjbig-dev{a} liblzma-dev{ab} libtiff-dev{b} libtiffxx5{a} 
#       0 packages upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
#       Need to get 461 kB of archives. After unpacking 1,796 kB will be used.
#       The following packages have unmet dependencies:
#        libtiff-dev : Depends: libtiff5 (= 4.1.0+git191117-2build1) but 4.1.0+git191117-2ubuntu0.20.04.3 is installed
#        liblzma-dev : Depends: liblzma5 (= 5.2.4-1) but 5.2.4-1ubuntu1.1 is installed
#       The following actions will resolve these dependencies:
#       
#            Keep the following packages at their current version:
#       1)     liblzma-dev [Not Installed]                        
#       2)     libtiff-dev [Not Installed]                        
#       
#       
#       
#       Accept this solution? [Y/n/q/?] n       <=========================
#       The following actions will resolve these dependencies:
#       
#            Downgrade the following packages:                                                     
#       1)     liblzma5 [5.2.4-1ubuntu1.1 (now) -> 5.2.4-1 (focal)]                                
#       2)     libtiff5 [4.1.0+git191117-2ubuntu0.20.04.3 (now) -> 4.1.0+git191117-2build1 (focal)]
#       
#       
#       
#       Accept this solution? [Y/n/q/?] y       <=========================
#       The following packages will be DOWNGRADED:
#         liblzma5 libtiff5 
#       The following NEW packages will be installed:
#         libjbig-dev{a} liblzma-dev{a} libtiff-dev libtiffxx5{a} 
#       0 packages upgraded, 4 newly installed, 2 downgraded, 0 to remove and 0 not upgraded.
#       Need to get 715 kB of archives. After unpacking 1,788 kB will be used.
#       Do you want to continue? [Y/n/?] y      <=========================

# Install `libcurl4-gnutls-dev` the same way and with the same selections:
sudo aptitude install libcurl4-gnutls-dev
#
#       $ sudo aptitude install libcurl4-gnutls-dev
#       The following NEW packages will be installed:
#         libcurl4-gnutls-dev{b} 
#       0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
#       Need to get 318 kB of archives. After unpacking 1,525 kB will be used.
#       The following packages have unmet dependencies:
#        libcurl4-gnutls-dev : Depends: libcurl3-gnutls (= 7.68.0-1ubuntu2) but 7.68.0-1ubuntu2.12 is installed
#       The following actions will resolve these dependencies:
#       
#            Keep the following packages at their current version:
#       1)     libcurl4-gnutls-dev [Not Installed]                
#       
#       
#       
#       Accept this solution? [Y/n/q/?] n       <=========================
#       The following actions will resolve these dependencies:
#       
#            Downgrade the following packages:                                      
#       1)     libcurl3-gnutls [7.68.0-1ubuntu2.12 (now) -> 7.68.0-1ubuntu2 (focal)]
#       
#       
#       
#       Accept this solution? [Y/n/q/?] y       <=========================
#       The following packages will be DOWNGRADED:
#         libcurl3-gnutls 
#       The following NEW packages will be installed:
#         libcurl4-gnutls-dev 
#       0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
#       Need to get 549 kB of archives. After unpacking 1,524 kB will be used.
#       Do you want to continue? [Y/n/?] y      <=========================

# Install `libnss3-dev` the same way and with the same selections:
sudo aptitude install libnss3-dev
#
#       $ sudo aptitude install libnss3-dev
#       The following NEW packages will be installed:
#         libnspr4-dev{a} libnss3-dev{b} 
#       0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
#       Need to get 437 kB of archives. After unpacking 2,611 kB will be used.
#       The following packages have unmet dependencies:
#        libnss3-dev : Depends: libnss3 (= 2:3.49.1-1ubuntu1) but 2:3.49.1-1ubuntu1.8 is installed
#       The following actions will resolve these dependencies:
#       
#            Keep the following packages at their current version:
#       1)     libnss3-dev [Not Installed]                        
#       
#       
#       
#       Accept this solution? [Y/n/q/?] n       <=========================
#       The following actions will resolve these dependencies:
#       
#            Downgrade the following packages:                                 
#       1)     libnss3 [2:3.49.1-1ubuntu1.8 (now) -> 2:3.49.1-1ubuntu1 (focal)]
#       
#       
#       
#       Accept this solution? [Y/n/q/?] y       <=========================
#       The following packages will be DOWNGRADED:
#         libnss3 
#       The following NEW packages will be installed:
#         libnspr4-dev{a} libnss3-dev 
#       0 packages upgraded, 2 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
#       Need to get 1,608 kB of archives. After unpacking 2,473 kB will be used.
#       Do you want to continue? [Y/n/?] y      <=========================
Run Code Online (Sandbox Code Playgroud)

参考:

  1. 经过很多小时的反复试验和我自己的挖掘。
  2. 主要网站: https: //poppler.freedesktop.org/
  3. Gitlab 上的仓库:https ://gitlab.freedesktop.org/poppler/poppler
  4. Gitlab 上的存储库安装说明:https://gitlab.freedesktop.org/poppler/poppler/-/blob/master/INSTALL
  5. 如何提取*.tar.xz文件:https://linuxize.com/post/how-to-extract-unzip-tar-xz-file/
  6. 强制安装 apt-get
  7. cmake 列出所有构建选项(-DOPTION_NAME):
  8. 我将说明(稍作修改)转移到 Dockerfile 中以进行快速测试:https://gist.github.com/FabianTe/f0225b5a2b7e55ff2b86534ba29c9451 (2认同)

小智 8

此问题与旧版本的 poppler 有关。升级到最新版本(21.03.0)可以解决该问题。

  • 这就是问题:https://gitlab.freedesktop.org/poppler/poppler/-/issues/1014 (2认同)