ApplyOCRTextLayer

OCR、文本、文档编辑

描述

验证与提供程序无关的 OCR JSON,并向页面添加适配的渲染模式 3 文本

添加的文本可搜索且可选择,但渲染页面时不可见

语法

Delphi

Function TPDFlib.ApplyOCRTextLayer(Page: Integer; Const ResultJSON,
  FontName: WideString; MinConfidence: Double): Integer;

ActiveX

Function PDFlib::ApplyOCRTextLayer(Page As Long, ResultJSON As String, FontName As String, MinConfidence As Double) As Long

DLL

int DLApplyOCRTextLayer(int InstanceID, int Page, const wchar_t* ResultJSON,
  const wchar_t* FontName, double MinConfidence);
int DLApplyOCRTextLayerA(int InstanceID, int Page, const char* ResultJSON,
  const char* FontName, double MinConfidence);

参数

Page一基目标页面
ResultJSON带版本的 OCR 结果对象
FontName可嵌入的 TrueType 字体名称或路径,或用以选择已安装回退字体的空字符串
MinConfidence从 0 到 1 的包含端点置信度阈值

JSON 架构

{
  "version": 1,
  "width": 2480,
  "height": 3508,
  "words": [
    {"text": "Invoice", "left": 120, "top": 180,
     "width": 260, "height": 54, "confidence": 0.98}
  ]
}

left 和 top 在源单位中使用左上角原点

同时存在 width 和 height 时,词框从这些源尺寸缩放到 PDF 页面;同时省略时,坐标解释为 PDF 点

每个单词均需要 text、left、top、width 和 height;confidence 为可选项,默认值为 1

几何值必须为有限非负值,宽度和高度必须为正值,置信度必须在 0 到 1 之间

返回值

1文本层已添加,或者没有单词达到阈值
0验证或写入失败

备注

在写入页面内容前,将验证完整的 JSON 结构和每个词边界

每个词根据其框高度确定大小,并使用文本缩放进行水平适配;独立图形状态可防止 OCR 格式泄漏到后续绘图操作

OCR JSON 无效时 LastErrorCode 为 110,页面、字体或文本层写入失败时为 307

LastOCRError 提供详细原因

另请参阅

OCRPage, OCRDocument, LastOCRError, RenderPageToString