dte49889 2019-05-06 19:56
浏览 666

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

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!

  • 写回答

1条回答

  • doumao1887 2019-05-07 03:31
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?