Feature #22481
closedShow thumbnails for PDF attachments
0%
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
Updated by Gregor Schmidt over 8 years ago
- File 0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch 0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch added
- File pdf-thumb.png pdf-thumb.png added
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.
Updated by Jan from Planio www.plan.io over 8 years ago
- File deleted (
0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch)
Updated by Jan from Planio www.plan.io over 8 years ago
- Target version set to Candidate for next minor release
Updated by kay rus over 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.
Updated by Gregor Schmidt over 8 years ago
- File 0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch 0001-Render-PDF-thumbnail-using-ImageMagick-GhostScript.patch added
Attached you may find an updated patch (trunk r15429)
Updated by Gregor Schmidt over 8 years ago
Updated by Go MAEDA over 8 years ago
- Related to Feature #22915: Additional filetypes (tif,tiff) for thumbnails generation added
Updated by Go MAEDA over 7 years ago
- Has duplicate Feature #16626: Preview first page pdf file as a jpg file added
Updated by Go MAEDA over 7 years ago
- File Render-PDF-thumbnail-using-ImageMagick-GhostScript-20170504.patch Render-PDF-thumbnail-using-ImageMagick-GhostScript-20170504.patch added
- Target version changed from Candidate for next minor release to 3.4.0
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.
Updated by Go MAEDA over 7 years ago
- Related to Feature #25988: Preview files by default instead of downloading them added
Updated by Jean-Philippe Lang over 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.
Updated by Jean-Philippe Lang over 7 years ago
And after that, PDF support is still marked as unavailable in admin/infos.
Updated by Jens Krämer about 7 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?
Updated by Go MAEDA about 7 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.
Updated by Go MAEDA over 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
Updated by Stephan Wenzel over 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.
Updated by Marius BĂLTEANU over 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.
Updated by Go MAEDA almost 6 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
Updated by Go MAEDA over 5 years ago
- File Render-PDF-thumbnail-using-ImageMagick-GhostScript-20190326.patch Render-PDF-thumbnail-using-ImageMagick-GhostScript-20190326.patch added
Updated the patch for r18003. Now the feature is disabled if Redmine is running on Windows.
Updated by Go MAEDA over 5 years ago
- File Render-PDF-thumbnail-using-ImageMagick-GhostScript-20190511.patch Render-PDF-thumbnail-using-ImageMagick-GhostScript-20190511.patch added
Updated the patch for the current trunk r18155.
Updated by Go MAEDA over 5 years ago
- File 0001-Test-for-22481.patch 0001-Test-for-22481.patch added
- File 190511141819_ecookbook-gantt.pdf 190511141819_ecookbook-gantt.pdf added
I wrote tests for the patch. I think the patch is ready to commit.
Updated by Go MAEDA over 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.
Updated by Marius BĂLTEANU over 5 years ago
- File 0001-Run-test-only-when-GhostScript-is-available.patch 0001-Run-test-only-when-GhostScript-is-available.patch added
- Status changed from Closed to Reopened
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
Updated by Go MAEDA over 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.
Updated by Marius BĂLTEANU about 5 years ago
- Related to Defect #32307: AttachmentsControllerTest#test_thumbnail_for_pdf_should_be_png fails if ImageMagick convert is not available added
Updated by Anonymous almost 5 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
Updated by Go MAEDA almost 5 years ago
- Related to Feature #32898: PDF thumbnails support on Windows added
Updated by Go MAEDA over 4 years ago
- Related to Defect #33283: Thumbnail support for PDF attachments may not be detected added