将PDF转换为JPG时质量低 [英] Low quality when converting PDF to JPG
问题描述
我正在尝试使用Imagemagic(RMAgick)将PDF文档转换为图像。原始PDF也是从图像创建的(不是原生矢量PDF)。
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
}
但是打印时产生的图像质量太低。原始PDF同时具有良好的质量。
我正在尝试使用这些选项
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
或使用PNG而不是JPG,但所有这些都不起作用,只增加kb中的图像大小) 。
or using PNG rather JPG, but all this doesn't work, only increase image size in kb ).
推荐答案
假设 original_pdf
是pdf文件的内容,例如:
Assuming original_pdf
is content of pdf file, e.g.:
original_pdf = File.open('from_file.pdf', 'rb').read
然后在方法块中应用质量选项 from_blob
而不是方法块写
:
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')
另请参阅 Magick :: ImageList的质量选项。新的
方法。
Look also quality options for Magick::ImageList.new
method.
这篇关于将PDF转换为JPG时质量低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!