Linux 下安裝Windows字體


Linux 下安裝Windows字體

項目部署到Linux平台之后經常會遇缺少字體的問題,例如在Ubuntu Server上預覽或者打印jasper報表時異常:

net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Arial' is not available to the JVM. See the Javadoc for more details.
  at net.sf.jasperreports.engine.util.JRFontUtil.checkAwtFont(JRFontUtil.java:321)
  at net.sf.jasperreports.engine.util.JRStyledText.getAwtAttributedString(JRStyledText.java:226)

而開發人員在本地測試缺沒有問題,這是因為這些字體在windows安裝的時候就有了(mac嘛我沒用過,嘿嘿,不知道是否默認安裝了windows的字體)

解決辦法(以Ubuntu 為例)

  • 使用包管理器安裝

    sudo apt update && sudo apt install ttf-mscorefonts-installer
    

    安裝過程中會彈出提示,一路默認選項同意即可

    安裝完成記得刷新字體緩存

    sudo fc-cache -f -v
    
  • 將Windows下的字體拷貝到Linux下

    將Windows字體(選中所有字體壓縮)壓縮成Fonts.zip包,並上傳到Linux中

    在Linux中新建目錄

    sudo mkdir -p /usr/share/fonts/WindowsFonts
    

    將Windows字體壓縮包中的內容解壓到剛剛創建的目錄中

    sudo unzip ~/Fonts.zip -d /usr/share/fonts/WindowsFonts
    

    然后修改一下權限

    sudo chmod 755 /usr/share/fonts/WindowsFonts/*
    

    最后刷新一下字體

    sudo fc-cache
    

    再次預覽報表,就可以正常顯示了~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM