From 290e452aec615ef935516524cf445b40c5254fe4 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Fri, 21 Jun 2019 16:15:08 +0200 Subject: [PATCH 1/3] Add ghostscript to Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index a653a486e..6fe764827 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \ postgresql-client \ default-jre-headless \ unison \ + ghostscript \ sudo graphviz --no-install-recommends \ libfile-mimeinfo-perl && \ apt-get install -y --no-install-recommends -t $(cat /tmp/lsb_release)-backports libreoffice && \ From 33cc3c29d18d9e6a960b283304af5ae1912e8d61 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Fri, 21 Jun 2019 19:42:58 +0200 Subject: [PATCH 2/3] Move PDF thumbnail generation to ImageMagick Closes SCI-3579 --- .../custom_file_preview.rb | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/paperclip_processors/custom_file_preview.rb b/lib/paperclip_processors/custom_file_preview.rb index c749d9e6d..f6ea765e6 100644 --- a/lib/paperclip_processors/custom_file_preview.rb +++ b/lib/paperclip_processors/custom_file_preview.rb @@ -10,16 +10,26 @@ module Paperclip dst = TempfileFactory.new.generate("#{basename}.#{options[:format]}") begin - Paperclip.run( - libreoffice_path, - "--headless --invisible --convert-to png --outdir #{directory} #{@file.path}" - ) + if @file.content_type == 'application/pdf' + # We use special convert options for PDFs to improve quality and + # background, we append [0] to convert only the first page + convert( + ":source -resize '#{options[:geometry]}' -format #{options[:format]} -flatten -quality 70 :dest", + source: File.expand_path(@file.path) + '[0]', + dest: File.expand_path(dst.path) + ) + else + Paperclip.run( + libreoffice_path, + "--headless --invisible --convert-to png --outdir #{directory} #{@file.path}" + ) - convert( - ":source -resize '#{options[:geometry]}' -format #{options[:format]} #{options[:convert_options]} :dest", - source: File.expand_path(original_preview_file), - dest: File.expand_path(dst.path) - ) + convert( + ":source -resize '#{options[:geometry]}' -format #{options[:format]} #{options[:convert_options]} :dest", + source: File.expand_path(original_preview_file), + dest: File.expand_path(dst.path) + ) + end ensure File.delete(original_preview_file) if File.file?(original_preview_file) end From 1a38324209533338f50370642c1cf1f30ebab03e Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Tue, 2 Jul 2019 10:10:48 +0200 Subject: [PATCH 3/3] Add ghostscript to Dockerfile.production --- Dockerfile.production | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile.production b/Dockerfile.production index ca922f441..0e6b5baa9 100644 --- a/Dockerfile.production +++ b/Dockerfile.production @@ -17,6 +17,7 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \ postgresql-client \ netcat \ default-jre-headless \ + ghostscript \ sudo graphviz --no-install-recommends \ libfile-mimeinfo-perl && \ apt-get install -y --no-install-recommends -t stretch-backports libreoffice && \