• Hello,
    I have a problem with previewing pdf files in the media on my website.
    Practically for some time I think after updating to one of the latest versions of WP it is no longer visible.
    The strange thing is that in the code in the tag there is a file in .pdf format (img width=”60″ height=”60″ src=”/wp-content/uploads/2021/03/edit-60×60.pdf” alt=””)
    and if I actually open it there is a small pdf that corresponds to the preview of the document, but in the list of documents in Media it gives the classic error image not found.
    Why is there this pdf? What could it be? Shouldn’t the preview be a jpg? How can I fix it? I checked on another site and there is not a .pdf file to view the preview but a jpg …. what can it be?

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The feature to show PDF previews was added in WP 4.7. But the generation of the preview image is only on upload.
    So if your PDF was uploaded before 4.7, or moved from another site that was before 4.7, then the handling of the preview could be mixed with the way it used to be.

    But perhaps it is something to do with the attachment since you said the latest version affected it.
    There was a bug, fixed in WP 5.6: https://core.trac.www.ads-software.com/ticket/48853
    The block editor handles PDF files differently than the Classic editor. See this open issue https://github.com/WordPress/gutenberg/issues/15097

    You can comment in the issue and ticket if it’s related, or open a new ticket if it’s not. https://core.trac.www.ads-software.com/

    Thread Starter designemotions

    (@designemotions)

    Hello,
    Thanks for the reply.
    Basically I had noticed that from 4.7 from the standard preview of the pdf a different preview was generated for each file.
    The problem that at some point this preview has not been seen anymore and going to look at the code instead of an image puts a link to a pdf is a very strange thing. Then from the code I was able to disable the generation of the preview and go back to the previous image.
    However, there remain those pdfs where you see the classic missing image placeholder and I would like to solve by understanding why it inserts a pdf in the img tag and does not insert an image, I also tried the plugins to regenerate the preview but they don’t. I wonder if it is possible at least to replace the preview for all the existing pdfs with a still image from code, I don’t care what the preview generates I just want to avoid the error (there are many documents I cannot put them back by hand).

    Between the time that you saw the PDF preview correctly and now when you don’t, what did you change? Did you switch editors? Did you convert Classic post to blocks? Did you try a plugin that might have changed the post content (or was that after)?
    What method was used to put the PDF into the post in the first place? Is this a problem only with old ones, or does it happen on new ones?
    What code did you use to disable the generation of the preview?

    I’m trying to determine if there’s a bug in WP, where it is putting an image tag with the PDF file, or if that is the result of something else.

    Thread Starter designemotions

    (@designemotions)

    Hello
    no maybe I haven’t explained myself, I was talking about the backend, the media library, I have the problem only in the backend in the list of documents. Only there I can not see the preview of the pdf.

    https://ibb.co/pPzJq1y

    Also look in the code for the link in the img tag. A link to a pdf is not a link to an image. How is it possible? I checked on a fresh install of WP and the link always points to an image. If I open the link it opens me a small pdf with preview dimensions (I deleted a part of the link so as not to make it public) but I assure you that it opens a pdf in miniature.

    https://ibb.co/R3b4q4w

    To disable the preview I have inserted this code in the fuctions.php of the child theme:

    function wpb_disable_pdf_previews () {
    $ fallbacksizes = array ();
    return $ fallbacksizes;
    }
    add_filter (‘fallback_intermediate_image_sizes’, ‘wpb_disable_pdf_previews’);

    But it is not valid for old pdfs that now all have the missing preview. How can I fix it? It bothers me a lot that the customer sees this error. It’s very strange…

    Thread Starter designemotions

    (@designemotions)

    No idea how I can correct the error?

    Thanks

    Did you add your code to disable the PDF previews before or after the problem?
    It seems that by returning an empty array for sizes, you would get nothing, which is what you are complaining about.
    What happens if you remove that code? (not sure when WP would generate the image if it was disabled on upload)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Preview pdf error in media’ is closed to new replies.