ApplyOCRTextLayer
OCR、文字、文件編輯
描述
驗證供應商中立的 OCR JSON,並把貼合的 rendering-mode-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 LongDLL
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 | 目標頁面(1 起算) |
|---|---|
| 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}
]
}lefttop
widthheight
text 與 left 以來源單位、左上角為原點top 與 width 同時存在時,單字框會從那些來源尺寸縮放到 PDF 頁面;兩者同時省略時,座標按 PDF 點解讀每個單字需要 height、confidence、
top、width 與 height;confidence 為選配,預設 1幾何值必須為有限非負值且寬高為正,confidence 則須在 0 到 1 之間
傳回值
| 1 | 文字圖層已加入,或沒有單字達到閾值 |
|---|---|
| 0 | 驗證或寫入失敗 |
備註
頁面內容寫入前會驗證完整 JSON 結構與每個文字邊界
每個文字以其方框高度決定大小,並以文字縮放做水平調整,同時以隔離的圖形狀態防止 OCR 格式外洩到後續的繪圖操作
LastErrorCode 為 110 表示 OCR JSON 無效,307 表示頁面、字型或文字層寫入失敗
LastOCRError 提供詳細原因