问题描述
我使用的是 Spatie/pdfToImage ,该文件建立在鬼脚本和imagemagick上我的服务器:
I am using Spatie/pdfToImage that builds on ghost script and imagemagick to on my server:
- 使用mailgun路由从电子邮件中获取多页pdf.
- 将pdf保存在/docs_pdf文件夹中,例如file.pdf
- 使用foreach循环浏览每个页面,并将每个页面以png格式保存到/docs,例如file _#.png
在我使用laravel的地方->代客,一切正常.
locally where I use laravel -> valet everything works fine.
在我的服务器上,通过laravel使用数字海洋伪造了多页pdf的语言,该pdf的语言是瑞典语,从普通瑞典语转变为一堆随机字母和符号.
On my server using digital ocean through laravel forge the language in a multipaged pdf that is in swedish transforms from normal swedish to a bunch of random letters and signs.
左边是正确的(是的,是正确的.其瑞典语),右边是错误的:
The left is correct (yes, its true. Its Swedish) and the right is wrong:
有人建议我,这可能是服务器上缺少字体的问题. pdf中使用的字体:
Someone suggested to me that this is probably a matter of the font missing on the server. The fonts used in the pdf:
<</StemV 68/FontName/PSQHMO+FoundrySans-Normal/FontFile2 216 0 R/FontStretch/Normal/FontWeight 400/Flags 32/Descent -240/FontBBox[-40 -240 960 916]/Ascent 916/FontFamily(FoundrySans-Normal)/CapHeight 667/XHeight 465/Type/FontDescriptor/ItalicAngle 0>>
<</StemV 100/FontName/MLHPWU+FoundrySans-Medium/FontFile2 217 0 R/FontStretch/Normal/FontWeight 400/Flags 32/Descent -241/FontBBox[-42 -241 1008 916]/Ascent 916/FontFamily(FoundrySans-Medium)/CapHeight 667/XHeight 470/Type/FontDescriptor/ItalicAngle 0>>
<</StemV 68/FontName/SUEECI+FoundrySans-Normal/FontFile2 218 0 R/FontStretch/Normal/FontWeight 400/Flags 4/Descent -240/FontBBox[-40 -240 960 916]/Ascent 916/FontFamily(FoundrySans-Normal)/CapHeight 667/XHeight 465/Type/FontDescriptor/ItalicAngle 0>>
<</StemV 48/FontName/KIDDUY+FoundrySans-Light/FontFile2 9 0 R/FontStretch/Normal/FontWeight 400/Flags 32/Descent -248/FontBBox[-28 -248 978 924]/Ascent 924/FontFamily(FoundrySans-Light)/CapHeight 667/XHeight 458/Type/FontDescriptor/ItalicAngle 0>>
这是imagemagick和ghostscript中的字体配置: https://www.imagemagick.org/script/resources.php
Here is configuration of fonts in imagemagick and ghostscript:https://www.imagemagick.org/script/resources.php
如何解决?
更新:
我现在已经在新服务器上进行了全新安装.
I have now made a clean install on a new server.
安装了Imagick和spatie/pdfToImage
Installed Imagick and spatie/pdfToImage
根据KenS的建议,我参加了比赛
As suggested by KenS I ran
终端输出
forge@Server:~/app/storage/app/public/files$ gs -sDEVICE=png16m -o test_out%d.png file.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 2.
Page 1
Page 2
文档呈现相同=错误.
我完全不知所措..不知道下一步是什么.
I am at a complete loss.. Don't know what next step might be..
Update2:
我还运行了convert imagemagick突击队,并且img的渲染方式也相同.
I also run the convert imagemagick commando and the img rendered the same way also.
因此,即使我用ghostscript独奏,imagemagick或spatie/pdfToImage进行操作,它也会提供相同的输出结果
So even if I do it with ghostscript solo, imagemagick or spatie/pdfToImage it gives me the same output
推荐答案
最后使它起作用.首先,我想对KenS表示敬意,这确实对我有帮助,如果没有他,那是行不通的.
Finally got it to work. I want to first give kudos to KenS that really really helped me and without him it would not have worked.
这就是我所做的:
1-我删除了ghostscript:
1 - I removed ghostscript:
sudo apt-get purge --auto-remove ghostscript
然后
wget
https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs925/ghostscript-9.25.tar.gz
tar xvf ghostscript-9.25.tar.gz
tar xvf ghostscript-9.25.tar.gz
输入解压缩的文件夹并执行
enter the unpacked folder and do
./configure
make
make install
然后
sudo ln -s /usr/local/bin/gs /usr/bin/gs
在上述操作之上,我做到了:
on top of the above I did:
sudo add-apt-repository ppa:glasen/freetype2
然后:
sudo apt update && sudo apt install freetype2-demos
这篇关于使用imagemagick将pdf转换为图像时指定默认替换字体,并且缺少字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!