SOFTELメモ

</> 技術者募集

wkhtmltoimageでエラー Cannot create a QPixmap when no GUI is being used

問題

wkhtmltoimage で以下のようなエラーが発生します。

# wkhtmltoimage test.html test.png
Loading page (1/2)
QPixmap: Cannot create a QPixmap when no GUI is being used   ] 45%
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
Rendering (2/2)
Done
# wkhtmltoimage https://www.softel.jp/ test.png
Loading page (1/2)
Rendering (2/2)
QPixmap: Cannot create a QPixmap when no GUI is being used   ] 25%
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
(略)
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::translate: Painter not active
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::setOpacity: Painter not active
QPainter::setFont: Painter not active
セグメンテーション違反です (コアダンプ)

答え

使っている wkhtmltoimage のバージョンが 0.11 ではないでしょうか。

解決方法がなさそうなので、もう一つ古い 0.10系か、最新版(0.12)を使って対応しました。

0.10 だと、実行ファイルをダウンロードしてきて、 /usr/local/bin/ などに置くだけで使えます。

0.12 だと、RPMが用意されています。

https://wkhtmltopdf.org/downloads.html

関連するメモ

コメント