原先使用過(guò)wkhtmltox,也是個(gè)不錯(cuò)的工具,使用也是相當(dāng)簡(jiǎn)單,不過(guò)對(duì)部分css3樣式不支持
現(xiàn)在使用Chrome CLI生成圖片,就是安裝瀏覽器,利用瀏覽器生成圖片,只要瀏覽器能解析,生成圖片就是ok的
參看下https://blog.csdn.net/xuechangchun007/article/details/120936431
安裝
yum install -y chromium
測(cè)試
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
有報(bào)錯(cuò),不過(guò)生成的圖片是ok的
接下來(lái)就是java執(zhí)行命令命令行,然后讀取圖片,業(yè)務(wù)邏輯就自行處理了