1.替换img地址
/**
* 替换img地址
* @param str -- 前台svg字符串
* @return
*/
private String transferImgPath(HttpServletRequest request,String str) {
System.out.println(str);
String requestURL = request.getRequestURL().toString();
String requestURI = request.getRequestURI();
String httpURL = requestURL.replace(requestURI,"");
String ptn = "(?i)href=\"([^\"]*)\"[^>]*>";
Pattern p = Pattern.compile(ptn, Pattern.DOTALL);
Matcher m = p.matcher(str);
List<String> list = new ArrayList<String>();
while(m.find()) {
String imgurl = m.group(1);
if(!imgurl.contains("http") && !list.contains(imgurl)) {
str = str.replaceAll(imgurl,httpURL + "/resources/myflow-min/" + imgurl);
}
list.add(imgurl);
}
return str;
}
2.将svg字符串转换为png