# wx.openDocument(Object object)

> __以 [Promise 风格](/miniprogram/dev/framework/app-service/api.md#异步-API-返回-Promise) 调用__：支持
> 
> __小程序插件__：支持，需要小程序基础库版本不低于 [2.15.0](1003706)
> 
> __微信 Windows 版__：支持
> 
> __微信 Mac 版__：支持
> 
> __微信 鸿蒙 OS 版__：支持

> 相关文档: [文件系统](/miniprogram/dev/framework/ability/file-system.md)

## 功能描述

新开页面打开文档。微信客户端 `7.0.12` 版本前默认显示右上角菜单按钮，之后的版本默认不显示，需主动传入 `showMenu`。

## 参数

### Object object


```json
[
  {
    "属性": "filePath",
    "类型": "string",
    "默认值": "",
    "必填": "是",
    "说明": "文件路径 (本地路径) ，可通过 downloadFile 获得",
    "最低版本": ""
  },
  {
    "属性": "showMenu",
    "类型": "boolean",
    "默认值": "false",
    "必填": "否",
    "说明": "是否显示右上角菜单",
    "最低版本": "[2.11.0](1003706)"
  },
  {
    "属性": "fileType",
    "类型": "string",
    "默认值": "",
    "必填": "否",
    "说明": "文件类型，指定文件类型打开文件",
    "最低版本": "[1.4.0](1003706)",
    "子项": [
      {
        "合法值": "doc",
        "说明": "doc 格式"
      },
      {
        "合法值": "docx",
        "说明": "docx 格式"
      },
      {
        "合法值": "xls",
        "说明": "xls 格式"
      },
      {
        "合法值": "xlsx",
        "说明": "xlsx 格式"
      },
      {
        "合法值": "ppt",
        "说明": "ppt 格式"
      },
      {
        "合法值": "pptx",
        "说明": "pptx 格式"
      },
      {
        "合法值": "pdf",
        "说明": "pdf 格式"
      }
    ]
  },
  {
    "属性": "success",
    "类型": "function",
    "默认值": "",
    "必填": "否",
    "说明": "接口调用成功的回调函数",
    "最低版本": ""
  },
  {
    "属性": "fail",
    "类型": "function",
    "默认值": "",
    "必填": "否",
    "说明": "接口调用失败的回调函数",
    "最低版本": ""
  },
  {
    "属性": "complete",
    "类型": "function",
    "默认值": "",
    "必填": "否",
    "说明": "接口调用结束的回调函数（调用成功、失败都会执行）",
    "最低版本": ""
  }
]
```

## 示例代码

```javascript

wx.downloadFile({
  // 示例 url，并非真实存在
  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    const filePath = res.tempFilePath
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})

```
