跳到主要内容

文档内容操作

💡 调用API,需要认证。认证参考【接口认证

API接口

POST {apiPrefix}/content/update

提交文档内容操作任务

  • 任务添加失败,同步返回失败原因
  • 任务添加成功,同步返回任务ID。第三方可以配置任务回调通知获取任务状态。

请求体

Content-Type为application/json

参数名类型说明是否必须
fileUrlstring文件下载地址
filenamestring包含后缀的文件名,目前源文件类型支持doc/docx/wps/pdf
tokenTypestring三方token类型,值为cookie或者header
tokenValuestring三方token值,zOffice下载文件或回调通知时回传
callbackstring回调地址。任务结束后zOffice回调通知状态
ops数组对文档内容操作的有序操作数组,数组对象见下方op说明。支持的操作列表见【操作列表](#操作列表)】

请求体示例

{
"fileUrl": "http://{{thirdparty-demo}}/v2/context/local-PublicAPI-contentUpdate-clearDoc/content",
"filename": "demo-docx.docx",
"tokenType":"cookie",
"tokenValue":"zdocs_access_token={{zdocs_access_token}}",
"callback": "http://{{thirdparty-demo}}/v2/context/convert/callback",
"ops": [ {
"actId": "ClearDoc",
"options": {
"args": ["acceptAllTrack", "removeAllComment"]
}
}]

}

正常返回:

{
"taskId": "6f6598c8-c87e-420b-b6c4-6f1b187201dc",
"code": "Ok",
"detail": {
"taskStatus": "IN_QUEUE"
}
}

错误返回:

{
"taskId": "695fbf6e-90d2-42ba-83d5-00e81e5e366e",
"code": "TaskQueueCongestion",
"detail": {
"taskStatus": "FAIL"
}
}

操作列表

清稿

{
"actId": "ClearDoc",
"options": {
"args": ["acceptAllTrack", "removeAllComment"]
}
}

args数组表示清除文档对应的具体操作

  • acceptAllTrack表示接受所有修订记录
  • removeAllComment表示移除所有评论

支持docx/wps/doc,源文件最大300m,docx格式600m,最多1000页

args为空表示执行上述所有操作

书签内容替换

使用限制
  • 不允许ops中有多个UpdateBookmarkRef
  • UpdateBookmarkRef不允许和其他操作在同一次文档内容操作请求中传递
  • 支持格式doc/docx/wps,所有文件(包括源文件和引用文件)总和最大300m

使用说明

  • 模板文件下载地址在请求体fileUrl中传递

  • 模板文件名在请求体filename中传递,文件名需要带后缀

  • 书签替换内容在请求体ops中传递,结构如下

{
"actId": "UpdateBookmarkRef",
"options": {
"args": [
{
"bookname": "书签名",
"dataType": "书签引用类型",
"dataRef": "书签引用内容",
"refName": "书签引用内容名称"
}
]
}
}

options说明

选项名选项类型是否必须说明
argsBookmarkRef数组BookmarkRef 对象包含四个属性:
* bookname
* dataType
* dataRef
* refName
  • bookname: 书签名。书签名不存在时,对应替换会被忽略,但不会影响其他书签替换。
  • dataType: 书签引用类型。可选值TEXT,DOC,PIC。分别对应引用内容为字符串,文档,图片。
  • dataRef: 书签引用内容。
    • dataType为TEXT时,该值为字符串;
    • dataType为DOC或PIC时,该值为下载对应文件的URL。
  • refName: 书签引用名称。
    • dataType为TEXT时,该值可以省略;
    • dataType为DOC或PIC时,该值为dataRef对应带后缀的文件名,请确保文件后缀名正确,否则会导致套红结果不符预期。支持的格式:png/jpeg/doc/wps/docx

例子 - 多个书签替换

{
"actId": "UpdateBookmarkRef",
"options": {
"args": [
{
"bookname": "文件标题",
"dataType": "TEXT",
"dataRef": "zOffice PublicAPI 书签套用"
},
{
"bookname": "签名部门",
"dataType": "PIC",
"dataRef": "http://{{thirdparty-demo}}/v2/context/local-PublicAPI-contentUpdate-updateBkRef-pic/content",
"refName": "sign.png"
},
{
"bookname": "正文",
"dataType": "DOC",
"dataRef": "http://{{thirdparty-demo}}/v2/context/local-PublicAPI-contentUpdate-updateBkRef-body/content",
"refName": "body.docx"
},
{
"bookname": "尾注",
"dataType": "TEXT",
"dataRef": "科技改变生活",
"refName": ""
}
]
}
}

文档加位置文本水印

{
"actId": "ApplyWatermark",
"options": {
"text": "watermark for test",
"fontcolor": "#DC134C",
"fontsize": "70",
"font": "黑体",
"rotation": 315,
"transparent": 20,
"position": "BOTTOM_RIGHT"
}
}

支持类型:

源文件类型限制
docx/wps/doc/ofd源文件最大300m,docx格式600m,最多1000页

options说明位置文本水印

文档加位置图片水印

word 文件

{
"actId": "ApplyPicWatermark",
"options": {
"picUrl": "http://{{thirdparty-demo}}/v2/context/local-pic/content",
"picName": "pic.png",
"isErosion": false,
"rotation": 0,
"position": "CENTER",
"picScale": 100
}
}

pdf、ofd文件

不传入缩放比例的参数:picScale , 水印图片自适应页面

 {
"actId": "ApplyPicWatermark",
"options": {
"picUrl": "http://{{thirdparty-demo}}/v2/context/local-logo/content",
"picName": "local-logo.png",
"picScale": 100,
"transparent": 78,
"rotation": 0,
"position": "CENTER"
}
}

支持类型:

源文件类型限制
docx/wps/doc源文件最大300m,docx格式600m,最多1000页,水印图片最大支持50m
pdf/ofd源文件最大200m、最多1000页,水印图片最大支持50m

options说明位置图片水印

文档加平铺文本水印

{
"actId": "ApplyWatermarkForFixed",
"options": {
"line1": "watermark for test",
"withDate": true,
"font": "黑体",
"fontcolor": "#DC134C",
"fontsize": "70",
"transparent": 70,
"rotation": 315,
"spacing": 50
}
}

支持类型:

源文件类型限制
pdf/ofd源文件最大200m,最多1000页

options说明平铺文本水印

文档加平铺图片水印

{
"actId": "ApplyTiledImgWatermarkForFixed",
"options": {
"picUrl": "http://{{thirdparty-demo}}/v2/context/local-png/content",
"picName": "filez.png",
"picScale": 100,
"rotation": 315,
"transparent": 70,
"spacing": 80
}
}

支持类型:

源文件类型限制
ofd源文件最大200m,最多1000页

options说明平铺图片水印