Project

General

Profile

Actions

Feature #22481

closed

Show thumbnails for PDF attachments

Added by Gregor Schmidt about 8 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

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.


Files


Related issues

Related to Redmine - Feature #22915: Additional filetypes (tif,tiff) for thumbnails generationNew

Actions
Related to Redmine - Feature #25988: Preview files by default instead of downloading themClosedJean-Philippe Lang

Actions
Related to Redmine - Defect #32307: AttachmentsControllerTest#test_thumbnail_for_pdf_should_be_png fails if ImageMagick convert is not availableClosed

Actions
Related to Redmine - Feature #32898: PDF thumbnails support on WindowsClosedGo MAEDA

Actions
Related to Redmine - Defect #33283: Thumbnail support for PDF attachments may not be detectedClosedGo MAEDA

Actions
Has duplicate Redmine - Feature #16626: Preview first page pdf file as a jpg fileClosed

Actions
Actions #1

Updated by Gregor Schmidt about 8 years 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.

Actions #2

Updated by Jan from Planio www.plan.io about 8 years ago

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

Updated by Jan from Planio www.plan.io about 8 years ago

  • Target version set to Candidate for next minor release
Actions #5

Updated by Toshi MARUYAMA almost 8 years ago

LGTM.

Actions #6

Updated by kay rus almost 8 years 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.

Actions #8

Updated by Gregor Schmidt almost 8 years ago

상경 김 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.

Actions #9

Updated by Go MAEDA almost 8 years ago

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

Updated by Go MAEDA almost 7 years ago

  • Has duplicate Feature #16626: Preview first page pdf file as a jpg file added
Actions #11

Updated by Go MAEDA almost 7 years 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.

Actions #12

Updated by Go MAEDA almost 7 years ago

  • Related to Feature #25988: Preview files by default instead of downloading them added
Actions #13

Updated by Jean-Philippe Lang almost 7 years ago

  • Target version changed from 3.4.0 to 4.1.0

I've just tried it on win64. gswin64 -version opens up a GS window and webrick waits until it's closed.

Actions #14

Updated by Jean-Philippe Lang almost 7 years ago

And after that, PDF support is still marked as unavailable in admin/infos.

Actions #15

Updated by Jens Krämer over 6 years ago

I played around with this a bit and it seems that Ghostscript on Windows always opens this window, so it's pretty useless to use as a check.

As Gregor mentioned checking for presence of the GS executable in itself is a bit unreliable as well, since ImageMagick still might be built without PDF support. Unfortunately convert -list format, which lists ImageMagick's supported file types, still lists PDF even with Ghostscript not present, it merely checks what options it was compiled with but does not actually look up the actual runtime dependencies (ghostscript libraries). That's consistent with the information I found on imagemagick.org . The only reliable way to determine if a certain file type can be handled is to actually try it out.

We could either:

- try to actually thumbnail a PDF once in gs_available?
- or resort to just checking the presence / executability of the Ghostscript binary
- or introduce an option to manually enable PDF thumbnailing with proper documentation ("install ghostscript!") and completely remove the Ghostscript availability check. The more I think about it this might be the best thing to do.

Thoughts?

Actions #16

Updated by Go MAEDA over 6 years ago

Jens Krämer wrote:

- or introduce an option to manually enable PDF thumbnailing with proper documentation ("install ghostscript!") and completely remove the Ghostscript availability check. The more I think about it this might be the best thing to do.

+1 for this. This is the most efficient and reliable way in the options, I think.

Actions #17

Updated by Go MAEDA almost 6 years ago

Jens Krämer wrote:

We could either:

- try to actually thumbnail a PDF once in gs_available?
- or resort to just checking the presence / executability of the Ghostscript binary
- or introduce an option to manually enable PDF thumbnailing with proper documentation ("install ghostscript!") and completely remove the Ghostscript availability check. The more I think about it this might be the best thing to do.

Another idea. I think there are not many people run Redmine for production on Windows, so we can simply reject Windows.

    def self.gs_available?
      return @gs_available if defined?(@gs_available)

      if ENV['OS'] == 'Windows_NT'
        @gs_available = false
      else
        @gs_available = system("gs -version") rescue false
        @gs_available ||= system("gswin32 -version") rescue false
        @gs_available ||= system("gswin64 -version") rescue false
      end

      @gs_available
Actions #18

Updated by Stephan Wenzel almost 6 years ago

My experience with imagemagick ist, that it is not very reliable with respect to predictability of its capabilities on different platforms. Why not let the user try on a setup page, if imagemagick is capable to handle pdf?

On GitHub and Redmine.org have shared two plugins [[https://www.redmine.org/plugins/redmine_preview_pdf]] and [[https://www.redmine.org/plugins/redmine_thumbnail_pdf]] that use the pdf capabilities of imagemagick. I will introduce a try-if-pdf-is-availbale option on it's setup page.

Actions #19

Updated by Marius BĂLTEANU almost 6 years ago

Go MAEDA wrote:

Another idea. I think there are not many people run Redmine for production on Windows, so we can simply reject Windows.

I’m in favour of rejecting Windows.

Actions #20

Updated by Go MAEDA over 5 years ago

I found that Redmine has Redmine::Platform.mswin? method. We don't have to check ENV['OS'].

This should be OK.

    def self.gs_available?
      return @gs_available if defined?(@gs_available)

      unless Redmine::Platform.mswin?
        @gs_available = system("gs -version") rescue false
      else
        @gs_available = false
      end

      @gs_available
    end
Actions #21

Updated by Go MAEDA about 5 years ago

Updated the patch for r18003. Now the feature is disabled if Redmine is running on Windows.

Actions #23

Updated by Go MAEDA almost 5 years ago

I wrote tests for the patch. I think the patch is ready to commit.

Actions #24

Updated by Go MAEDA almost 5 years ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you for the great improvement.

Actions #25

Updated by Marius BĂLTEANU almost 5 years ago

We should run test_thumbnail_for_pdf_should_be_png only when GS is available.

One test fails without the patch: https://gitlab.com/redmine-org/redmine/-/jobs/223654807
All tests pass after applying the patch: https://gitlab.com/redmine-org/redmine/-/jobs/223683936

Actions #26

Updated by Go MAEDA almost 5 years ago

  • Status changed from Reopened to Closed

Marius BALTEANU wrote:

We should run test_thumbnail_for_pdf_should_be_png only when GS is available.

Thank you for cleaning up after my mistake. Committed the fix in r18221.

Actions #27

Updated by Marius BĂLTEANU over 4 years ago

  • Related to Defect #32307: AttachmentsControllerTest#test_thumbnail_for_pdf_should_be_png fails if ImageMagick convert is not available added
Actions #28

Updated by Anonymous over 4 years ago

For windows, use "gswin64c(32c).exe"(command line version) instead of "gswin64(32).exe".
Now it's working on windows.

--- org/lib/redmine/thumbnail.rb
+++ patch/lib/redmine/thumbnail.rb
@@ -77,5 +77,6 @@

       if Redmine::Platform.mswin?
-        @gs_available = false
+        @gs_available = system("gswin64c -version > nul 2>&1") rescue false
+        @gs_available ||= system("gswin32c -version > nul 2>&1") rescue false
       else
         begin

Actions #29

Updated by Go MAEDA about 4 years ago

Actions #30

Updated by VVD VVD about 4 years ago

Created a separate issue: #33283.

Actions #31

Updated by Go MAEDA about 4 years ago

  • Related to Defect #33283: Thumbnail support for PDF attachments may not be detected added
Actions

Also available in: Atom PDF