当前位置: 首页 > news >正文

How-to-extract-text-from-PDF-Image-files-OCR-CarlZeng

本文阐述如何自建并使用OCR识别图片或PDF中文字(转化成文本等进一步处理), 以及NetSuite调用OCR API的场景雏形.
How to extract text from PDF(Image) files. 20251113 引入自建ocr服务

docker部署OCR项目

支持离线+API, 自建ocr服务

Docker compose, vi docker-compose.yml

version: "3"
services:trwebocr:image: mmmz/trwebocr:latestcontainer_name: trwebocrrestart: unless-stoppedports:- "8103:8089"environment:- LANG=zh_CN.UTF-8volumes:- ./data:/app/tr_web/data  #持久化OCR数据

运行docker后, OCR服务开启

访问方式一: (通过网页访问)

访问方式二: 文字识别API

描述: 进行文字识别与检测的接口

地址: https://ocr.carlzeng.com:3/api/tr-run/

方法: POST

请求参数:

参数名称 是否必选 数据类型 描述
file 和 img 二选一 file 通过上传的方式来发送图片的字段
img 和 file 二选一 string 图片的base64值,不需要前缀。
compress int 值为空时,默认将图片最长边压缩到1600px。 值为 0 时,不压缩图片。 值为非0 时,将最长边压缩到该值的大小。
is_draw int 值为 0 时,不返回图片。(没有data['img_detected']返回)

返回参数:

参数名称 是否必选 数据类型 描述
code int 识别结果的状态码,识别成功为200,有异常为 400
msg string 识别结果的文字信息
data dict 识别结果,若识别异常则没有此字段
data['img_detected'] string 画出文字区域的图片base64值
data['raw_out'] list 识别结果的输出
data['speed_time'] float 识别的耗时

返回示例:

{"code": 200,"msg": "\u6210\u529f", "data": {"img_detected": "data:image/jpeg;base64,/9j/4AAQSkZJR5t...","raw_out": [[[11, 13, 402, 36], "\u753b\u51fa\u6587\u5b57\u533a\u57df\u7684\u56fe\u7247base64\u503c", 0.9999545514583588], [[11, 112, 215, 36], "\u8bc6\u522b\u7ed3\u679c\u7684\u8f93\u51fa", 0.999962397984096], [[11, 171, 158, 36], "\u8bc6\u522b\u7684\u8017\u65f6", 0.999971580505371]], "speed_time": 0.67}}

image-20251113205953922

本小节灵感:

https://github.com/alisen39/TrWebOCR)

https://post.smzdm.com/p/agwev0l6/

NetSuite API呼叫OCR

Background: below is SS1.0 as example since it came from NetSuite email plugin, SS2.0 is the same thing.

下面使用的第三方服务平台, 同样把地址修改为上方的自建平台也是实现ocr识别功能.

1. Registry a API key throw https://ocr.space/OCRAPI

There are limitations for Free Plan

2. Save the email attachment(PDF file) to NetSuite FileCabinet, set it to available without login, get the full url address, encode it.

var importFile = attachments[indexAtt];importFile.setIsOnline(true);
var intFileId = nlapiSubmitFile(importFile);
var strInvFileUrl = "https://" + nlapiGetContext().getCompany() + ".app.netsuite.com"+ objInvoiceFileRec.getURL();
strInvFileUrl = encodeURIComponent(strInvFileUrl);

3. Send Request to https://api.ocr.space/parse/imageurl?apikey=abcAPIKEYabc&filetype=PDF&isTable=true&url=

var response = nlapiRequestURL(strReqUrl, null, a);
There are varience of parameters for this API, in my case, it's invoice formated as table, that's why I send isTable=true to identify it; then it will help me to locate the expected cell and values.

4. Got and parsed the Response, we will get the Text messages on the PDF or Images.

var arrParsedLines = (objOcrRes['ParsedResults'] && objOcrRes['ParsedResults'][0]) ? objOcrRes['ParsedResults'][0]['TextOverlay']['Lines']: null;
var objVndBillData = parseDataFromInvPdf(arrParsedLines);

定制服务下单

image-20251110210430326

服务流程

image-20251109195518962

服务内容

image-20251109195734192

image-20251109195806782

http://www.jsqmd.com/news/40531/

相关文章:

  • Web应用模糊测试完全指南
  • 升鲜宝供应链管理系统、各端的访问地址及nginx 真实的配置方法
  • uiautomator2元素查看器WEditor的安装和启动
  • WEditor的使用方法
  • 【题解】LOJ6300. 「CodePlus 2018 3 月赛」博弈论与概率统计
  • 感情粉末沿着试管边缘 在祝福中逐渐分解 加热认知离子重新排列 于底部悲伤沉淀
  • C#循序渐进 - 详解
  • 2025.11.14 - A
  • 从RvmTranslator到PlantAssistant
  • MI50 在ubuntu 下 风扇控制实现
  • PortSwigger靶场之 CSRF where token is not tied to user session通关秘籍 - 实践
  • nvm不能下载安装低版本node解决办法
  • flask: 抛出异常
  • 20251114——读后感5
  • 雪地奔驰全等级提升所需经验一览
  • 2025皮肤亚健康管理品牌最新专业推荐:科技赋能健康美新生态
  • 【HT-086-Div.2】嗡嗡蜜蜂
  • 第四十一篇
  • 深入解析:Vue3 路由配置和使用与讲解(超级详细)
  • 好题集 (0) - 目录
  • 251114
  • HubSpot如何规模化推进AI编码助手应用
  • 好题集 (4) - CF487E Tourists
  • 完整教程:OpenHarmony内核基础:LiteOS-M内核与POSIX/CMSIS接口
  • Http基础协议和解析 - 指南
  • 2025年问题肌培训企业最新专业推测top5:技术创新与实战效能全面升级,做好皮肤管理,搞定皮肤亚健康、祛痘祛斑。
  • 备份一点有趣的东西(期刊资源)
  • 11.14模拟赛
  • Swift 和 Tesseract OCR 进行验证码识别
  • 实用指南:云计算生态及学习方向和就业领域方向