把多张图片快速合并成一个pdf文件
08 September 2020
把多张图片快速合并成一个pdf文件
img2pdf方案
安装img2pdf,参考:https://gitlab.mister-muffin.de/josch/img2pdf;
建意把源码下下来,在源码目录下直接使用pip3 install .
安装,安装好后使用以下命令即可把多张图片转成一个pdf。
img2pdf *.png *.jpg -o out.pdf
使用万能的 imagemagick
使用brew安装好 imagemagick
brew install imagemagick
如果安装失败,使用sudo chown -R $(whoami) $(brew --prefix)/*
,或者:
sudo mkdir /usr/local/Frameworks
sudo chown $USER /usr/local/Frameworks
转成pdf
convert *.jpg output.pdf
convert -quality 60 *.jpg output.pdf
如果是window,可以使用 cygwin 安装 imagemagick 。
把PDF导出成一张张image/html/text
使用XpdfReader项目:https://www.xpdfreader.com/pdftoppm-man.html
pdftopng ./aaa.pdf ./aaa # 导出成png图片
pdftohtml ./aaa.pdf ./aaa # 导出html并放到生成的aaa目录下
pdftotext ./aaa.pdf ./text # 导出html并放到生成的aaa目录下
如果是要把html生成为pdf
使用wkhtmltopdf是一个不错的选择,官方地址:https://wkhtmltopdf.org/
wkhtmltopdf http://localhost/aaaa.html $HOME/doc_pdf/check.pdf
其他
imagemagick安装好后,可能会有以下环境变量设置的提示:
==> glib
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> docbook
To use the DocBook package in your XML toolchain,
you need to add the following to your ~/.bashrc:
export XML_CATALOG_FILES="/usr/local/etc/xml/catalog"
==> gnu-getopt
gnu-getopt is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have gnu-getopt first in your PATH run:
echo 'export PATH="/usr/local/opt/gnu-getopt/bin:$PATH"' >> ~/.zshrc
Bash completion has been installed to:
/usr/local/opt/gnu-getopt/etc/bash_completion.d
==> libtool
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.
==> guile
Guile libraries can now be installed here:
Source files: /usr/local/share/guile/site/3.0
Compiled files: /usr/local/lib/guile/3.0/site-ccache
Extensions: /usr/local/lib/guile/3.0/extensions
Add the following to your .bashrc or equivalent:
export GUILE_LOAD_PATH="/usr/local/share/guile/site/3.0"
export GUILE_LOAD_COMPILED_PATH="/usr/local/lib/guile/3.0/site-ccache"
export GUILE_SYSTEM_EXTENSIONS_PATH="/usr/local/lib/guile/3.0/extensions"
==> unbound
To have launchd start unbound now and restart at startup:
sudo brew services start unbound
==> gnutls
If you are going to use the Guile bindings you will need to add the following
to your .bashrc or equivalent in order for Guile to find the TLS certificates
database:
export GUILE_TLS_CERTIFICATE_DIRECTORY=/usr/local/etc/gnutls/
==> icu4c
icu4c is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).
If you need to have icu4c first in your PATH run:
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc
For compilers to find icu4c you may need to set:
export LDFLAGS="-L/usr/local/opt/icu4c/lib"
export CPPFLAGS="-I/usr/local/opt/icu4c/include"
For pkg-config to find icu4c you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"