| 主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情! |
| 我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作 |

【相關學習推薦:小程序開發教程】
實施計劃實施步驟安裝環境官方網站地址:https://wkhtmltopdf.org/
Windows:只需下載安裝包并安裝即可。
Linux:下載相應的安裝包并安裝相應的中文字體(phantomjs也需要安裝字體),并在html中聲明引用。
相關代碼使用java執行命令并調用wkhtmltoImage設置相關參數。有關特定參數,請參見wkhtmltoImage的命令提示符。
package com . yumingzhu . wx web . util;導入Java . io . buffered reader;導入Java . io . io exception;導入Java . io . inputstreamreader;/* * * @ Description * @ Author yumingzhu * @ Date 2020/7/22 20:12 */public class CustomWKHtmlToPdfUtil { private static String tempPath =“C:/apps/tmpFile“;//public static string get命令(string html to image,string源文件路徑,string目標文件路徑){//--quality設置為50,默認值94可能會導致圖像文件過大:Process Builder Pb = New Process Builder(html to image,“--crop -w”,“800”,“---width”,“800”,“--quality”,“50”,源文件路徑,目標文件路徑);工藝流程;請嘗試{ process = Pb . start();//請注意,調用process.getErrorStream()而不是process。getInputStream()buffered reader err streamreader = new buffered reader(new input streamreader(process。get errorstream()));system . out . println(“read errstreamreader“);String line = nullline = errstreamreader . readline();while(行!= null){ system . out . println(line);line = errstreamreader . readline();} process . destroy();System.out.println(“銷毀的進程“);} catch(io exception e){ e . printstacktrace();} return targetFilePath} public static void main(String【】args)拋出異常{ String image path = tempPath+“/“+system . current time millis()+“。png“;//圖像路徑system . out . println(image path);string htmlToImage =“E:\ software app \ \ wkhtmltopdf \ \ bin \ \ wkhtmltoimage . exe“;customwkhtmltopdfutil . get command(htmlToImage,“file:///G:/share/text _ none _ title _ share/index . html“,image path);System.out.println(“執行完成“);}}如果html頁面的寬度和高度設置得較小,則剪切出的圖片將會較小且模糊。增加html的寬度和高度將使圖片更清晰,這將導致更大的剪切圖片文件,從而減慢小程序的下載過程。你需要在這里自己權衡。
WkhtmlImage不支持css3 linear -漸變,因此不能使用下劃線樣式。你可以考慮用圖片來代替。
中文字體需要加引號才能生效。
以上是示例小程序(java后端)生成海報的詳細信息,更多內容請關注主機參考的其他相關文章!
這幾篇文章你可能也喜歡:
本文由主機參考刊發,轉載請注明:生成海報的示例小程序(java后端)(一鍵生成海報的小程序在哪里) http://www.k2270.com/101767.html
主機參考

















評論前必須登錄!
注冊