我正在尝试使用 Jsoup 获取字体信息。例如:
下面是我的代码:
result = rtfToHtml(new StringReader(streamToString((InputStream)contents.getTransferData(dfRTF))));
// Example of text extraction from html
// Parse html
// String test = result.toString();
Document doc = Jsoup.parse(result);
// Select first bold text
String strdoc = doc.toString();
String words[] = strdoc.split("font-family");
Element firstBoldElt = doc.select("b").first();
Elements ele = doc.select("body");
String test = ele.toString();
Elements all = doc.select("b");
String boldtext = all.text();
通过使用代码,我的输出将如下所示:
"<body>
<p class="default">
<span style="color: #000000; font-size: 21pt; font-family: MyriadPro-Bold;">
<b>Hello World</b>
</span>
<span style="color: #000000; font-size: 21pt; font-family: MyriadPro-Bold;">, Testing</span>
<span style="color: #000000; font-size: 21pt; font-family: MyriadPro-Bold;">
<i><b>Font </b></i>
</span>
<span style="color: #000000; font-size: 21pt; font-family: MyriadPro-Bold;"> Style</span>
<span style="color: #000000; font-size: 21pt; font-family: MyriadPro-Bold;">
<i>Check</i>
</span>
<span style="color: #000000; font-size: 10pt; font-family: MyriadPro-Bold;"></span>
</p>
</body>"
我可以提取第一个BOLD元素或所有BOLD元素,但是我如何才能像这样提取所有类似的元素。
<b>Hello World</b>
, Testing
<i><b>Font </b></i>
Style
<i>Check</i>
任何建议或参考都受到高度赞赏。
已编辑
<body lang="en-MY" dir="LTR">
<p style="margin-bottom: 0in">
<font color="#000000"> <font face="ArialMT, serif"> <font size="2">
<span style="font-style: normal">
<span style="text-decoration: none">
<b>BOLD </b>
</span>
</span>
</font></font></font>
<font color="#000000"><font face="ArialMT, serif"><font size="2">
<span style="font-style: normal">
<span style="text-decoration: none">
<span style="font-weight: normal">
REGULAR
</span>
</span>
</span>
</font></font></font>
<font color="#000000"><font face="ArialMT, serif"><font size="2">
<span style="font-style: normal">
<u>
<span style="font-weight: normal">
UNDERLINED
</span>
</u>
</span>
</font></font></font>
<font color="#000000"><font face="ArialMT, serif"><font size="2">
<span style="font-style: normal">
<span style="text-decoration: none">
<span style="font-weight: normal">
</span>
</span>
</span>
</font></font></font>
<font color="#000000"><font face="ArialMT, serif"><font size="2">
<i>
<span style="text-decoration: none">
<span style="font-weight: normal">
ITALIC
</span>
</span>
</i>
</font></font></font>
<font color="#000000"><font face="ArialMT, serif"><font size="2">
<span style="font-style: normal">
<span style="text-decoration: none">
<span style="font-weight: normal">
</span>
</span>
</span>
</font></font></font>
<font color="#000000"><font face="ArialMT, serif"><font size="2">
<i>
<span style="text-decoration: none">
<b>BOLDITALIC</b>
</span>
</i></font>
</font></font></p>
</body>