当前位置: 首页 > 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.rkmt.cn/news/49813.html

相关文章:

  • 升鲜宝供应链管理系统、各端的访问地址及nginx 真实的配置方法
  • 2025.11.14模拟赛
  • uiautomator2元素查看器WEditor的安装和启动
  • MI50 在ubuntu 下 风扇控制实现
  • nvm不能下载安装低版本node解决办法
  • 完整教程:【实时Linux实战系列】实时 Linux 在边缘计算网关中的应用
  • 20251114——读后感5
  • 251114
  • 好题集 (4) - CF487E Tourists
  • Http基础协议和解析 - 指南
  • 2025年问题肌培训企业最新专业推测top5:技术创新与实战效能全面升级,做好皮肤管理,搞定皮肤亚健康、祛痘祛斑。
  • 备份一点有趣的东西(期刊资源)
  • Swift 和 Tesseract OCR 进行验证码识别
  • Python安装uiautomator2
  • 用【WPF+Dlib68】实现 侧脸 眼镜虚拟佩戴 - 用平面图表现空间视觉 - 教程
  • 2025年11月徐州网站开发服务商怎么选
  • 好题集 (3) - LG P2122 还教室
  • python3如何切换路径
  • 2025-11-14 早报新闻
  • 在 CSharp 中调用 Wolfram Language (Mathematica)
  • oracle 11g r2 linux
  • Kafka协调器:消费者组管理与重平衡机制 - 指南
  • 2025山东公考面试/笔试/考试/辅导培训五星推荐榜:三家优质机构精准适配备考需求,助力高效上岸
  • 2025智能科技/医疗设备/信息科技/新中式茶饮/科创/平面/东方美学/品牌设计/品牌logo设计/品牌VI设计领域优质公司排行榜:聚焦全案创意与视觉赋能,3 家机构助力品牌高效破圈
  • 2025防火/模压/瓦楞/大跨距/热镀锌/热浸锌/不锈钢/光伏/铝合金/锌铝镁电缆桥架优选榜:河北百著全系列防护覆盖 三家实力厂家凭场景优势突围
  • 2025修护/二硫化硒去屑/香氛/控油蓬松/洗发水品牌推荐榜:精准护养新选择,MASIL玛丝兰领衔解决头屑、扁塌等护发难题
  • antd 上传文件组件在表单回显时不显示下载按钮
  • 2025滚齿机优质厂家推荐榜:济南兴宇数控五星领跑,三大厂商凭技术与适配性成行业标杆
  • 2025年芝麻白/芝麻灰/火烧面/亚光面/花岗岩/路岩石优质厂家优选榜:聚焦专业品质,助力工程建设
  • 2025泰安软件开发公司推荐榜:软件开发公司/软件公司/泰安软件公司技术实力助力企业数字化转型