Home › Forums › Feature Requests › Show PDF Thumbnails on file uploads if available
Now that WordPress 4.7 supports creating thumbnails for PDF’s (Assuming the server you’re on has GhostScript installed). Would it be possible to show the preview thumbnail for files that are PDFs, when uploaded in wp-admin?
It’s been great for a new project that I don’t need to create a second field for the PDF Thumbnail.
Currently it’s just a file icon, which is fine, but I think it would look nicer if the client can see what they just uploaded.
Now that it’s possible in WP core, I’m sure it will be added sooner or later, depending on what everything else the developer is working on and his priorities. You should submit this to support if you want the developer to see it sooner rather than later https://support.advancedcustomfields.com/new-ticket/
Hello,
FYI, I had same issue and did this hook to make it:
function acf_change_icon_on_files ( $icon, $mime, $attachment_id ){ // Display thumbnail instead of document.png
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) === false && $mime === 'application/pdf' ){
$get_image = wp_get_attachment_image_src ( $attachment_id, 'thumbnail' );
if ( $get_image ) {
$icon = $get_image[0];
}
}
return $icon;
}
add_filter( 'wp_mime_type_icon', 'acf_change_icon_on_files', 10, 3 );
Hey @jonas, $get_image = wp_get_attachment_image_src ( $attachment_id, 'thumbnail' );
doesn’t seem to be returning anything for me, any ideas? ($icon, $mime, and $attachment_id are all returning correct data)
Hello,
Yes, there’s probably the following reason to that..
=> You may have WordPress 4.7+ with an hosting where Imagemagick or Imagick AND ghostscript are installed. Else you will not have the new wordpress option that automatically create an image preview of your PDF stored as an attachement image. More info here:
https://make.wordpress.org/core/2016/11/15/enhanced-pdf-support-4-7/
If you don’t have this option automatically activated, there’s 2 possibilities to try:
1) you might maybe find a plugin that add the option to set a featured image to your PDF attachment… then you’ll need to manually attach the image to your PDF each time you download one.
2) Else, try the following plugin – as WP 4.7 feature – it also require Imagemagick and Ghostscript, but for an unknown reason it was working for me on a website where the default WP 4.7+ behaviour were not working:
https://fr.wordpress.org/plugins/pdf-image-generator/
I don’t have more time to investigate, but if someone has the reason why this plugin works where WP 4.7 doesn’t, i’m curious of the answer.
Now it seems as if PHP8 doesn’t support Imagemagick or Ghostscript…
So I end up using a paid version ($20) to show my PDF thumbnails that doesn’t use modules called https://wp-pdf.com
It works with ACF upload field and the render template code as well as @jonas code!!
The topic ‘Show PDF Thumbnails on file uploads if available’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.