[英]Read pdf file with php-imagick on Travis
I need to read a pdf file on Travis with php-imagick extension. 我需要在php-imagick扩展上阅读Travis上的pdf文件。
I learned i need to adjust imagick policy.xml file to allow imagick to read pdf files. 我了解到我需要调整imagick policy.xml文件以允许imagick读取pdf文件。 So i added a custom policy.xml.
所以我添加了一个自定义policy.xml。
env:
global:
- MAGICK_CONFIGURE_PATH=$HOME/.config/ImageMagick/
...
before_script:
# Allow imagemagick to read PDF files
- echo $MAGICK_CONFIGURE_PATH
- mkdir $MAGICK_CONFIGURE_PATH
- echo '<policymap>' > $MAGICK_CONFIGURE_PATH/policy.xml
- echo '<policy domain="coder" rights="read" pattern="PDF" />' >> $MAGICK_CONFIGURE_PATH/policy.xml
- echo '</policymap>' >> $MAGICK_CONFIGURE_PATH/policy.xml
- sudo rm /etc/ImageMagick-6/policy.xml
but still the build fails with [Failed to read the file]
但仍然是
[Failed to read the file]
构建失败
The file is there, locally it works, i suspect that imagick still cant read PDFs. 文件在那里,在本地工作,我怀疑imagick仍然无法阅读PDF。 The new policy also seems to be applied:
新政策似乎也适用:
$convert -list policy
Path: /home/travis/.config/ImageMagick/policy.xml
Policy: Coder
rights: Read
pattern: PDF
Policy: Coder
rights: Read
pattern: PDF
Path: [built-in]
Policy: Undefined
rights: None
How can i fix this? 我怎样才能解决这个问题?
Failed build is: https://travis-ci.org/ivoba/silverstripe-simple-pdf-preview/jobs/563919021 构建失败的原因是: https : //travis-ci.org/ivoba/silverstripe-simple-pdf-preview/jobs/563919021
Did you try it on a Standard Debian Environment. 您是否在标准Debian环境中尝试过它? In my case Imagick was able to process PDFs without further do - Please ensure, that the Source PDF is in a non Adobe-Restricted Version eg PDF1.4.
在我的情况下,Imagick能够无需进一步处理PDF - 请确保源PDF是非Adobe限制版本,例如PDF1.4。 Otherwise it might not work:
否则它可能不起作用:
$im = new \Imagick();
$im->setResolution(300, 300);
$im->readImage($path_of_pdf_file);
$im->writeImages($folder_to_place_each_page . '/' . $name, false)
After a while i just answer my own question: 过了一会儿我才回答我自己的问题:
The problem was that imagemagick needs ghostscript for working with pdfs and ghostscript needs to be installed in Debian. 问题是imagemagick需要ghostscript来处理pdf,而ghostscript需要安装在Debian中。
So additionally to editing the policy.xml file, adding the install command to .travis.yml did the trick. 除了编辑policy.xml文件之外,将安装命令添加到.travis.yml也可以。
sudo apt-get install -y ghostscript
Full working travis file is: https://github.com/ivoba/silverstripe-simple-pdf-preview/blob/master/.travis.yml 完整的travis文件是: https : //github.com/ivoba/silverstripe-simple-pdf-preview/blob/master/.travis.yml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.