2013-04-23 86 views
3

我試圖使用Imagemagic(RMAgick)將PDF文檔轉換爲圖像。原始PDF也是從圖像創建的(不是原生矢量PDF)。將PDF轉換爲JPG時質量不佳

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 
} 

但打印時產生的圖像質量太低。原始PDF在同一時間質量很好。 我試圖使用這些選項

self.quality = 100 
self.density = 144 

或使用PNG而JPG,但是這一切都不起作用,只會加劇KB圖像大小)。

+0

可能重複[轉換PDF到高分辨率圖像](http://stackoverflow.com/questions/6605006/convert-pdf-to-image-with-high-resolution) – plinth 2013-04-23 13:53:59

回答

7

假設original_pdf是PDF文件的內容,例如:

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

然後在方法write的方法from_blob 而不是堵堵的適用質量選項:

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') 

看也quality options for Magick::ImageList.new method

+0

工作對我來說真棒!謝謝! – FUT 2014-01-27 09:49:51

+0

是的!這是實際上似乎使密度有任何影響的唯一方法 – atomkirk 2016-10-08 17:03:18

+0

這對我來說非常適合轉換爲PNG – tnaught 2017-09-21 20:29:29