Struggling with Files and PDF Thumbnails in Drupal 7

I'm working on building a document library in Drupal 7. The project has presented a lot more challenges than I initially anticipated, and one of them is the presentation of files. Each entry can either be an internal only entry, or be visible to the world. Each entry can also contain multiple files, and each of those can either be internal only or visible to the world. I am migrating from another system with a lot of content in place. In the current system, each entry has an optional cover image, files are just listed by filename. That's where the trouble begins.

I thought it would be very nice to be able to use the cover image if had been uploaded; and if there wasn't one in place, but there had been a pdf file uploaded, to use an image generated from the first page of the PDF file.

I tried two different modules. I can still remember enough to talk about two of them: PDF Preview and PDFThumb. PDF to ImageField also looks like it could work, but either I tried it and it didn't work or I haven't tried it yet.

PDFThumb

At first it seemed like I would need to create a separate content type just to hold the files so that I could specify at the file-level whether it was for internal or external use and potentially provide a title and a thumbnail. In this scenario, PDFThumb is a good option because what it needs, in the form I wanted to work with it, is a file field with the file widget, and an image field to connect it to. Visiting /admin/config/media/pdfthumb will allow you to find the content type that contains your file field and specify the image field that the generated thumbnail should go into. This didn't work for me at all at first, and failed with very unhelpful error messages. I eventually figured it out (ghostscript was not in apache's path), and left a comment on an issue for the module. After that it worked like a charm, but then I discovered the file entity module when looking at the media module and there began a whole new set of issues.

File Entity allows, among other things, for files to have fields associated with them, so I think that this will enable me to specify whether the file is for internal or external use right on the file entry, along with providing title and/or descriptive text. The piece I still need to figure out, is how to toggle the display of those files based on user role, but I can think of a number of possibilities, so that can be considered a little bit later.

PDF Preview

Unfortunately, with the file entity module, PDF Thumb doesn't seem to be able to find the file field within the file type I've set up. I think I could associate the file field inside my content type with the cover image, but that field is a single entry that is potentially already populated with more desirable content, and the file field can have multiple files, and each one would ideally have a thumbnail associated with it, I'd be back to either using a separate content type or possible a field collection. Fortunately there is a module that should allow a media field that contains a pdf to display it as a thumbnail, which it just what I want, or would be if it worked. Instead when I set that file type to use PDF Preview, I get:

User error: ImageMagick error 1: convert: no images defined `/path/to/drupal/install/sites/default/files/pdfpreview/e75afd6ce6484b9e72f0993adbedb3c3.jpg' @ error/convert.c/ConvertImageCommand/3241. in trigger_error() (line 519 of /path/to/drupal/install/sites/all/modules/imagemagick/imagemagick.module). => 

type errors. Searching for this turned up some people saying it was due to spaces in the PDF filename, but I confirmed that it happens even with the spaces. Configuring ImageMagick to display debugging information gives me the command being run

User notice: ImageMagick command: <pre>/usr/local/bin/convert &#039;/path/to/drupal/install/sites/default/files/test/filename.pdf[0]&#039; -quality &#039;75&#039; -resize &#039;220x220&#039; &#039;/path/to/drupal/install/sites/default/files/pdfpreview/e75afd6ce6484b9e72f0993adbedb3c3.jpg&#039;</pre> in trigger_error() (line 7669 of /path/to/drupal/install/includes/common.inc). =>

I tried running the command in the terminal with straight quotes in place of the html entities and it ran, so it seems like the issue may be that somehow the straight quotes are being turned into html entities before they are passed to the system to run, but even if I can figure out how to fix that issue, the pdf thumbnail that was returned has big black areas in it that shouldn't be black because the source pdf apparently had transparency in it, which gets turned into black when imagemagick converts to jpeg without some flags set for turning off alpha channels and the like. There is an issue open on PDF Preview for dealing with this issue, but it is 3 and a half years old (this seems to be par for the course with drupal issues, which I find alarming), and while it is fortunately still somewhat active, it seems to have still not finally been resolved.

So my choice is to install the dev version of the module, and possibly apply some of the patches to see what is and isn't working for me and report back to hopefully keep things moving on the issue, or to do without PDF thumbnails for now. Since I have a lot to accomplish and a dwindling amount of time left to accomplish it in, I'll be opting for the latter, and trying to come back to PDF thumbnails later on.

Editorial Note

Things have been sparse on this site, but as I get deeper into this site build, I find I'm having to relearn things I already learned and forgot, and sometimes I can't remember why I made the decisions I did sometimes. I think I'll try to start writing something about what I've considered here whenever I can so I can use it as a reference down the road.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.