【发布时间】:2012-12-05 00:51:06
【问题描述】:
我的目标是检索页面上所有单词的各自坐标,我所做的是
PdfReader reader = new PdfReader("cde.pdf");
TextWithPositionExtractionStategy S = new TextWithPositionExtractionStategy();
PdfTextExtractor.GetTextFromPage(reader,1,S);
Vector curBaseline = renderInfo.GetDescentLine().GetStartPoint();
Vector topRight = renderInfo.GetAscentLine().GetEndPoint();
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
string x1 = curBaseline[Vector.I1].ToString();
string x2 = curBaseline[Vector.I2].ToString();
string x3 = topRight[Vector.I1].ToString();
string x4 = topRight[Vector.I2].ToString();
但是,我得到的是一个字符串的坐标,它包含了一行的所有单词,而不是一个单词。例如pdf的内容是“我是女孩”,我得到的是“的坐标”我是女孩”,但不是“i”“am”“a”“girl”的坐标。如何修改代码以便获得单词坐标。谢谢。
【问题讨论】:
-
一个词就是一个字符串。向我们准确展示您得到的结果,并将其与您想要的结果进行比较。
-
PDF 中的文本段不一定在单词边界处开始或停止。因此,您将不得不拆分文本段或合并它们。
-
@mkl,谢谢,我知道你说什么,但我不知道该怎么做。你能给我更多帮助吗?
标签: c# itextsharp