gpt4 book ai didi

ruby-on-rails - 我们可以在 Ruby on Rails 中将 PDF、Excel、Word 转换为图像吗?

转载 作者:行者123 更新时间:2023-12-04 21:07:22 25 4
gpt4 key购买 nike

在我的项目中,需要将 PDF、Excel、Word 文档转换为图像。

我知道有 imagemagick 可以用来转换 PDF,但我不确定 Excel 和 PDF 文件。

我看过JODConverter它将 Excel、Word 等转换为 PDF,然后我必须将 PDF 转换为图像。我认为 Ruby 中没有绑定(bind) JODConverter 的 gem 或插件。

在 Ruby on Rails 平台中还有比这些更好的解决方案吗?

最佳答案

您可以使用 gem rmagick将pdf文件转换为图像。

这是将所有页面保存为变量 pdf_image 中的图像的示例代码。

pdf_image = Magick::ImageList.new('tmp/prakhar.pdf'){ self.density = 150 }

然后你可以循环变量 pdf_image 并保存页面。
# Write the image files in the tmp/images folder
pdf_image.each_with_index do |page, index|
page.write('tmp/images' + '/page_' + index.to_s + '.jpg')
end

关于ruby-on-rails - 我们可以在 Ruby on Rails 中将 PDF、Excel、Word 转换为图像吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6606931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com