配置字体文件

package com.sziov.gacnev.flowable.config;

import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

/**
 * Flowable配置
 */
@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        engineConfiguration.setActivityFontName("宋体");
        engineConfiguration.setLabelFontName("宋体");
        engineConfiguration.setAnnotationFontName("宋体");
    }
}

生成流程图代码

package com.sziov.gacnev.flowable.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.*;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;


/**
 * 工作流流程实例管理
 * @author pwl
 */
@RestController
@RequestMapping("/v1")
@Slf4j
@Api(value = "工作流流程实例管理", description = "工作流流程实例管理")
public class FlowInstanceController {
    
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    ProcessEngine processEngine;
    @Autowired
    HistoryService historyService;
    @Autowired
    RepositoryService repositoryService;

    @ApiOperation(value = "流程实例图")
    @GetMapping("/public/instance/pic")
    public void showPic(HttpServletResponse resp, String processId) throws Exception {
        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (pi == null) {
            return;
        }
        List<Execution> executions = runtimeService
                .createExecutionQuery()
                .processInstanceId(processId)
                .list();

        List<String> activityIds = new ArrayList<>();
        List<String> flows = new ArrayList<>();
        for (Execution exe : executions) {
            List<String> ids = runtimeService.getActiveActivityIds(exe.getId());
            activityIds.addAll(ids);
        }

        /**
         * 生成流程图
         */
        BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
        ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
        ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
        InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0, false);
        OutputStream out = null;
        byte[] buf = new byte[1024];
        int legth = 0;
        try {
            out = resp.getOutputStream();
            while ((legth = in.read(buf)) != -1) {
                out.write(buf, 0, legth);
            }
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }

}

获取中文字体

字体包这边已经为大家准备好了
链接:https://pan.baidu.com/s/1eF_VflVDkk-zLbcbuIdXbA
提取码:pwly

上传到服务器目录:/usr/share/fonts 下

在这里插入图片描述

使用unzip windowsFonts.zip 命令解压字体包

在这里插入图片描述

使用cd windowsFonts 进入目录下

在这里插入图片描述

使用 fc-cache -fv 命令安装字体,查看字体是否安装成功 fc-list 命令

在这里插入图片描述

重启java流程图接口所在的服务,再页面访问发现中文不再乱码了
在这里插入图片描述

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐