使用imagemagick将pdf转换为jpg时出现字体渲染错误

时间:2018-09-22 12:01:03

标签: pdf jpeg ghostscript ubuntu-18.04

我有一个pdf,我试图在装有Ubuntu 18.04 OS的数字海洋服务器上使用imagemagick转换为jpg图像。

当我在家用计算机(Ubuntu 16.04 OS,桌面版本)上执行此操作时,转换成功运行。

当我在服务器上运行相同的命令时,生成的图像在文本呈现方面存在问题。特别是在某些行上,我在文本中看到了矩形,如您在图像中看到的:

Error in displaying fonts

我想这与某些字体有关。所以我在原始的pdf上执行了pdffonts,显示为:

name                                 type              encoding        emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- --------- 
Helvetica-Bold                       Type 1            WinAnsi          no  no  no       8  0
Helvetica                            Type 1            WinAnsi          no  no  no       9  0 
e42697+DejaVuSans                    TrueType          WinAnsi         yes no  yes     10  0

所以现在我认为出现问题是因为Helvetica字体未嵌入pdf中。

我用来转换的命令如下:

convert invoice.pdf[0] -encoding WinAnsi -thumbnail 800x -background white -alpha remove -quality 95 -gravity center -format jpg jpg:out.jpg

所以问题是:有没有一种方法可以在convert命令中添加一些选项来避免该问题,还是可以在服务器上安装某些软件包?我已经尝试过-font选项,但没有成功。

以下是我使用的工具的版本:

$ convert --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 
http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib

$ ghostscript --version
9.22

感谢您的帮助。 如果您需要更多信息,请告诉我。

编辑 我还尝试从源代码中编译最新的imagemagick 7,但还是一样。

$ convert -list  configure

Path: /usr/local/lib/ImageMagick-7.0.8//config-Q16HDRI/configure.xml

Name           Value
-------------------------------------------------------------------------------
CC             gcc
CFLAGS         -I/usr/include/libxml2 -I/usr/include/libpng16  -                
I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 - 
I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux- 
gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -                
I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 - 
I/usr/include/OpenEXR  -I/usr/include/lqr-1 -I/usr/include/glib-2.0 - 
I/usr/lib/x86_64-linux-gnu/glib-2.0/include  -I/usr/include/freetype2 - 
I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 - 
I/usr/include/freetype2 -I/usr/include/libpng16 -pthread    -fopenmp -g -O2 
-Wall -mtune=core2 -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 - 
DMAGICKCORE_QUANTUM_DEPTH=16
CODER_PATH     /usr/local/lib/ImageMagick-7.0.8/modules-Q16HDRI/coders
CONFIGURE      ./configure  '--with-gslib=yes'
CONFIGURE_PATH /usr/local/etc/ImageMagick-7/
COPYRIGHT      Copyright (C) 1999-2018 ImageMagick Studio LLC
CPPFLAGS       -I/usr/local/include/ImageMagick-7
CXX            g++
CXXFLAGS       -g -O2 -pthread
DEFS           -DHAVE_CONFIG_H
DELEGATES      bzlib djvu mpeg fftw fontconfig freetype gslib jbig jng jpeg lcms lqr lzma openexr pango png ps tiff wmf x xml zlib
DISTCHECK_CONFIG_FLAGS  --disable-deprecated  --with-quantum-depth=16  --with-jemalloc=no  --with-umem=no  --with-autotrace=no  --with-fontpath=  --with-rsvg=no  --with-perl=no
DOCUMENTATION_PATH /usr/local/share/doc/ImageMagick-7
EXEC-PREFIX    /usr/local
EXECUTABLE_PATH /usr/local/bin
FEATURES       DPC HDRI Cipher OpenMP
FILTER_PATH    /usr/local/lib/ImageMagick-7.0.8/modules-Q16HDRI/filters
GIT_REVISION   14730
HOST           x86_64-pc-linux-gnu
INCLUDE_PATH   /usr/local/include/ImageMagick-7
LDFLAGS        -L/usr/local/lib
LIB_VERSION    0x708
LIB_VERSION_NUMBER 7,0,8,11
LIBRARY_PATH   /usr/local/lib/ImageMagick-7.0.8
LIBS            -ljbig -llcms2 -ltiff -lfreetype  -ljpeg -lgs -llqr-1 - 
lglib-2.0 -lpng16 -lz  -ldjvulibre -lfftw3   -lfontconfig -lfreetype    - 
lwmflite  -lXext -lXt   -lSM -lICE -lX11  -llzma -lbz2 -lIlmImf -lImath - 
lHalf -lIex -lIexMath -lIlmThread -lpthread  -lpangocairo-1.0 -lpango-1.0 - 
lgobject-2.0 -lglib-2.0 -lcairo   -lxml2  -lz    -lm -lgomp
NAME           ImageMagick
PCFLAGS        -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 - 
DMAGICKCORE_QUANTUM_DEPTH=16
PREFIX         /usr/local
QuantumDepth   16
RELEASE_DATE   2018-09-22
SHARE_PATH     /usr/local/share/ImageMagick-7
SHAREARCH_PATH /usr/local/lib/ImageMagick-7.0.8/config-Q16HDRI
TARGET_CPU     x86_64
TARGET_OS      linux-gnu
TARGET_VENDOR  pc
VERSION        7.0.8
WEBSITE        http://www.imagemagick.org

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       OpenMP
NAME           ImageMagick
QuantumDepth   16

编辑2

我能够将问题限制为ghostscript。 现在执行以下命令时,我也会遇到相同的问题:

$ gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 - 
sOutputFile=gs_out_300.png invoice.pdf
GPL Ghostscript 9.22 (2017-10-04)
Copyright (C) 2017 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusSans-Bold font from 
/usr/share/ghostscript/9.22/Resource/Font/NimbusSans-Bold... 4509328 2901747 2393680 1046799 3 done.
Loading NimbusSans-Regular font from /usr/share/ghostscript/9.22/Resource/Font/NimbusSans-Regular... 4575440 3079563 
2413880 1062624 3 done.

0 个答案:

没有答案