原先使用过wkhtmltox,也是个不错的工具,使用也是相当简单,不过对部分css3样式不支持
现在使用Chrome CLI生成图片,就是安装浏览器,利用浏览器生成图片,只要浏览器能解析,生成图片就是ok的
参看下https://blog.csdn.net/xuechangchun007/article/details/120936431
安装
yum install -y chromium
测试
chromium-browser --no-sandbox --headless --screenshot=test.png -run-all-compositor-stages-before-draw --window-size=1280,1400 test.html
[root@xxxxxxxxxxx~]# chromium-browser --no-sandbox --headless --screenshot=test.png -run-all-compositor-stages-before-draw --window-size=1280,1400 test.html
[0726/152136.525841:ERROR:angle_platform_impl.cc(43)] Display.cpp:977 (initialize): ANGLE Display::initialize error 12289: Could not open the default X display.
[0726/152136.526057:ERROR:gl_surface_egl.cc(852)] EGL Driver message (Critical) eglInitialize: Could not open the default X display.
[0726/152136.528157:WARNING:bluez_dbus_manager.cc(248)] Floss manager not present, cannot set Floss enable/disable.
[0726/152136.528073:ERROR:gl_surface_egl.cc(1489)] eglInitialize Default failed with error EGL_NOT_INITIALIZED
[0726/152136.528639:ERROR:gl_ozone_egl.cc(21)] GLSurfaceEGL::InitializeOneOff failed.
[0726/152136.539316:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0726/152136.563806:ERROR:angle_platform_impl.cc(43)] Display.cpp:977 (initialize): ANGLE Display::initialize error 12289: Could not open the default X display.
[0726/152136.564481:ERROR:gl_surface_egl.cc(852)] EGL Driver message (Critical) eglInitialize: Could not open the default X display.
[0726/152136.564527:ERROR:gl_surface_egl.cc(1489)] eglInitialize Default failed with error EGL_NOT_INITIALIZED
[0726/152136.564565:ERROR:gl_ozone_egl.cc(21)] GLSurfaceEGL::InitializeOneOff failed.
[0726/152136.573258:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0726/152136.586732:ERROR:angle_platform_impl.cc(43)] Display.cpp:977 (initialize): ANGLE Display::initialize error 12289: Could not open the default X display.
[0726/152136.586854:ERROR:gl_surface_egl.cc(852)] EGL Driver message (Critical) eglInitialize: Could not open the default X display.
[0726/152136.586995:ERROR:gl_surface_egl.cc(1489)] eglInitialize Default failed with error EGL_NOT_INITIALIZED
[0726/152136.587080:ERROR:gl_ozone_egl.cc(21)] GLSurfaceEGL::InitializeOneOff failed.
[0726/152136.589127:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0726/152136.596440:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is disabled, ANGLE is
有报错,不过生成的图片是ok的
接下来就是java执行命令命令行,然后读取图片,业务逻辑就自行处理了