3

I'm attempting to use Imagemagic(RMAgick) to convert PDF-document into image. Original PDF is created from an image too(not native vector PDF).

image = Magick::Image::from_blob(original_pdf) { self.format = 'PDF' }
image[0].format = 'JPG'
image[0].to_blob
image[0].write(to_file.jpg) {
  self.quality = 100
  self.density = 144
}

But resulting image has too low quality, when printing. Original PDF has good quality in same time. I'm trying to use these options

self.quality = 100
self.density = 144

or using PNG rather JPG, but all this doesn't work, only increase image size in kb ).

wildDAlex
  • 357
  • 6
  • 15
  • possible duplicate of [Convert PDF to image with high resolution](http://stackoverflow.com/questions/6605006/convert-pdf-to-image-with-high-resolution) – plinth Apr 23 '13 at 13:53

1 Answers1

9

Assuming original_pdf is content of pdf file, e.g.:

original_pdf = File.open('from_file.pdf', 'rb').read

Then apply quality options in block of method from_blob instead of block of method write:

image = Magick::Image::from_blob(original_pdf) do
  self.format = 'PDF'
  self.quality = 100
  self.density = 144
end
image[0].format = 'JPG'
image[0].to_blob
image[0].write('to_file.jpg')

Look also quality options for Magick::ImageList.new method.

Community
  • 1
  • 1
Oleksandr Avoiants
  • 1,889
  • 17
  • 24