Pdf2图像库无法读取使用DocuSign签名的pdf



我正在尝试将使用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).

我在这里请求poppler添加Ubuntu的安装说明,即使只是链接到这个答案。我的请求很快被拒绝并结束了。如果你想看到poppler更好地支持在世界上第四流行的操作系统(Ubuntu(上安装和构建自己的产品,请投票支持这个请求

pdftoppm/Poppler需要更新。请参阅此处:

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

如何在Linux Ubuntu上安装/升级到最新版本的Poppler/pdftoppm(在撰写本文时为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.

在Ubuntu 20.04上,我从sudo apt install poppler-utils输出的其中一行说:

poppler-utils is already the newest version (0.86.1-0ubuntu1).

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

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

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

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

1.下载源代码

# 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

2.安装依赖项

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      <=========================

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

cmake -DTESTDATADRIR=./test -DCMAKE_INSTALL_MANDIR:PATH=/usr/local/share/man ..
time make
sudo make install
# re-initialize your bash terminal by re-sourcing your startup file
. ~/.bashrc
# Reload/find/link shared libraries from the new executable
sudo ldconfig "$(which pdftoppm)"  # PREFERRED
# OR (same thing on my system at least)
sudo ldconfig /usr/local/bin/pdftoppm
# Ensure your version is now newer than it was when we started!
# Mine now outputs `pdftoppm version 22.11.0`!
pdftoppm -v
# Now run the `pdftoppm` command again to convert a PDF to a bunch of TIF files,
# for example:
pdftoppm "My Optional 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"
# It should work now. Done!
# NB: the man pages may not be be updated for the newest executables you just
# built. So, you may need to use `pdftoppm --help` instead of `man pdftoppm`.

参考文献:

  1. Looooots的试错和我自己的挖掘,很多小时
  2. 主要网站:https://poppler.freedesktop.org/
  3. Gitlab上的Repo:https://gitlab.freedesktop.org/poppler/poppler
  4. Gitlab上的Repo安装说明: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(:https://stackoverflow.com/a/42945360/4561887
  8. 如何在Ubuntu上安装libcurl:https://askubuntu.com/a/78185/327339
  9. 如何安装zlib:https://itsfoss.com/install-zlib-ubuntu/
  10. [我的回购]:";语法错误:外部参照表内的Gen太大(大于INT_MAX("/"错误:"pdftoppm"失败。ret_code=1":https://github.com/ElectricRCAircraftGuy/PDF2SearchablePDF/issues/29
    1. 我的pdf2searchablepdfrepo使用poppler,可能需要poppler的升级版本
  11. 我了解到CCD_ 11的一个地方是:;破损包装";不允许我安装程序包

这个问题与旧版本的poppler有关。升级到最新版本(21.03.0(解决了这个问题。

您需要联系Pdf2Image以获得可能的解决方案,看起来升级应该修复它

相关内容

  • 没有找到相关文章

最新更新