PDF Image in content

There’s no easy way in version 4.8, as far as I know.

Few ideas come to mind, regarding writing plugins to make it easier:

  • Use the media_send_to_editor filter to modify the HTML output for the application/pdf mime type, to include the preview image. This makes it is easier for user to insert pdf preview images, but hardcodes the HTML. Also note that if the pdf attachment is later deleted, the preview images are deleted too. This could resulted in broken pdf preview images on the front-end, but that’s nothing new, as we’ve seen the same happen for image attachments, that we later delete.

  • Same as above but return a custom shortcode instead of HTML. This is not as user friendly but makes it easier to adjust the HTML later on and make sure the pdf isn’t deleted, to avoid broken images.

  • Generate a shortcode string for each pdf attachment that the user can just copy/paste into the editor. Also less user friendly, but flexible.

  • Create a real image attachment for the pdf preview images, so it would be stored in the wp_posts table and have it’s own separated upload files. Filters like fallback_intermediate_image_sizes and wp_generate_attachment_metadata would be helpful entry points. This would be more complex to write and would most likely not solve all the issues related to a good user experience.

Note that the info on the pdf preview images is e.g. stored in the _wp_attachment_metadata meta value and we can see here in the core how they are generated with the WordPress Image Editor API.

Hope it helps!