title: Taro.openDocument(option)

sidebar_label: openDocument

Opens a file in a new page.

Reference

Type

  1. (option: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
filePath string Yes File path, which can be obtained via downloadFile
fileType "doc" | "docx" | "xls" | "xlsx" | "ppt" | "pptx" | "pdf" No File type in which the file is opened
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

fileType

Valid values of object.fileType

Property Description
doc doc format
docx docx format
xls xls format
xlsx xlsx format
ppt ppt format
pptx pptx format
pdf pdf format

Sample Code

  1. Taro.downloadFile({
  2. url: 'https://example.com/somefile.pdf',
  3. success: function (res) {
  4. var filePath = res.tempFilePath
  5. Taro.openDocument({
  6. filePath: filePath,
  7. success: function (res) {
  8. console.log('File opened successfully')
  9. }
  10. })
  11. }
  12. })

API Support

API WeChat Mini-Program H5 React Native
Taro.openDocument ✔️