当前位置:网站首页>下载(导出)pdf模板文件(比如:审批单),报错:Invalid nested tag *** found, expected closing tag ***
下载(导出)pdf模板文件(比如:审批单),报错:Invalid nested tag *** found, expected closing tag ***
2022-07-01 18:44:00 【云南吴小黑】
- 前言,接着上一篇(下载(导出)pdf模板文件(比如:审批单));
- 报错原因:html格式有误,结束标签丢失(可能根据实际情况,确认html也是正确的,但是还是会报这个错);
- 解决思路:在拿到html内容时,通过jsoup格式化html内容;
- pom引入jsoup包
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
- 在java代码中实现html格式化
/** * 将html 转换成为严格的XHTML */
public class Html2Xhtml {
/** * 转化类 * * @param htmlPath html文件输入路径(带文件名称) * @param xhtmlPath xhtml文件输入路径(带文件名称) * @return */
public static String html2Xhtml(String htmlPath, String xhtmlPath) {
if (StringUtils.isEmpty(htmlPath)) {
return null;
}
String path = null;
try (FileInputStream fin = new FileInputStream(htmlPath)) {
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
int data = -1;
while ((data = fin.read()) != -1) {
byteArrayOut.write(data);
}
fin.close();
String html = byteArrayOut.toString("UTF-8");
//System.out.println("原始HTML:" + html);
String newHtml = formatHtml(html);
//System.out.println("格式化后HTML:" + newHtml);
byte[] htmlFileData = newHtml.getBytes(StandardCharsets.UTF_8);
byteArrayOut.close();
ByteArrayInputStream tidyInput = new ByteArrayInputStream(htmlFileData);
ByteArrayOutputStream tidyOut = new ByteArrayOutputStream();
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setShowWarnings(false);
tidy.setIndentContent(true);
tidy.setSmartIndent(true);
tidy.setIndentAttributes(false);
tidy.setMakeClean(true);
tidy.setQuiet(true);
tidy.setWord2000(true);
tidy.setXHTML(true);
tidy.setErrout(new PrintWriter(System.out));
tidy.parse(tidyInput, tidyOut);
tidyInput.close();
tidyOut.writeTo(new FileOutputStream(xhtmlPath));
tidyOut.flush();
tidyOut.close();
path = xhtmlPath;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
path = null;
}
return path;
}
/** * 格式化html * * 报错代码:Invalid nested tag *** found, expected closing tag *** * 报错原因:html转xhtml过程中,标签没有闭合 * 解决思路:通过jsoup格式化html * @param html * @return */
private static String formatHtml(String html) {
Document document = Jsoup.parse(html);
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
document.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
return document.html();
}
}
边栏推荐
- Extensive reading of the paper [film: visual reasoning with a general condition layer]
- Once the SQL is optimized, the database query speed is increased by 60 times
- Lake Shore—CRX-EM-HF 型低温探针台
- 助力数字经济发展,夯实数字人才底座—数字人才大赛在昆成功举办
- transform + asm资料
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- M91 fast hall measuring instrument - better measurement in a shorter time
- 中英说明书丨人可溶性晚期糖基化终末产物受体(sRAGE)Elisa试剂盒
- M91快速霍尔测量仪—在更短的时间内进行更好的测量
- Chaos engineering platform chaosblade box new heavy release
猜你喜欢

华为游戏初始化init失败,返回错误码907135000

【To .NET】C#集合类源码解析

Lake shore optimag superconducting magnet system om series

Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit

赋能「新型中国企业」,SAP Process Automation 落地中国

Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
![[pytorch record] automatic hybrid accuracy training torch cuda. amp](/img/a5/cf1eb2801380cf2887dfd532d3eb1e.jpg)
[pytorch record] automatic hybrid accuracy training torch cuda. amp

论文阅读【Learning to Discretely Compose Reasoning Module Networks for Video Captioning】

寶,運維100+服務器很頭疼怎麼辦?用行雲管家!

从零开始学 MySQL —数据库和数据表操作
随机推荐
使用环信提供的uni-app Demo,快速实现一对一单聊
[6.24-7.1] review of wonderful technical blog posts in the writing community
Lake shore M91 fast hall measuring instrument
Extensive reading of the paper [film: visual reasoning with a general condition layer]
MATLAB中subplot函数的使用
Games202 operation 0 - environment building process & solving problems encountered
The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables
PostgreSQL varchar[] array type operation
Lake Shore M91快速霍尔测量仪
案例分享:QinQ基本组网配置
Netease games, radical going to sea
苹果产品在日本全面涨价,iPhone13涨19%
Lumiprobe free radical analysis h2dcfda instructions
Junit单元测试框架详解
Taiaisu M source code construction, peak store app premium consignment source code sharing
Go语言高级
PMP是被取消了吗??
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
[quick application] win7 system cannot run and debug projects using Huawei ide
XML语法、约束