pdfbox Could not load font file: C:\WINDOWS\FONTS\mstmc.ttf java.io.EOFException

2022-07-25,,,,

PDF转图片使用pdfbox

版本2.0.22

初始化过程中,该jar包会读取服务器上的全部字体文件。该报错并非缺少该字体文件mstmc.ttf

而是该文件无法正常作为字体读取

mstmc.ttf文件大小为4KB明显不是正常的字体文件且双击无法安装

通过debugger修改源码 org\apache\pdfbox\pdfbox\2.0.22\pdfbox-2.0.22.jar!\org\apache\pdfbox\pdmodel\font\FileSystemFontProvider.class

跳过加载该文件,问题解决

private void scanFonts(List<File> files)
    {
        for (File file : files)
        {
            try
            {
                //win10下该文件非字体
                if (file.getCanonicalPath().contains("mstmc.ttf")) {
                    continue;
                }
                else if ((file.getPath().toLowerCase().endsWith(".ttf") || file.getPath().toLowerCase().endsWith(".otf")))
                {
                    addTrueTypeFont(file);
                }
                else if (file.getPath().toLowerCase().endsWith(".ttc") ||
                        file.getPath().toLowerCase().endsWith(".otc"))
                {
                    addTrueTypeCollection(file);
                }
                else if (file.getPath().toLowerCase().endsWith(".pfb"))
                {
                    addType1Font(file);
                }
            }
            catch (IOException e)
            {
                LOG.error("Error parsing font " + file.getPath(), e);
            }
        }
    }

 

本文地址:https://blog.csdn.net/a783295110/article/details/112517462

《pdfbox Could not load font file: C:\WINDOWS\FONTS\mstmc.ttf java.io.EOFException.doc》

下载本文的Word格式文档,以方便收藏与打印。