mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
Merge pull request #1920 from jbargu/jg_poppler_pdf
Switch to pdftoppm PDF preview maker
This commit is contained in:
commit
5ca333fe1c
3 changed files with 14 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM ruby:2.5.5
|
||||
FROM ruby:2.5.5-stretch
|
||||
MAINTAINER BioSistemika <info@biosistemika.com>
|
||||
|
||||
# Get version of Debian (lsb_release substitute) and save it to /tmp/lsb_release for further commands
|
||||
|
@ -20,7 +20,7 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
|
|||
postgresql-client \
|
||||
default-jre-headless \
|
||||
unison \
|
||||
ghostscript \
|
||||
poppler-utils \
|
||||
sudo graphviz --no-install-recommends \
|
||||
libfile-mimeinfo-perl && \
|
||||
apt-get install -y --no-install-recommends -t $(cat /tmp/lsb_release)-backports libreoffice && \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM ruby:2.5.5
|
||||
FROM ruby:2.5.5-stretch
|
||||
MAINTAINER BioSistemika <info@biosistemika.com>
|
||||
|
||||
RUN echo deb "http://http.debian.net/debian stretch-backports main" >> /etc/apt/sources.list
|
||||
|
@ -17,7 +17,7 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
|
|||
postgresql-client \
|
||||
netcat \
|
||||
default-jre-headless \
|
||||
ghostscript \
|
||||
poppler-utils \
|
||||
sudo graphviz --no-install-recommends \
|
||||
libfile-mimeinfo-perl && \
|
||||
apt-get install -y --no-install-recommends -t stretch-backports libreoffice && \
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
module Paperclip
|
||||
class CustomFilePreview < Processor
|
||||
def make
|
||||
pdftoppm_path = ENV['PDFTOPPM_PATH'] || 'pdftoppm'
|
||||
libreoffice_path = ENV['LIBREOFFICE_PATH'] || 'soffice'
|
||||
directory = File.dirname(@file.path)
|
||||
basename = File.basename(@file.path, '.*')
|
||||
|
@ -11,25 +12,22 @@ module Paperclip
|
|||
|
||||
begin
|
||||
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)
|
||||
Paperclip.run(
|
||||
pdftoppm_path,
|
||||
"-singlefile -r 72 -png #{@file.path} #{File.join(directory, basename)}"
|
||||
)
|
||||
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)
|
||||
)
|
||||
end
|
||||
|
||||
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)
|
||||
)
|
||||
ensure
|
||||
File.delete(original_preview_file) if File.file?(original_preview_file)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue