linux - 有没有办法用golang将PDF转换为jpeg?

标签 linux pdf go jpeg

我目前正在将“旧的”基于 Python 的聊天机器人重写为 golang。 我遇到的一个问题是我无法将 PDF 转换为 jpeg。我想这样做,这样我就可以轻松地将它发送到聊天中。

已经使用 bimg(根本不起作用)和 imagemagick (gopkg.in/gographics/imagick.v3/imagick) 尝试了此操作,如对另一个线程的此答案中提供的:“https://stackoverflow.com/a/47520596/7502507

imagick.Initialize()

defer imagick.Terminate()

mw := imagick.NewMagickWand()

defer mw.Destroy()

mw.ReadImage(pdf)

mw.SetIteratorIndex(0) // This being the page offset

mw.SetImageFormat("jpg")

mw.WriteImage(image)

它根本不生成 jpg,它只是给我错误

ERROR_POLICY: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408

我怎样才能使这项工作?我似乎无法为此编辑安全设置。

感谢任何帮助!

最佳答案

我遇到过同样的问题,但没有找到任何纯 Golang 解决方案。

不是纯 Golang 解决方案,而是 this使用 cgo 完美工作在内部。底层库是 Pdfium这是一个 C++ 库,由 Google 开发并在 Chrome 中使用。

经过大量研究,我发现 Pdfium 在速度、稳健性、许可要求和可靠性方面是同类产品中最好的。

为了提高操作的整体性能,我最终得到了 this编码器,因为 Golang 的图像编码器不适合性能,而是 slow .

关于linux - 有没有办法用golang将PDF转换为jpeg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56011592/

相关文章:

asp.net - SelectPdf .net 的安全异常

linux - 从 Vertica 的复制脚本中删除页脚

使用转换 (STL) 时的 C++ 错误

c - `((t*)0)->f)` 在 C 代码中的作用是什么?

java - FOP - 如何避免大量页面序列导致高内存消耗?

java - 使用 Cipher RSA 写入加密的 PDF 文件

if-statement - "if"具有多个返回值的方法的初始化语句

go - 无法将接口(interface) slice 传递给空白接口(interface)类型函数

go - 如何使用 channel 收集各种goroutine的响应

regex - 使用 AWK 将字符串用正斜杠括起来