Using pdfBox to convert pdf to picture and solve the problem of Chinese block code

Keywords: Apache Java Maven svn

Reference article Troubleshooting: when pdfbox is used to transfer pdf to image, stsong light font in Chinese is garbled

pdfbox version is 2.0
A log like this (for example, using fallback XXX for CID keyed font stsong light) is printed in the log, which means that stsong light font is not installed in the system. pdfbox uses XXX font instead. If the box appears, it means that there is no such font, and there is no alternative font, and the log also has corresponding other prompts.

The normal operation is to install the missing STSong light font. However, all the fonts found on the Internet are STSong fonts that have no effect after installation. My windows 10

Refer to the above article (see for sure), modify FontMapperImpl to add the mapping font stsong light - > stfangsong in questions
Download pdfbox from Apache Source code Modify \ pdfbox\src\main\java\org\apache\pdfbox\pdmodel\font\

final class FontMapperImpl implements FontMapper
    private static final FontCache fontCache = new FontCache(); // todo: static cache isn't ideal
    private FontProvider fontProvider;
    private Map<String, FontInfo> fontInfoByName;
    private final TrueTypeFont lastResortFont;

    /** Map of PostScript name substitutes, in priority order. */
    private final Map<String, List<String>> substitutes = new HashMap<String, List<String>>();

        // substitutes for standard 14 fonts
                Arrays.asList("CourierNew", "CourierNewPSMT", "LiberationMono", "NimbusMonL-Regu"));
                Arrays.asList("CourierNewPS-BoldMT", "CourierNew-Bold", "LiberationMono-Bold",
                        "LiberationMono-Italic", "NimbusMonL-ReguObli"));
                        "LiberationMono-BoldItalic", "NimbusMonL-BoldObli"));
                Arrays.asList("ArialMT", "Arial", "LiberationSans", "NimbusSanL-Regu"));
                Arrays.asList("Arial-BoldMT", "Arial-Bold", "LiberationSans-Bold",
                Arrays.asList("Arial-ItalicMT", "Arial-Italic", "Helvetica-Italic",
                        "LiberationSans-Italic", "NimbusSanL-ReguItal"));
                Arrays.asList("Arial-BoldItalicMT", "Helvetica-BoldItalic",
                        "LiberationSans-BoldItalic", "NimbusSanL-BoldItal"));
                Arrays.asList("TimesNewRomanPSMT", "TimesNewRoman", "TimesNewRomanPS",
                        "LiberationSerif", "NimbusRomNo9L-Regu"));
                Arrays.asList("TimesNewRomanPS-BoldMT", "TimesNewRomanPS-Bold",
                        "TimesNewRoman-Bold", "LiberationSerif-Bold",
                Arrays.asList("TimesNewRomanPS-ItalicMT", "TimesNewRomanPS-Italic",
                        "TimesNewRoman-Italic", "LiberationSerif-Italic",
                Arrays.asList("TimesNewRomanPS-BoldItalicMT", "TimesNewRomanPS-BoldItalic",
                        "TimesNewRoman-BoldItalic", "LiberationSerif-BoldItalic",
        substitutes.put("Symbol", Arrays.asList("Symbol", "SymbolMT", "StandardSymL"));
        substitutes.put("ZapfDingbats", Arrays.asList("ZapfDingbatsITC", "Dingbats", "MS-Gothic"));
        // FIXME believelelf STSong-Light->STFangsong
		substitutes.put("STSong-Light", Arrays.asList("STFangsong"));
        // Acrobat also uses alternative names for Standard 14 fonts, which we map to those above
        // these include names such as "Arial" and "TimesNewRoman"

Compile and package my jdk7 with maven according to the official website instructions
Using the modified jar package to solve the problem of garbled code
Baidu online disk
Extraction code: ir0z

Download some descriptions of the source code from the official website:

The path I use SVN to check out is
The updated version must be compiled with jdk1.8. My project is running with 1.7, so I downloaded version 2.0.0

maven compilation and packaging instructions

Follow the instructions to run mvn clean install in the. \ pdfbox folder
But test will be run, and I will report an error here, so I closed the test mvn clean install -DskipTests reference resources

I'm a rookie. If you have good solutions or ideas, please leave a message
I hope this article can help you. Thank you

Posted by tejama on Tue, 09 Jun 2020 20:53:59 -0700