【在线文档预览】在项目中加入下面的代码:

var fileUrl = 'https://view.56wenku.cn/demo/test.docx'; //要预览文件的访问地址
window.open('https://view.56wenku.cn/online?format=html&url='+fileUrl);


【在线文档水印】通过传一个参数watermarkTxt,参数值为文字,示例如下

var fileUrl = 'https://view.56wenku.cn/demo/test.docx'; //要预览文件的访问地址
window.open('https://view.56wenku.cn/online?format=html&url='+fileUrl+'&watermarkTxt=智享文库文档在线预览');

【文档预览页数】通过传一个参数limit限制,参数值为数字,示例如下

var fileUrl = 'https://view.56wenku.cn/demo/test.docx'; //要预览文件的访问地址
window.open('https://view.56wenku.cn/online?format=html&url='+fileUrl+'&limit=1');

接口调用

接口地址:https://view.56wenku.cn/online

请求方式:GET/POST

请求参数:

参数名 参数类型 是否必须 参数说明
url String http/https文档地址支持:doc、docx、xls、xlsx、ppt、pptx、pdf、ofd、zip、rar、txt、图片等格式。
format String 返回结果格式,可选值:json、html,默认json
limit int office文档控制预览页数,对pdf/doc/docx/ppt/pptx有效
watermarkTxt String 水印文本,显示文本水印

返回结果

当参数format=json时返回如下结果,返回示例:

{
    "code":0,
    "success":true,
    "msg":"success",
    "content":"https://view.56wenku.cn/view?url=aHR0cHM6Ly92aWV3LnpoaXBhbGwuY24vZGVtby90ZXN0LmRvY3g%3D&limit=2&watermarkTxt=watermark"

}

参数名 参数类型 参数说明
code int 返回码,0表示成功,非0表示失败
success bool 业务状态,true成功
msg String 返回信息
content String 返回预览地址