1

I'm trying to figure out why one of my WordPress sites is not generating thumbnails for PDF uploads. It works on my dev and staging sites. When comparing them, the only difference that I can find is that my production site is running PHP 7.2, whereas dev and staging are running PHP 7.3. I have the imagick extension installed on all of them.

Thumbnails are being generated for image files - it's only PDF files that aren't working. The iMagick PHP extension should be all that's needed, right? I've turned on WordPress debug logging and looked for errors there and in the Apache error logs, but have found nothing.

Any suggestions?

2 Answers 2

3

I found a solution! I hope this helps save some time and frustration for others that might encounter this problem. It turns out that it isn't WordPress or PHP.

After a lot of digging, I came across this discussion by some members of the WordPress Core team: https://core.trac.wordpress.org/ticket/48853. It says that there is some kind of issue in Ghostscript 8.70 and below that prevents the thumbnails from being generated for PDFs. So, I checked the installed version of Ghostscript. Sure enough, it's 8.70. I looked for a yum update, but 8.70 is the latest available for the server OS (CentOS 6).

I saw several posts that described installing a newer version from a tar.gz file, so I tried that using the defaults. WordPress still would not generate PDF thumbnails. Rats. Even though the command line reported the newer version of Ghostscript, it was like WordPress didn't see it. Then I saw a post somewhere that seemed to indicate that WordPress was looking in /usr/bin for the Ghostscript executable. The default ./configure command (with no arguments) installed GS in /usr/local/bin. After installing GS into /usr/bin instead, WordPress was finally able to generate PDF thumbnails!

Here are the steps for CentOS 6:

  1. wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs919/ghostscript-9.19.tar.gz (I saw somewhere that if you go higher than that version with CentOS 6, you'll have to mess with updating compilers and linkers and whatnot.)
  2. tar -zxvf ghostscript-9.19.tar.gz
  3. cd ghostscript-9.19
  4. ./configure --prefix=/usr (To install where WordPress expects to find GS)
  5. make
  6. sudo make install

That's it! I also bounced Apache for good measure, but I'm not sure that's necessary. Hope this helps!

1
  • Thanks for the share. I was hopeful this would solve same issue on my site. Had no prob generating PDF thumbs on the dev server (different server). But on live server, no go. Alas, it already has GhostScript 9.26.
    – omega33
    Commented Aug 29, 2022 at 2:18
0

Another possible cause if images are producing thumbnails but PDFs are not is the security policy in ImageMagick. (This may have been relevant to @omega33's comment.) If so, PDF thumbnail creation fails silently even with WP_DEBUG on, but wp media regenerate may show the error. See https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion After editing /etc/ImageMagick-6/policy.xml you may need to restart PHP-FPM or the web server.

If it's only affecting some images and not all PDFs, it may instead be some kind of timeout or conceivably a quota problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.