Enhanced PDF Support in WordPress 4.7

WordPress 4.7 makes it easier to preview PDFs in the media library by generating image representations of the first page, which are now used throughout the media library and media attachment screens.

If a WP_Image_Editor is available that supports PDF, the following sizes are generated:

  • Full size representation, rendered at 128dpi.
  • Thumbnail (without cropping)
  • Medium
  • Large

The sizes generated can be modified, or the feature disabled entirely via the new fallback_intermediate_image_sizes filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output., and are all stored in the sizes array in attachment metaMeta Meta is a term that refers to the inside workings of a group. For us, this is the team that works on internal WordPress sites like WordCamp Central and Make WordPress..

The preview images generated are used within the Media screen, Gallery, Attachment Details, and on the Attachment page for PDFs.

CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. support is provided through WP_Image_Editor_Imagick and requires Imagick, ImageMagick, and Ghostscript support. When not supported, or if the generation fails, WordPress falls back to previous behavior and saves the attachment without adding image previews to meta.

For more context, see #31050 for the primary ticketticket Created for both bug reports and feature development on the bug tracker. and #38594 for the filter.

Updated:

Since this change requires having Imagick load only the first page of a PDF for performance reasons, this means that if you rely on core loading the entire PDF for your extension of WP_Image_Editor_Imagick, this will no longer function as expected (See: #38832).

As a result, in [39303], the PDF setup code was moved to WP_Image_Editor_Imagick->pdf_setup(), which can be overridden to restore the previous behavior if needed.

#4-7, #dev-notes, #media