Fix WordPress not generating PDF previews even if Imagick and GhostScript are installed
Sometimes even if you have ImageMagick, Imagick and GhostScript installed, WordPress does still not generate PDF previews. It seems like there is some kind of security feature in ImageMagick that doesn’t allow it to process PDF files out of the box.
It’s probably there for a good reason so you should probably keep it on if you have unauthenticated users uploading PDFs using the WordPress admin panel.
However, if you want to disable this security feature, open /etc/ImageMagick-6/policy.xml
and scroll to the section that says
<!-- disable ghostscript format types -->
<policy domain="coder" rights="none" pattern="PS" />
<policy domain="coder" rights="none" pattern="PS2" />
<policy domain="coder" rights="none" pattern="PS3" />
<policy domain="coder" rights="none" pattern="EPS" />
<policy domain="coder" rights="none" pattern="PDF" />
<policy domain="coder" rights="none" pattern="XPS" />
And delete those lines. Here’s a quick line you can put into a dockerfile
# Fix PDF preview
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
Now the PDF previews should work as intended.