我是pdfbox的新手。在使用pdfbox库提取文本后,是否有办法区分上标和下标文本与普通文本?谢谢。
if((position.getY() < lastPosition.getTextPosition().getY()
&& position.getHeight() < lastPosition.getTextPosition().getHeight())
|| (position.getY() > lastPosition.getTextPosition().getY()
&& position.getHeight() > lastPosition.getTextPosition().getHeight()))
line.add(WordSeparator.getSeparator());
然后将以下内容添加到writeLine()中,在上标之前或之后添加标签:
if(word.textPositions.size()>0)
{
TextPosition firstChar = word.textPositions.get(0);
if(i==0)
{
prevY = firstChar.getY();
prevHeight = firstChar.getHeight();
}
if(prevY!=0)
{
if((firstChar.getY() < prevY && firstChar.getHeight() < prevHeight))
{
output.write("<sup>");
writeString(word.getText(), word.getTextPositions());
}
else if((firstChar.getY() > prevY && firstChar.getHeight() > prevHeight))
{
output.write("</sup>");
writeString(word.getText(), word.getTextPositions());
}
else
writeString(word.getText(), word.getTextPositions());
}