有什么办法可以用golang将PDF转换为jpeg吗?

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

已经使用bimg(一点都不起作用)和imagemagick(gopkg.in/gographics/imagick)进行了尝试 .v3 / imagick)提供给另一个线程:“ https://stackoverflow.com/a/47520596/7502507</ a>“ </ p>

  imagick.Initialize()

defer imagick.Terminate()

mw:= imagick.NewMagickWand ()

defer mw.Destroy()

mw.ReadImage(pdf)

mw.SetIteratorIndex(0)//这是页面偏移量

mw.SetImageFormat(“ jpg”)
\ nmw.WriteImage(image)
</ code> </ pre>

它根本不会产生jpg,只会给我错误</ p>

 < 代码> ERROR_POLICY:尝试执行安全策略“ PDF”不允许的操作@ error / constitute.c / IsCoderAuthorized / 408 
</ code> </ pre>

如何进行此操作 工作? 我似乎无法为此编辑安全设置。</ p>

我们将提供任何帮助!</ p>
</ div>

展开原文

原文

I am currently rewriting my "old" Python-based Chatbots into golang. One issue I came across was that I can´t convert a PDF into jpeg. Which I´d like to do so I can send it into a chat easily.

Already tried this with bimg (did not work at all) and imagemagick (gopkg.in/gographics/imagick.v3/imagick) as provided in this answer to another thread: "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)

It does not produce a jpg at all, it just gives me the error

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

How can I make this work? I can´t seem to edit the security settings for this.

Any help is appreciated!

dsa5233
dsa5233 显然这是由于Ghostscript中的错误所致,您必须修改policy.xml或更新Ghostscript程序包(已发布修复程序):stackoverflow.com/questions/52998331/…
一年多之前 回复
duanri1985
duanri1985 也许可以通过提高特权来解决某些问题?
一年多之前 回复

1个回答



这不是我要做的事情。 但是,我最近正在研究使用pdf的golang cli工具,它们具有图像提取功能。 您可以深入研究代码并从那里进行研究:</ p>

https://github.com/hhrutter/pdfcpu </ p>
</ div>

展开原文

原文

This is not something I have done. However I was recently looking at this golang cli tool for working with pdf and they have an extract to image feature. You could have a dig into the code and possible work it out from there:

https://github.com/hhrutter/pdfcpu

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐