my.openDocument
The my.openDocument API enables users to preview a PDF file within the mini program.
Supported types of mini programs: DSL, H5+
After clicking on the PDF file, the user can preview the file without leaving the mini program. After closing the preview, the user will still be at the current mini program page.
Sample code
my.downloadFile({
url: "https://gw.alipayobjects.com/os/basement_prod/0155bfea-000c-4e5b-a306-d90ef272dd46.pdf",
success: (res) => {
my.openDocument({
filePath: res.apFilePath,
fileType: "pdf",
success: (res) => {
console.log(res);
},
fail(res) {
console.log(err);
}
});
}
});Parameters
Object type
Property | Type | Required | Description |
filePath | String | Yes | Obtain the file path via the my.downloadFile JSAPI. By passing the The length is limited to 70 characters. |
fileType | String | Yes | File type. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
Legal values for fileType
Value | Description |
| PDF format. |
Error code
Error code | Description | Solution |
| 4011 | File path is invalid or no permission to access incoming path. | Check the incoming file path. |
| 4012 | Preview files do not exist. | Make sure files that correspond to file path exist. |
| 4013 | File format is not supported. | Currently preview of PDF files is supported. |