我目前正在将“旧的”基于 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 在速度、稳健性、许可要求和可靠性方面是同类产品中最好的。
关于linux - 有没有办法用golang将PDF转换为jpeg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56011592/