AIPPT项目开源啦,欢迎大家学习❗

aippt项目开源分享
github地址 :  https://github.com/veasion/aippt       (有技术对接交流群)
官网体验(开放Api): https://docmee.cn

开放接口

线上接口地址:https://docmee.cn

SDK

接口鉴权

创建接口 token

POST /api/user/createApiToken

请求 header

​ Api-Key 在开放平台获取 获取API-KEY

请求 body

 

{

"uid": "xxx", // 第三方用户ID(用户之间数据隔离,可空)

"limit": null // 限制 token 最大生成PPT次数(数字,为空则不限制,为0时不允许生成PPT,大于0时限制生成PPT次数)

}

响应 body

 

{

"data": {

"token": "sk_xxx", // token (调用api接口鉴权用,请求头传token)

"expireTime": 7200, // 过期时间(秒)

"uid": "xxx"

},

"code": 0,

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/user/createApiToken' \

--header 'Content-Type: application/json' \

--header 'Api-Key: xxx' \

--data '{"uid": "xxx","limit": 10}'

注意:该接口请在服务端调用,同一个 uid 创建 token 时,之前通过该 uid 创建的 token 会在10秒内过期

场景说明:在UI集成中,为防止 token 滥用,limit 参数可以让第三方集成商维护自己平台用户的使用次数,未注册用户访问时可以创建 limit 为 0 的 token ,用户能使用但生成不了PPT,UI中监听次数用完的事件指导用户登录,登录用户访问时可以根据系统 vip 级别限制和维护系统用户 limit 次数

查询API信息

GET /api/user/apiInfo

请求 header

​ Api-Key 在开放平台获取 获取API-KEY

响应 body

 

{

"data": {

"availableCount": 100, // 可用次数

"usedCount": 0 // 已使用次数

},

"code": 0,

"message": "操作成功"

}

请求示例

 

curl -X GET --location 'https://docmee.cn/api/user/apiInfo' \

--header 'Api-Key: xxx'

API 接口鉴权

请求 Header

​ token 通过 createApiToken 接口创建的 token,如果是服务端调用也可直接使用 apiKey 作为 token

接口请求示例

 

curl --location 'https://docmee.cn/api/ppt/xxx' \

--header 'token: xxx'

封面图片资源访问,需要在 url 上拼接 ?token=xxx

AI PPT

接口调用说明

api 接口有很多种灵活搭配方案,具体取决于您的业务需求。

  • 方案一:直接生成PPT(最简单对接方案)

    • 调用 directGeneratePptx 直接生成PPT 接口,支持流式和非流式,PPT文件通过接口返回的 fileUrl 下载
  • 方案二:实时流式生成PPT(用户体验最佳-文多多官方方案)

    • 调用 generateOutline 生成大纲 接口,流式生成 PPT 大纲目录 markdown.

    • 调用 generateContent 生成大纲内容同时异步生成PPT 接口,这个接口 asyncGenPptx 参数需要传 true,流式生成,根据第一步返回的大纲目录生成完整大纲内容 markdown,异步生成 PPT

    • 在第二步 generateContent 接口中,接收实时流式 json 数据过程中判断 json 中是否有 pptId ,存在时调用 asyncPptInfo 查询异步生成PPT信息 接口,获取异步生成 PPT 的进度和数据(前端实时渲染)

  • 方案三:同步流式生成PPT

    • 调用 generateOutline 生成大纲 接口,流式生成 PPT 大纲目录 markdown.
    • 调用 generateContent 生成大纲内容 接口,这个接口 asyncGenPptx 参数需要传 false,流式生成,根据第一步返回的大纲目录生成完整大纲内容 markdown
    • 调用 generatePptx 生成 PPT 接口,通过完整 markdown 内容合成 PPT,通过 fileUrl 下载
  • 方案四:通过markdown生成PPT

    • 集成方生成 markdown 内容,内容格式如下:

       

      # 主题

      ## 章节

      ### 页面标题

      #### 内容标题

      - 内容

    • 调用 generatePptx 生成 PPT 接口,通过完整 markdown 内容合成 PPT,通过 fileUrl 下载

解析文件内容

POST /api/ppt/parseFileData

form/data 参数

参数类型是否必传说明
fileFile文件(支持 doc/docx/pdf/txt/md/xlsx 等文件)
contentstring用户粘贴文本内容
fileUrlstring文件公网链接
websitestring网址(http/https)
websearchstring网络搜索关键词

响应:

 

{

"data": {

"dataUrl": "https://xxx" // 数据url(有效期:当天)

},

"code": 0,

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/parseFileData' \

--header 'Content-Type: multipart/form-data' \

--header 'token: {token}' \

--form 'file=@test.doc;filename=test.doc' \

--form 'content=文本内容' \

--form 'fileUrl=https://xxx.pdf' \

--form 'website=https://docmee.cn' \

--form 'websearch=上海元符号智能科技有限公司'

生成大纲

POST /api/ppt/generateOutline

参数

 

{

// 方式一:通过主题创建

"subject": "xxx", // 主题

"prompt": null, // 用户要求

// 方式二:通过文件内容创建

"dataUrl": "https://xxx" // 数据url

}

响应 event-stream 流式生成

 

{

"text": "",

"status": 1 // 状态:-1异常 1解析文件 3生成中 4完成

}

{ "text": "# ", "status": 3 }

{ "text": " ", "status": 3 }

{ "text": "主题", "status": 3 }

...

{

"text": "",

"status": 4,

"result": {

"level": 1,

"name": "主题",

"children": [

{

"level": 2,

"name": "章节",

"children": [

{

"level": 3,

"name": "页面标题",

"children": [

{

"level": 4,

"name": "内容标题"

}

]

}

]

}

]

}

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/generateOutline' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"subject": "AI未来的发展"}'

生成大纲内容

POST /api/ppt/generateContent

参数

 

{

"outlineMarkdown": "# 主题\n## 章节\n### 页面标题\n#### 内容标题", // 大纲 markdown 文本

"prompt": null, // 用户要求

"asyncGenPptx": false, // 是否异步生成,这里为 false 同步,异步请见 "AI PPT (异步)" 菜单

"dataUrl": null // 数据url

}

响应 event-stream 流式生成

 

{

"text": "",

"status": 3 // 状态:-1异常 1解析文件 3生成中 4完成

}

{ "text": "#", "status": 3 }

{ "text": " ", "status": 3 }

{ "text": "主题", "status": 3 }

...

{

"text": "",

"status": 4,

"result": {

"level": 1,

"name": "主题",

"children": [

{

"level": 2,

"name": "章节",

"children": [

{

"level": 3,

"name": "页面标题",

"children": [

{

"level": 4,

"name": "内容标题",

"children": [

{

"level": 0,

"name": "内容"

}

]

}

]

}

]

}

]

}

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/generateContent' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"outlineMarkdown": "xxx"}'

分页查询 PPT 模板

POST /api/ppt/templates

参数

 

{

"page": 1,

"size": 10,

"filters": {

"type": 1, // 模板类型(必传):1系统模板、4用户自定义模板

"category": null, // 类目筛选 ['年终总结', '教育培训', '医学医疗', '商业计划书', '企业介绍', '毕业答辩', '营销推广', '晚会表彰', '个人简历']

"style": null, // 风格筛选 ['扁平简约', '商务科技', '文艺清新', '卡通手绘', '中国风', '创意时尚', '创意趣味']

"themeColor": null // 主题颜色筛选 ['#FA920A', '#589AFD', '#7664FA', '#65E5EC', '#61D328', '#F5FD59', '#E05757', '#8F5A0B', '#FFFFFF', '#000000']

}

}

响应

 

{

"code": 0,

"total": 1,

"data": [

{

"id": "xxx", // 模板ID

"type": 1, // 模板类型:1大纲完整PPT、4用户模板

"coverUrl": "https://xxx.png", // 封面

"category": null, // 类目

"style": null, // 风格

"themeColor": null, // 主题颜色

"subject": "", // 主题

"num": 20, // 模板页数

"createTime": "2024-01-01 10:00:00"

}

],

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/templates' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"page": 1, "size":10, "filters": { "type": 1 }}'

封面图片资源访问,需要在 url 上拼接 ?token=xxx

随机 PPT 模板

POST /api/ppt/randomTemplates

参数

 

{

"size": 30,

"filters": {

"type": 1, // 模板类型(必传):1系统模板、4用户自定义模板

"category": null, // 类目 ['年终总结', '教育培训', '医学医疗', '商业计划书', '企业介绍', '毕业答辩', '营销推广', '晚会表彰', '个人简历']

"style": null, // 风格 ['扁平简约', '商务科技', '文艺清新', '卡通手绘', '中国风', '创意时尚', '创意趣味']

"themeColor": null, // 主题颜色 ['#FA920A', '#589AFD', '#7664FA', '#65E5EC', '#61D328', '#F5FD59', '#E05757', '#8F5A0B', '#FFFFFF', '#000000']

"neq_id": [] // 排查ID集合(把之前查询返回的id排除)

}

}

响应

 

{

"code": 0,

"total": 1,

"data": [

{

"id": "xxx", // 模板ID

"type": 1, // 模板类型:1大纲完整PPT、4用户模板

"coverUrl": "https://xxx.png", // 封面

"category": null, // 类目

"style": null, // 风格

"themeColor": null, // 主题颜色

"subject": "", // 主题

"num": 20, // 模板页数

"createTime": "2024-01-01 10:00:00"

}

],

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/randomTemplates' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"size":10, "filters": { "type": 1 }}'

封面图片资源访问,需要在 url 上拼接 ?token=xxx

生成 PPT

POST /api/ppt/generatePptx

参数

 

{

"templateId": "xxx", // 模板ID(非必填)

"pptxProperty": false, // 是否返回PPT数据结构

"outlineContentMarkdown": "# 主题\n## 章节\n### 页面标题\n#### 内容标题\n- 内容" // 大纲内容markdown

}

响应

 

{

"code": 0,

"data": {

"pptInfo": {

// ppt信息

"id": "xxx", // ppt id

"subject": "xxx", // 主题

"coverUrl": "https://xxx.png", // 封面

"templateId": "xxx", // 模板ID

"pptxProperty": "xxx", // PPT数据结构(json 数据通过 gzip 压缩 base64 编码返回,具体解码和数据结构请见【PPT前端渲染】部分讲解)

"userId": "xxx", // 用户ID

"userName": "xxx", // 用户名称

"companyId": 1000,

"updateTime": null,

"createTime": "2024-01-01 10:00:00"

}

},

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/generatePptx' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"outlineContentMarkdown": "xxx", "pptxProperty": false}'

直接生成PPT

POST /api/ppt/directGeneratePptx

参数

 

{

"stream": false, // 是否流式生成

"templateId": "xxx", // 模板ID(非必填)

"pptxProperty": false, // 是否返回PPT数据结构

// 方式一:通过主题创建

"subject": "xxx", // 主题

"prompt": null, // 用户要求

// 方式二:通过文件内容创建

"dataUrl": "https://xxx" // 数据url

}

非流式-响应(application/json)

 

{

"code": 0,

"data": {

"pptInfo": {

// ppt信息

"id": "xxx", // ppt id

"subject": "xxx", // 主题

"coverUrl": "https://xxx.png", // 封面

"fileUrl": "https://xxx.pptx", // PPT文件

"templateId": "xxx", // 模板ID

"pptxProperty": "xxx", // PPT数据结构(json 数据通过 gzip 压缩 base64 编码返回,具体解码和数据结构请见【PPT前端渲染】部分讲解)

"userId": "xxx", // 用户ID

"userName": "xxx", // 用户名称

"companyId": 1000,

"updateTime": null,

"createTime": "2024-01-01 10:00:00"

}

},

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/directGeneratePptx' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"stream": false, "subject": "AI未来的发展", "pptxProperty": false}'

流式-响应(event-stream)

 

{

"text": "",

"status": 3 // 状态:-1异常 1解析文件 3生成中 4完成

}

{ "text": "#", "status": 3 }

{ "text": " ", "status": 3 }

{ "text": "主题", "status": 3 }

...

{ "text": "", "status": 3, "pptId": "xxx" }

{

"text": "",

"status": 4,

"result": {

// ppt信息

"id": "xxx", // ppt id

"subject": "xxx", // 主题

"coverUrl": "https://xxx.png", // 封面

"fileUrl": "https://xxx.pptx", // PPT文件

"templateId": "xxx", // 模板ID

"pptxProperty": "xxx", // PPT数据结构(json 数据通过 gzip 压缩 base64 编码返回,具体解码和数据结构请见【PPT前端渲染】部分讲解)

"userId": "xxx", // 用户ID

"userName": "xxx", // 用户名称

"companyId": 1000,

"updateTime": null,

"createTime": "2024-01-01 10:00:00"

}

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/directGeneratePptx' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"stream": true, "subject": "AI未来的发展", "pptxProperty": false}'

获取 PPT 列表

POST /api/ppt/listPptx

参数

 

{

"page": 1,

"size": 10,

"filters": {

// 可根据字段过滤

}

}

响应

 

{

"code": 0,

"total": 1,

"data": [

{

"id": "xxx", // ppt id

"subject": "xxx", // 主题

"coverUrl": "https://xxx.png", // 封面

"templateId": "xxx", // 模板ID

"userId": "xxx", // 用户ID

"userName": "xxx", // 用户名称

"companyId": 1000,

"updateTime": null,

"createTime": "2024-01-01 10:00:00"

}

],

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/listPptx' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"page": 1, "size": 10}'

加载 PPT 数据

GET /api/ppt/loadPptx?id=

响应

 

{

"code": 0,

"data": {

"pptInfo": {

// ppt信息

// 数据同 generatePptx 生成PPT 接口结构...

}

},

"message": "操作成功"

}

请求示例

 

curl -X GET --location 'https://docmee.cn/api/ppt/loadPptx?id=xxx' \

--header 'token: {token}'

下载 PPT

POST /api/ppt/downloadPptx

请求

 

{

"id": "xxx"

}

响应

 

{

"code": 0,

"data": {

"id": "xxx",

"name": "xxx",

"subject": "xxx",

"fileUrl": "https://xxx" // 文件链接(有效期:2小时)

},

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/downloadPptx' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"id":"xxx"}'

更换 PPT 模板

POST /api/ppt/updatePptTemplate

参数

 

{

"pptId": "xxx", // ppt id

"templateId": "xxx", // 模板ID

"sync": false // 是否同步更新PPT文件(默认 false 异步更新,速度快)

}

响应

 

{

"code": 0,

"data": {

"pptId": "xxx",

"templateId": "xxx",

"pptxProperty": { // 更换后的pptx结构数据(json)

// ...

}

}

}

更新 PPT 属性

POST /api/ppt/updatePptxAttr

参数

 

{

"id": "xxx",

// 下面字段不能为空则修改

"name": null,

"subject": null

}

响应

 

{

"code": 0,

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/updatePptxAttr' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"id":"xxx","name":"xxx"}'

保存 PPT

POST /api/ppt/savePptx

参数

 

{

"id": "xxx", // ppt id

"drawPptx": true, // 是否重新渲染PPT文件并上传

"drawCover": true, // 是否重新渲染PPT封面并上传

"pptxProperty": {

// 修改过后的 pptx 页面数据结构树

}

}

响应

 

{

"code": 0,

"data": {

"pptInfo": {

// ppt信息

// 数据同 generatePptx 生成PPT 接口结构...

}

},

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/savePptx' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"id":"xxx","drawPptx":true,"drawCover":true,"pptxProperty":{}}'

删除 PPT

POST /api/ppt/delete

参数

 

{

"id": "xxx" // ppt id

}

响应

 

{

"code": 0,

"message": "操作成功"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/delete' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"id":"xxx"}'

AI PPT (异步)

Ai 异步流式生成 PPT,只需在调用生成大纲接口后调用下面的 generateContent 接口即可生成PPT,无需再次调用生成PPT接口

生成大纲内容同时异步生成PPT

POST /api/ppt/generateContent

参数

 

{

"templateId": "xxx", // 模板ID(非必填)

"outlineMarkdown": "# 主题\n## 章节\n### 页面标题\n#### 内容标题", // 大纲 markdown 文本

"asyncGenPptx": true, // 异步生成PPT(这里必须为 true 才会流式生成)

"prompt": null, // 用户要求

"dataUrl": null // 数据url

}

响应 event-stream 流式生成

 

{

"text": "",

"status": 3, // 状态:-1异常 0模型重置 1解析文件 2搜索网页 3生成中 4完成

// 下面为异步生成PPT时返回的数据,可以每出现一次就调用 asyncPptInfo 接口获取最新的PPT数据

"pptId": "xxx", // 异步生成pptId

"total": 23, // 总页数

"current": 1 // 当前已生成页数

}

{ "text": "#", "status": 3 }

{ "text": " ", "status": 3 }

{ "text": "主题", "status": 3 }

...

{

"text": "",

"status": 4,

"result": {

"level": 1,

"name": "主题",

"children": [

{

"level": 2,

"name": "章节",

"children": [

{

"level": 3,

"name": "页面标题",

"children": [

{

"level": 4,

"name": "内容标题",

"children": [

{

"level": 0,

"name": "内容"

}

]

}

]

}

]

}

]

}

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/ppt/generateContent' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"outlineMarkdown":"xxx","asyncGenPptx":true}'

查询异步生成PPT信息

说明:该接口不需要轮询,在 generateContent 接口流式返回 pptId 数据时调用,每出现一次 pptId 就调用一次获取最新的 PPT 信息

GET /api/ppt/asyncPptInfo?pptId=

参数

​ pptId 为 generateContent 接口流式返回的pptId

响应

 

{

"code": 0,

"data": {

"total": 23, // 总页数

"current": 1, // 当前已生成页数

"pptxProperty": "xxx" // PPT数据结构(json gzip base64)

}

}

请求示例

 

curl -X GET --location 'https://docmee.cn/api/ppt/asyncPptInfo?pptId=xxx' \

--header 'token: {token}'

JSON

ppt转json

POST /api/pptjson/ppt2json

form/data

请求参数

参数类型说明
fileFilePPTX 文件(必传)
uploadImageboolean图片是否上传到服务器,false 时返回base64图片数据

响应

 

{

"width": 960,

"height": 540,

"pages": [], // 页面结构数据

"font": [], // 字体数据

"slideMasters": [], // 母版结构数据

"version": "1.0"

}

请求示例

 

curl -X POST --location 'https://docmee.cn/api/pptjson/ppt2json' \

--header 'Content-Type: multipart/form-data' \

--header 'token: {token}' \

--form 'file=@test.pptx' \

--form 'uploadImage=false'

json转ppt

POST /api/pptjson/json2ppt

请求参数

 

{

"width": 960,

"height": 540,

"pages": [], // 页面结构数据

"font": [], // 字体数据

"slideMasters": [], // 母版结构数据

"version": "1.0"

}

响应(文件流) application/octet-stream

请求示例

 

curl -X POST --location 'https://docmee.cn/api/pptjson/json2ppt' \

--header 'Content-Type: application/json' \

--header 'token: {token}' \

--data '{"width":960,"height":540,"pages": [],"font": [],"slideMasters": [],"version": "1.0"}'

PPT 前端渲染

渲染说明

关于 ppt 数据结构在前端渲染问题,我们已经把前端代码开源到 github:

GitHub - veasion/aippt: AI 智能生成 PPT,PPT 解析为 JSON,JSON 反渲染为 PPT,商用级 AiPPT 项目,可在线体验

GitHub - veasion/aippt-vue: vue for aippt demo

GitHub - veasion/aippt-react: react for aippt demo

关于上面 pptxProperty 数据解码,为了减少带宽占用,我们在服务端对 pptxProperty 做了压缩和编码(json 字符串数据通过 gzip 压缩 base64 编码),通过 js 解码:

 

// 依赖js库

// https://github.com/veasion/aippt/blob/main/static/base64js.js

// https://github.com/veasion/aippt/blob/main/static/pako.js

let pptxProperty = 'xxx'

let gzip = base64js.toByteArray(pptxProperty)

let json_str = pako.ungzip(gzip, { to: 'string' })

let pptxObj = JSON.parse(json)

数据结构说明

pptxProperty 解压后的 json 数据结构简易说明

 

{

"width": 960, // PPT宽度

"height": 540, // PPT高度

"font": [ // 嵌入字体

{

"typeface": "HarmonyOS Sans", // 字体

"eotUrl": "https://xxx.eot" // embedding open type font

}

],

"version": "1.0",

"slideMasters": [ // PPT母版&版式(包含主题、版式等)

{

"background": { // 母版背景

"strokeStyle": {},

"realType": "Background",

"anchor": [0, 0, 960, 540], // x,y,width,height

"fillStyle": { // 填充方式

"type": "color", // 类型:color/gradient/texture/pattern/groupFill/bgFill/noFill

"color": {

"color": -1, // 颜色(32bit ARGB) color = (A & 255) << 24 | (R & 255) << 16 | (G & 255) << 8 | (B & 255) << 0, R => (color >> 16) & 255

"realColor": -1 // 真实颜色(根据hsv等偏移计算的真实颜色)

}

}

},

"theme": { // 母版主题

"name": "Office 主题", // 主题名称

"colors": { // 主题颜色

"accent1": -12291388, // 主题颜色1

"accent2": -1213135, // 主题颜色2...

"accent3": -5921371,

"accent4": -16384,

"accent5": -10773547,

"accent6": -9392825,

"lt1": -1,

"dk2": -12299158,

"dk1": -16777216,

"lt2": -1579290,

"hlink": -16423999,

"folHlink": -6992014

},

"font": { // 字体

"majorFont": [ // 主要字体

"等线 Light",

"",

""

],

"minorFont": [ // 次要字体

"等线",

"",

""

]

}

},

"children": [], // 元素树(数据结构跟page中的children一致)

"slideLayouts": [ // 母版版式

{

"type": "CUST",

"name": "标题幻灯片",

"children": [], // 元素树(数据结构跟page中的children一致)

"background": {

"strokeStyle": {},

"realType": "Background",

"anchor": [0, 0, 960, 540],

"fillStyle": {

"color": {

"color": -1,

"realColor": -1

},

"type": "color"

}

}

}

]

}

],

"pages": [ // PPT页面结构

{

"page": 1, // 第几页

"extInfo": { // 数据信息

"slideMasterIdx": 0, // 对应母版下标

"slideLayoutIdx": 0, // 对应母版下的版式下标

"notes": "这是一个备注", // PPT页面备注

"background": { // 背景

"strokeStyle": {},

"realType": "Background",

"anchor": [0, 0, 960, 540], // x,y,width,height

"fillStyle": { // 填充样式

"type": "color", // color/gradient/texture/pattern/groupFill/bgFill/noFill

"color": { // 颜色

"scheme": "accent1", // 对应主题色

"color": -12291388, // 颜色(32bit ARGB) color = (A & 255) << 24 | (R & 255) << 16 | (G & 255) << 8 | (B & 255) << 0, R => (color >> 16) & 255

"realColor": -12291388 // 真实颜色(32bit ARGB)

}

}

}

},

"children": [ // 元素结构树

{

"id": "1", // id

"type": "text", // 类型:text/freeform/image/container/diagram/connector/table/graphicFrame

"point": [397.09094488188978, 124.36362204724409, 87.24377952755906, 29.081259842519687], // 真实位置(根据缩放偏移等数据计算过的真实位置)[x,y,width,height]

"depth": 1, // 深度

"extInfo": { // 扩展信息

"property": { // 属性

"realType": "TextBox", // 真实类型

"textDirection": "HORIZONTAL", // 文本方向 => HORIZONTAL,VERTICAL,EA_VERTICAL,VERTICAL_270,STACKED

"shapeType": "rect",

"textWordWrap": false, // 是否自动换行

"anchor": [397.09094488188978, 124.36362204724409, 87.24377952755906, 29.081259842519687], // 相对位置 [x,y,width,height]

"textVerticalAlignment": "TOP", // 文本垂直对齐 => TOP,MIDDLE,BOTTOM,JUSTIFIED,DISTRIBUTED

"fillStyle": { // 填充

"type": "color",

"color": {

"scheme": "accent6", // 对应主题色

"color": -9392825, // 颜色(32bit ARGB) color = (A & 255) << 24 | (R & 255) << 16 | (G & 255) << 8 | (B & 255) << 0, R => (color >> 16) & 255

"realColor": -9392825 // 真实颜色(32bit ARGB)

}

},

"geometry": { // 行状

"name": "rect", // 形状,custom 为自定义形状,其他都为系统预置形状

"data": null, // custom 自定义形状 paths 数据

"avLst": null // 调整参数

},

"textAutofit": "SHAPE",

"textInsets": [3.6, 7.2, 3.6, 7.2] // 文本形状调整边距 [top,left,bottom,right]

}

},

"children": [ // 子元素结构树

{

"id": "2", // id

"pid": "1", // pid

"type": "p", // 类型:text 下为 p 段落,p 段落下为 r 字符

"extInfo": {

"property": {

"textAlign": "LEFT", // 段落文本对齐 LEFT,CENTER,RIGHT,JUSTIFY,JUSTIFY_LOW,DIST,THAI_DIST

"fontAlign": null, // 字体对齐 AUTO,TOP,CENTER,BASELINE,BOTTOM

"indent": 0, // 缩进

"bullet": null, // 项目符合

"bulletStyle": null, // 项目符合样式

"leftMargin": null, // 左边距

"rightMargin": null, // 右边距

"lineSpacing": null, // 段落-间距-行距:1.5倍行距为 150, 2倍行距为 200

"spaceBefore": null, // 段落-间距-段前:文本段落之前的行距

"spaceAfter": null // 段落-间距-段后:文本段落之后的行距

}

},

"depth": 2,

"children": [

{

"id": "3",

"pid": "2",

"type": "r", // 类型 r 字符

"text": "文本数据", // 文本数据

"depth": 3,

"extInfo": {

"property": {

"fontSize": 18, // 字体大小

"lang": "zh-CN",

"fontColor": { // 字体颜色填充,结构同 fillStyle

"type": "color", // color/gradient/texture/pattern/groupFill/bgFill/noFill

"color": {

"scheme": null, // 主题色

"color": -16777216, // 颜色(32bit ARGB) color = (A & 255) << 24 | (R & 255) << 16 | (G & 255) << 8 | (B & 255) << 0, R => (color >> 16) & 255

"realColor": -16777216, // 真正颜色(计算后的颜色)

"alpha": null, // 透明度,alpha / 100000.0 * 255

"hueMod": null, // hsv 色相

"hueOff": null, // 偏移

"satMod": null, // hsv 饱和度

"satOff": null, // 偏移

"lumMod": null, // hsv 亮度 lumMod / 100000 => 85000=0.85; 95000=0.95; 50000=0.5

"lumOff": null, // 偏移

"shade": null,

"tint": null

}

}

}

},

"xpath": "//shapes[0]/text/p/r"

}

],

"xpath": "//shapes[0]/text/p"

}

],

"xpath": "//shapes[0]/text"

},

{

"id": "4",

"type": "text",

"point": [267.6364566929134, 240.72732283464567, 98.15283464566929, 98.90913385826772],

"depth": 1,

"extInfo": {

"property": {

"strokeStyle": { // 线条样式

"lineCap": "FLAT",

"lineDash": "SOLID",

"lineCompound": "SINGLE",

"lineWidth": 1, // 线条宽度

"paint": { // 画笔样式,结构同 fillStyle

"type": "color",

"color": {

"scheme": "accent1",

"color": -12291388,

"shade": 15000,

"realColor": -15258543

}

}

},

"realType": "Auto",

"textDirection": "HORIZONTAL",

"shapeType": "triangle",

"anchor": [267.6364566929134, 240.72732283464567, 98.15283464566929, 98.90913385826772],

"textVerticalAlignment": "MIDDLE",

"fillStyle": {

"color": {

"scheme": "accent2",

"color": -1213135,

"realColor": -1213135

},

"type": "color"

},

"geometry": {

"name": "triangle"

},

"textAutofit": "NORMAL",

"textInsets": [3.6, 7.2, 3.6, 7.2]

}

},

"children": [

{

"pid": "4",

"id": "5",

"text": "",

"type": "p",

"extInfo": {

"property": {

"leftMargin": 0,

"textAlign": "CENTER"

}

},

"depth": 2,

"children": [],

"xpath": "//shapes[1]/text/p"

}

],

"xpath": "//shapes[1]/text"

},

{

"id": "6",

"type": "image", // 图片

"point": [ 535.9091338582678, 238.72732283464567, 127.36362204724409, 127.36362204724409],

"depth": 1,

"extInfo": {

"property": {

"image": "data:image/jpeg;base64,xxx", // 图片数据 url/base64

"fileName": "image1.jpg", // 图片文件名

"extension": ".jpg", // 图片文件后缀

"realType": "Picture",

"shapeType": "rect",

"anchor": [535.9091338582678,238.72732283464567,127.36362204724409,127.36362204724409], // 相对位置 [x,y,width,height]

"fillStyle": { // 填充

"type": "texture", // 类型:蒙版填充

"texture": { // 蒙版

"insets": [0, 0, 0, 0], // 图片裁剪 [top,left,bottom,right]

"stretch": [0, 0, 0, 0], // 图片拉伸 [top,left,bottom,right]

"flipMode": "NONE", // X,Y,XY,NONE

"imageData": "data:image/jpeg;base64,xxx", // 蒙版图片数据,在image类型中数据等于 extInfo.property.image 图片数据

"alpha": 100000, // 透明度 => alpha / 100000

"contentType": "image/jpeg", // 图片内容类型

"alignment": null // TOP/TOP_LEFT/TOP_RIGHT/LEFT/BOTTOM/BOTTOM_LEFT/BOTTOM_RIGHT/RIGHT/CENTER

}

},

"geometry": {

"name": "rect"

},

"contentType": "image/jpeg"

}

},

"children": [],

"xpath": "//shapes[2]/image"

}

]

}

]

}

颜色填充说明

形状填充 fillStyle 和 线条画笔 paint 、文字 fontColor 都是同样填充数据结构

  • 无填充

     

    {

    "type": "noFill"

    }

  • 颜色填充

     

    {

    "type": "color",

    "color": {

    "scheme": null, // 主题色,对应母版主题颜色中的 accent1/accent2/...

    "color": -16777216, // 颜色(32bit ARGB) color = (A & 255) << 24 | (R & 255) << 16 | (G & 255) << 8 | (B & 255) << 0, R => (color >> 16) & 255

    "realColor": -16777216, // 真正颜色(计算后的颜色)

    "alpha": null, // 透明度,alpha / 100000.0 * 255

    "hueMod": null, // hsv 色相

    "hueOff": null, // 偏移

    "satMod": null, // hsv 饱和度

    "satOff": null, // 偏移

    "lumMod": null, // hsv 亮度 lumMod / 100000 => 85000=0.85; 95000=0.95; 50000=0.5

    "lumOff": null, // 偏移

    "shade": null,

    "tint": null

    }

    }

    注意:上面颜色渲染是用 realColor 字段即可,修改也是改 realColor 字段,同时把其他字段设置为 null

    颜色是按位或计算得出来的整数类型,转换方式如下:

    int32 颜色转 rgba 前端颜色:

     

    let color = -16777216 // ARGB

    let r = (color >> 16) & 255 // 红 0-255

    let g = (color >> 8) & 255 // 绿 0-255

    let b = (color >> 0) & 255 // 蓝 0-255

    let a = ((color >> 24) & 255) / 255 // 透明度 0-255 转小数 0-1

    let rgba = `rgba(${r}, ${g}, ${b}, ${a})`

    rgba转int32

     

    let r = 255

    let g = 255

    let b = 255

    let a = 255

    let color = (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0

  • 渐变颜色

     

    {

    "type": "gradient",

    "gradient": {

    "gradientType": "linear", // 类型:linear,circular,rectangular,shape

    "colors": [ // 渐变颜色 color-stop

    {

    "type": "color",

    "color": {

    "scheme": null, // 主题色

    "color": -16777216, // 颜色(32bit ARGB)

    "realColor": -16777216 // 真正颜色(计算后的颜色)

    }

    },

    {

    "type": "color",

    "color": {

    "scheme": null, // 主题色

    "color": -14787035, // 颜色(32bit ARGB)

    "realColor": -14787035 // 真正颜色(计算后的颜色)

    }

    }

    ],

    "fractions": [0.5, 0.5], // offset比例 0-1

    "angle": null, // 角度(确定方向)

    "insets": null // 射线中所在访问占比 [1,0.5,0.5,1]

    }

    }

  • 图案

     

    {

    "type": "pattern",

    "pattern": {

    "prst": "vert", // 预置图案类型

    "bgColor": { // 背景色

    "type": "color",

    "color": {

    "scheme": null,

    "color": -16777216,

    "realColor": -16777216

    }

    },

    "fgColor": { // 前景色

    "type": "color",

    "color": {

    "scheme": null,

    "color": -14787035,

    "realColor": -14787035

    }

    }

    }

    }

  • 容器颜色

     

    {

    "type": "groupFill" // 使用父元素容器 container 中的 groupFillStyle 颜色进行填充

    }

  • 背景颜色

     

    {

    "type": "bgFill" // 使用背景颜色填充

    }

容器嵌套说明

容器 container 嵌套后子元素中的位置使用的是相对位置,偏移和缩放取决于父容器中的 interiorAnchor 属性

容器对象结构属性示例:

 

{

"anchor": [10, 20, 100, 200], // 容器位置 [x,y,width,height]

"interiorAnchor": [5, 10, 200, 400], // 内部位置 [x,y,width,height]

"flipHorizontal": false, // 水平翻转

"flipVertical": false, // 垂直翻转

"rotation": 0, // 旋转角度

"groupFillStyle": null // 容器填充颜色,给子元素 groupFill 用

}

子元素位置计算方式

 

// scaleX = anchor[2] / interiorAnchor[2]

// scaleY = anchor[3] / interiorAnchor[3]

// 元素真实x = 元素x * scaleX + 容器x - 容器内部偏移x * scaleX

// 元素真实y = 元素y * scaleY + 容器y - 容器内部偏移y * scaleY

// 元素真实w = 元素w * scaleX

// 元素真实h = 元素h * scaleY

最后更新时间:2024/8/1 11:58

  • 16
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值