解决思路就是修改源码,过滤掉mstmc.ttf文件读取,具体操作如下:
1、在自己的项目中新建包结构为:org.apache.pdfbox.pdmodel.font
2、新建FileSystemFontProvider.java文件,将下方代码复制进去即可
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.pdfbox.pdmodel.font;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fontbox.FontBoxFont;
import org.apache.fontbox.cff.CFFCIDFont;
import org.apache.fontbox.cff.CFFFont;
import org.apache.fontbox.ttf.NamingTable;
import org.apache.fontbox.ttf.OS2WindowsMetricsTable;
import org.apache.fontbox.ttf.OTFParser;
import org.apache.fontbox.ttf.OpenTypeFont;
import org.apache.fontbox.ttf.TTFParser;
import org.apache.fontbox.ttf.TrueTypeCollection;
import org.apache.fontbox.ttf.TrueTypeCollection.TrueTypeFontProcessor;
import org.apache.fontbox.ttf.TrueTypeFont;
import org.apache.fontbox.type1.Type1Font;
import org.apache.fontbox.util.autodetect.FontFileFinder;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.util.Charsets;
/**
* A FontProvider which searches for fonts on the local filesystem.
*
* @author John Hewson
*/
final class FileSystemFontProvider extends FontProvider {
private static final Log LOG = LogFactory.getLog(FileSystemFontProvider.class);
private final List<FSFontInfo> fontInfoList = new ArrayList<FSFontInfo>();
private final FontCache cache;
private static class FSFontInfo extends FontInfo {
private final String postScriptName;
private final FontFormat format;
private final CIDSystemInfo cidSystemInfo;
private final int usWeightClass;
private final int sFamilyClass;
private final int ulCodePageRange1;
private final int ulCodePageRange2;
private final int macStyle;
private final PDPanoseClassification panose;
private final File file;
private final FileSystemFontProvider parent;
private FSFontInfo(File file, FontFormat format, String postScriptName, CIDSystemInfo cidSystemInfo,
int usWeightClass, int sFamilyClass, int ulCodePageRange1, int ulCodePageRange2, int macStyle,
byte[] panose, FileSystemFontProvider parent) {
this.file = file;
this.format = format;
this.postScriptName = postScriptName;
this.cidSystemInfo = cidSystemInfo;
this.usWeightClass = usWeightClass;
this.sFamilyClass = sFamilyClass;
this.ulCodePageRange1 = ulCodePageRange1;
this.ulCodePageRange2 = ulCodePageRange2;
this.macStyle = macStyle;
this.panose = panose != null && panose.length >= PDPanoseClassification.LENGTH
? new PDPanoseClassification(panose)
: null;
this.parent = parent;
}
@Override
public String getPostScriptName() {
return postScriptName;
}
@Override
public FontFormat getFormat() {
return format;
}
@Override
public CIDSystemInfo getCIDSystemInfo() {
return cidSystemInfo;
}
/**
* {@inheritDoc}
* <p>
* The method returns null if there is there was an error opening the font.
*
*/
@Override
public synchronized FontBoxFont getFont() {
// synchronized to avoid race condition on cache access,
// which could result in an unreferenced but open font
FontBoxFont cached = parent.cache.getFont(this);
if (cached != null) {
return cached;
} else {
FontBoxFont font;
switch (format) {
case PFB:
font = getType1Font(postScriptName, file);
break;
case TTF:
font = getTrueTypeFont(postScriptName, fil