Feature #22481

Show thumbnails for PDF attachments

Added by Gregor Schmidt about 1 year ago. Updated 22 days ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Attachments
Target version:3.4.0
Resolution:

Description

If GhostScript is installed, ImageMagick is able to handle PDF files as well. This could be used to create thumbnails for PDF attachments.

The attached patch adds this feature. It is based on current trunk (r15332)

It does a couple of things:

It adds a Redmine::Thumbnail::gs_available?

This method tries to determine if GhostScript is installed. It does so by checking if GhostScript binaries are found in the PATH. This might be insufficient, since ImageMagick might be configured to use the GhostScript libraries without the binaries being installed. But this is rather unlikely.

This property is also made available in /admin/info and descriptions for English and German are added.

Attachment#thumbnailable? is extended

So that, if GhostScript is available, PDFs are also considered thumbnailable

Redmine::Thumbnail::generate is extended

to create PDF thumbnails. Thumbnails will only show the first page ([0] at the end of source parameter) and they will be stored in PNG format (png: at the beginning of target parameter).

AttachmentController#detect_content_type is extended

to return image/png if an attachment thumbnail of a PDF is rendered. In all other cases the thumbnails format used to match the attachment's. But this was not feasible for PDF files.

0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch Magnifier (7.64 KB) Gregor Schmidt, 2016-04-13 14:02

pdf-thumb.png (27.1 KB) Gregor Schmidt, 2016-04-13 14:03

0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch Magnifier - Updated to r15429 (7.89 KB) Gregor Schmidt, 2016-05-30 10:56

Render-PDF-thumbnail-using-ImageMagick-GhostScript-20170504.patch Magnifier - patch for r16542 (6.91 KB) Go MAEDA, 2017-05-04 11:15


Related issues

Related to Redmine - Feature #22915: Additional filetypes (pdf,tif,tiff) for thumbnails genera... New
Duplicated by Redmine - Feature #16626: Preview first page pdf file as a jpg file Closed

History

#1 Updated by Gregor Schmidt about 1 year ago

I have attached an updated patch. The first one (now obsolete) was missing a change in Attachment, I had introduced locally for the changes in #22482.

I have also added a screen shot previewing the feature.

#2 Updated by Jan from Planio www.plan.io about 1 year ago

  • File deleted (0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch)

#3 Updated by Jan from Planio www.plan.io about 1 year ago

  • Target version set to Candidate for next minor release

#5 Updated by Toshi MARUYAMA about 1 year ago

LGTM.

#6 Updated by kay rus 12 months ago

Gregor, I guess you have to update your patch because of this new feature: https://github.com/redmine/redmine/commit/bf81c96b79cc80bc4ffb08714a3d3f92e68e254a

You can find some hits here: http://www.redmine.org/attachments/16039/pdf_thumbnails.patch

And in addition, I guess you can add tiff support ([0] is also necessary here, so I'd suggest you to add "[0]" for all images, not only for pdf, it works in my patch as well), and add some tests.

#7 Updated by Gregor Schmidt 12 months ago

Attached you may find an updated patch (trunk r15429)

#8 Updated by Gregor Schmidt 12 months ago

@kay rus: Thanks for additionally suggesting TIFF support in #22915. I did not include your changes into my patch to keep this issue focused. I assume, adding tiff after this change was applied will be just as easy.

#9 Updated by Go MAEDA 12 months ago

  • Related to Feature #22915: Additional filetypes (pdf,tif,tiff) for thumbnails generation added

#10 Updated by Go MAEDA 28 days ago

  • Duplicated by Feature #16626: Preview first page pdf file as a jpg file added

#11 Updated by Go MAEDA 22 days ago

It is a great feature. We can easy guess the content of attached PDF files by seeing its thumbnail.
I updated the patch for the current trunk. Let's deliver this feature in the upcoming version.

Also available in: Atom PDF