プロジェクト

全般

プロフィール

Vote #77352

完了

Show thumbnails for PDF attachments

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Attachments_19
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
19
version_id:
127
issue_org_id:
22481
author_id:
14446
assigned_to_id:
332
comments:
30
status_id:
5
tracker_id:
2
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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:

h3. 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.

h3. @Attachment#thumbnailable?@ is extended

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

h3. @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).

h3. @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.


journals

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.

!pdf-thumb.png!
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
LGTM.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Attached you may find an updated patch (trunk r15429)
--------------------------------------------------------------------------------
@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.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
I've just tried it on win64. @gswin64 -version@ opens up a GS window and webrick waits until it's closed.
--------------------------------------------------------------------------------
And after that, PDF support is still marked as unavailable in admin/infos.
--------------------------------------------------------------------------------
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":http://studio.imagemagick.org/discourse-server/viewtopic.php?t=10723 . 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?
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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.

<pre><code class="ruby">
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
</code></pre>

--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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.

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

This should be OK.

<pre><code class="ruby">
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
</code></pre>
--------------------------------------------------------------------------------
Updated the patch for r18003. Now the feature is disabled if Redmine is running on Windows.
--------------------------------------------------------------------------------
Updated the patch for the current trunk r18155.
--------------------------------------------------------------------------------
I wrote tests for the patch. I think the patch is ready to commit.
--------------------------------------------------------------------------------
Committed the patch. Thank you for the great improvement.
--------------------------------------------------------------------------------
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

--------------------------------------------------------------------------------
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.

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
For windows, use "gswin64c(32c).exe"(command line version) instead of "gswin64(32).exe".
Now it's working on windows.
<pre><code class="diff">
--- 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
</code></pre>

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Created a separate issue: #33283.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,New,22915,Additional filetypes (tif,tiff) for thumbnails generation
relates,Closed,25988,Preview files by default instead of downloading them
relates,Closed,32307,AttachmentsControllerTest#test_thumbnail_for_pdf_should_be_png fails if ImageMagick convert is not available
relates,Closed,32898,PDF thumbnails support on Windows
relates,Closed,33283,Thumbnail support for PDF attachments may not be detected
duplicates,Closed,16626,Preview first page pdf file as a jpg file

Admin Redmine さんが3年以上前に更新

  • カテゴリAttachments_19 にセット
  • 対象バージョン4.1.0_127 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0