11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/docpdf/adapters/converters/rmagick.rb', line 11
def convert(data, filename)
img = nil
Tempfile.create(["docpdf", File.extname(filename || ".tmp")]) do |tempfile|
tempfile.binmode
tempfile.write(data)
tempfile.rewind
img = Magick::Image.read(tempfile.path).first
img.to_blob { |attrs| attrs.format = "PDF" }
end
rescue Magick::ImageMagickError => e
raise ConversionError, "RMagick failed to convert #{filename || 'image'} to PDF: #{e.message}"
ensure
img&.destroy!
end
|