1

I'm using the most recent Craft CMS 2.6.2791. I'd like to generate preview thumbnails for pdf assets in my templates, so I found this plugin:

https://github.com/carnesmedia/pthumb

However, following the instructions on the readme page gives a nonsense url. In my template, I have:

<img src="{{ craft.PThumb.thumbnail(pdf) }}">

If I inspect the src generated by this I see

http://localhost:8888/myproject/public//assets/pdfs/previews/b15c8529f2b4a9b354c5e592e84d1ac5.png

However, this renders as a broken image. I check my project structure and the previews directory is nowhere to be found. Am I doing something wrong or perhaps missing a step?

I'm also open to any other solutions that could generate a thumbnail from the first page of a pdf asset automatically. Thanks!

  • You have two forward slashes after the public folder in your URL: public//assets/pdfs. If you visit the image URL and remove the extra slash, does the image load? – Jamie Wade Jun 24 '16 at 8:05
  • Never used the plugin, but anything unusual showing up in craft/storage/runtime/logs? – Brad Bell Jun 24 '16 at 16:40
  • the double slash doesn't seem to matter. Actually it's because I put my {{siteURL}} in front of the thumbnail expression so my img tag actually looks like <img src="{{siteUrl}}{{ craft.PThumb.thumbnail(pdf) }}">. When {{siteUrl}} gets interpreted, craft seems to always add a slash at the end. This doesn't really prevent the url from being loaded though, at least if you enter it in the browser url bar. And I don't see anything happen to the most recent log in craft/storage/runtime/logs when I make changes to this template. – ChaiTea Jun 24 '16 at 18:14
1

For anyone looking to do this on Craft 3, I used pThumb previously, but I created a plugin specifically to do this for Craft 3 - https://github.com/bymayo/craft-pdf-transform

It takes Asset PDF files and coverts them to JPEG / PNG files automatically when they are uploaded.

Or, do theres a Twig method that lets you convert the PDF to an image if the image already exists in Assets. But this can be a bit labour intensive on the server to do when a template is rendering so is only advised for small files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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