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

Jan*_*ein 3 linux pdf jpeg go

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

已经用 bimg(根本不起作用)和 imagemagick (gopkg.in/gographics/imagick.v3/imagick) 尝试过这个,如另一个线程的答案中提供的:“ /sf/answers/3326441751/

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)
Run Code Online (Sandbox Code Playgroud)

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

ERROR_POLICY: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408
Run Code Online (Sandbox Code Playgroud)

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

任何帮助表示赞赏!

Vig*_*ggi 5

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

不是一个纯粹的Golang解决方案,但这个完美的作品,它使用CGO内部。底层库是Pdfium,它是一个 C++ 库,由 Google 开发并在 Chrome 中使用。

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

为了提高操作的整体性能,我最终使用了这个编码器,因为 Golang 的图像编码器不适合性能并且速度