HarmonyOS 使用filePreview打开文件问题

let uiContext = getContext(this);
let displayInfo: filePreview.DisplayInfo = {
  x: 100,
  y: 100,
  width: 800,
  height: 800
};
let fileInfo: filePreview.PreviewInfo = {
  title: '1.txt',
  uri: 'file://docs/storage/Users/currentUser/Documents/2.pdf',
  mimeType: 'application/pdf'
};
filePreview.openPreview(uiContext, fileInfo, displayInfo).then(() => {
  console.info('Succeeded in openPreview');
}).catch((err: BusinessError) => {
  console.error(`Failed to openPreview, err.code = ${err.code}, err.message = ${err.message}`);
});

如上代码,使用filePreview来预览代码项目rawfile目录中的2.pdf文件,其中fileInfo中的uri怎么填写?

HarmonyOS
2024-12-25 17:57:21
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

filePreview不支持预览pdf格式的文件,pdf格式需要使用PDF kit。https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/pdf-pdfview-implements-V5其中uri为沙箱文件的路径。需要将rawfile目录下的文件拷贝到沙箱路径中。

分享
微博
QQ
微信
回复
2024-12-25 19:51:25
相关问题
HarmonyOS filePreview使用问题
1171浏览 • 1回复 待解决
HarmonyOS filePreview 不支持pdf文件的预览
1758浏览 • 1回复 待解决
HarmonyOS filePreview预览txt提示预览失败
2002浏览 • 1回复 待解决
HarmonyOS fopen打开文件失败
829浏览 • 1回复 待解决
dlopen打开.so文件使用md5加密
1586浏览 • 1回复 待解决
HarmonyOS excel文件如何打开
1183浏览 • 1回复 待解决
HarmonyOS 怎么打开PDF文件
1235浏览 • 1回复 待解决
关于 SO 文件使用问题
1295浏览 • 1回复 待解决
怎么指定应用打开文件
473浏览 • 0回复 待解决
HarmonyOS 打开图库自动返回问题
907浏览 • 1回复 待解决
如何打开指定文件夹,选择文件返回
10228浏览 • 1回复 待解决