Skip to content

新版打印组件(version>1.0.0)print 接口

返回的响应doc 维度

render完成

{
  "cmd":"notifyDocResult",
  "requestID":"xxx",
  "status":"rendered",
  "printer":"xx",
  "taskId":"xx"
	"documentId":"123",
	"code":0,
	"detail":"描述信息/错误描述"
}
{
  "cmd":"notifyDocResult",
  "requestID":"xxx",
  "status":"rendered",
  "printer":"xx",
  "taskId":"xx"
	"documentId":"123",
	"code":0,
	"detail":"描述信息/错误描述"
}
字段可选值描述
cmdnotifyDocResultdoc 阶段的通知
statusrendered渲染完成
printer进行处理的打印机名
taskId请求数据中的taskId
documentId该数据对应的 doc
code0 为成功,其他为失败
detail描述信息
requestID标志这次通知对应的请求

print完成

如果 render 阶段就失败了,那么就不会进入到 printed 阶段

{
  "cmd":"notifyDocResult",
  "requestID":"xxx",
  "status":"printed",
  "printer":"xx",
  "taskId":"xx"
	"documentId":"123",
	"code":0,
	"detail":"描述信息/错误描述",
  "spendTime":{
    "downloading":351,
    "rendering":470,
    "pending":1,
    "total":100
  }
}
{
  "cmd":"notifyDocResult",
  "requestID":"xxx",
  "status":"printed",
  "printer":"xx",
  "taskId":"xx"
	"documentId":"123",
	"code":0,
	"detail":"描述信息/错误描述",
  "spendTime":{
    "downloading":351,
    "rendering":470,
    "pending":1,
    "total":100
  }
}

相对于render完成阶段status为 printed,并且增加了下面的部分

"spendTime":{
  "downloading":351,
  "rendering":470,
  "pending":1,
  "total":100
}
"spendTime":{
  "downloading":351,
  "rendering":470,
  "pending":1,
  "total":100
}
字段可选值描述
downloading下载资源的用时,单位ms
renderingrender 用时,单位ms
pendingpending 用时,单位 ms
total总用时,上述各个阶段的总和

返回的响应task 维度

任务成功提交

{
  "cmd":"notifyTaskResult",
  "requestID":"xxx",
  "status":"initial",
  "printer":"xx",
  "taskId":"xx"
}
{
  "cmd":"notifyTaskResult",
  "requestID":"xxx",
  "status":"initial",
  "printer":"xx",
  "taskId":"xx"
}
字段可选值描述
cmdnotifyTaskResult任务的通知信息
statusinitial/running/partialSuccess/completeSuccess/completeFailure初始化/执行中/部分成功/完全成功/完全失败

任务开始

{
  "cmd":"notifyTaskResult",
  "requestID":"xxx",
  "status":"running",
  "printer":"xx",
  "taskId":"xx"
}
{
  "cmd":"notifyTaskResult",
  "requestID":"xxx",
  "status":"running",
  "printer":"xx",
  "taskId":"xx"
}

任务完成

{
  "cmd":"notifyTaskResult",
  "requestID":"xxx",
  "status":"printed",
  "printer":"xx",
  "taskId":"xx"
  "spendTime":{
    "downloading":351,
    "rendering":470,
    "pending":1,
    "total":100
  }
}
{
  "cmd":"notifyTaskResult",
  "requestID":"xxx",
  "status":"printed",
  "printer":"xx",
  "taskId":"xx"
  "spendTime":{
    "downloading":351,
    "rendering":470,
    "pending":1,
    "total":100
  }
}

整体流程

graph TD
t1[在组件中成功提交打印任务]-->t2[任务提交通知]
t2--一段时间后-->t3[打印机开始执行任务]
t3-->tt[任务进行中阶段开始的通知]
tt-->t4[doc 开始 render 阶段]
subgraph 遍历 doc
t4-->t5[doc render 阶段完成]
t5-->t6[doc rendered 通知]
t6-->t7[doc 开始 print 阶段]
t7-->t8[doc 完成 print 阶段]
t8-->t9[doc printed 通知]
end
t9-->t10[doc 遍历结束]
t10-->t11[task 完成通知]
graph TD
t1[在组件中成功提交打印任务]-->t2[任务提交通知]
t2--一段时间后-->t3[打印机开始执行任务]
t3-->tt[任务进行中阶段开始的通知]
tt-->t4[doc 开始 render 阶段]
subgraph 遍历 doc
t4-->t5[doc render 阶段完成]
t5-->t6[doc rendered 通知]
t6-->t7[doc 开始 print 阶段]
t7-->t8[doc 完成 print 阶段]
t8-->t9[doc printed 通知]
end
t9-->t10[doc 遍历结束]
t10-->t11[task 完成通知]

preview

preview 通知

由于增加了 oneDocOneTask 功能,preview 的通知内容有所更改

{
	"cmd": "print",
	"taskID": "TASK_1616574131744",
	"status": 0,
	"msg": "no error",
	"responses": [{
		"documentId": "10000001",
		"urls": ["https://localhost:13529/file/20210324_042212_695_0_0.pdf"]
	}]
}
{
	"cmd": "print",
	"taskID": "TASK_1616574131744",
	"status": 0,
	"msg": "no error",
	"responses": [{
		"documentId": "10000001",
		"urls": ["https://localhost:13529/file/20210324_042212_695_0_0.pdf"]
	}]
}

urls 字段为数组,数组元素为 k:v 对,k 为 documentId,而 v则为该 doc 对应的文件组,例如 pdf 一般来说只有一个链接,而图片则是每一页一个链接.

该通知的返回时机为 print 阶段.

preview 新增功能

图片色彩

在print 命令中存在 printingConfig字段,该字段中可以使用imageColorMode来决定当预览类型是图片时的图片色彩类型,如下表所示

色彩类型
1RGB
2ARGB
4BGR
6ABGR
10GRAY
12BINARY

图片缩放

使用 scala 可以对预览的图形进行缩放,该缩放将影响图像的分辨率,简单来说 scala 越大,则图像文件越大,尺寸越大.见示例.

示例

{
	"cmd": "print",
	"task": {
		"printer": "",
		"printingConfig": {
			"scala": 3.0,
			"imageColorMode": 1
		},
		"documents": []
	}
}
{
	"cmd": "print",
	"task": {
		"printer": "",
		"printingConfig": {
			"scala": 3.0,
			"imageColorMode": 1
		},
		"documents": []
	}
}

注意点

通知的回复是异步的,不保证回复到达的顺序,由 ws 的实现决定.