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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题