【发布时间】:2018-01-11 10:30:31
【问题描述】:
我的 pdf 中有一些经过 OCR 处理的文本。
OCR 将单词的边界框返回给我。
我能够在 pdf 上绘制边界框 (wordRect),一切似乎都是正确的。
但是当我告诉我的字体大小是这些边界框的高度时, 一切都出错了。文字看起来比应有的小得多,并且与高度不匹配。
我缺少一些转换。如何确保文本与边界框一样高?
pdftron.PDF.Font font = pdftron.PDF.Font.Create(convertedPdf.GetSDFDoc(), pdftron.PDF.Font.StandardType1Font.e_helvetica);
for (int j = 0; j < ocrStream.pr_WoordList.Count; j++)
{
wordRect = (Rectangle) ocrStream.pr_Rectangles[j];
Element textBegin = elementBuilder.CreateTextBegin();
gStateTextRun = textBegin.GetGState();
gStateTextRun.SetTextRenderMode(GState.TextRenderingMode.e_stroke_text);
elementWriter.WriteElement(textBegin);
fontSize = wordRect.Height;
double descent;
if (hasColorImg)
{
descent = (-1 * font.GetDescent() / 1000d) * fontSize;
textRun = elementBuilder.CreateTextRun((string)ocrStream.pr_WoordList[j], font, fontSize);
//translate the word to its correct position on the pdf
//the bottom line of the wordrectangle is the baseline for the font, that's why we need the descender
textRun.SetTextMatrix(1, 0, 0, 1, wordRect.Left, wordRect.Bottom + descent );
【问题讨论】:
-
您能否发布您所看到的屏幕截图,并清楚地表明您希望看到的内容?请注意,字体大小是一个“缩放因子”,并没有明确设置文本的大小。这取决于每个字形本身。
-
这对您来说仍然是个问题吗?我想提供帮助,但目前尚不清楚您对输出的期望是什么?字形的确切高度不仅取决于字体和字体大小,还取决于特定的字形(例如
a与A)。你的边界框是每个字形吗?同样,屏幕截图会很有帮助,它可以显示你得到了什么,以及你期望得到什么。 -
我找到了另一个解决方案。感谢瑞恩提供的信息,非常感谢您的帮助
-
如果可以的话,你可以回答你自己的问题,我相信它会对其他人有用。