Class: Pludoni::Pdfutils::ConvertImageToPdf
- Inherits:
-
Object
- Object
- Pludoni::Pdfutils::ConvertImageToPdf
- Defined in:
- lib/pludoni/pdfutils/convert_image_to_pdf.rb
Instance Method Summary collapse
-
#initialize(blob) ⇒ ConvertImageToPdf
constructor
A new instance of ConvertImageToPdf.
- #run(&block) ⇒ Object
Constructor Details
#initialize(blob) ⇒ ConvertImageToPdf
5 6 7 |
# File 'lib/pludoni/pdfutils/convert_image_to_pdf.rb', line 5 def initialize(blob) @blob = FileWrapper.make(blob) end |
Instance Method Details
#run(&block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pludoni/pdfutils/convert_image_to_pdf.rb', line 9 def run(&block) fname = File.basename(@blob.filename.to_s, '.*') @blob.open do |source| # convert image to pdf tf = Tempfile.new([fname, '.pdf']) tf.binmode cli = "gs -dNOSAFER -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite -o #{tf.path} viewjpeg.ps -c \\(#{source.path}\\) viewJPEG" stdout, stderr, status = Open3.capture3(cli) unless status.success? raise ConversionFailedError, "PDF convertion failed: Command: #{cli}\nStdout: #{stdout}\nStderr: #{stderr}" end FileWrapper.make(tf, filename: "#{fname}.pdf") end end |