在OpenHarmony设备上呈现PDF文件内容pdfjs 【坚果派】

在OpenHarmony设备上呈现PDF文件内容pdfjs

简介

JavaScript实现解析和展示PDF,可以在OpenHarmony设备上呈现PDF文件内容。

安装模块

使用npm install 安装

  npm install @ohos/pdfjs

使用说明

配置全局resourceManager

pdfjs 获取资源文件需要在EntryAbility文件配置全局resourceManager

globalThis.resourceManager = this.context.resourceManager;

1.使用getDocument(src:Uint8Array)方式加载要打开的PDF文件数据。

        globalThis.resourceManager.getRawFile(pdfFilePath, (error, value) => {
      if (error != null) {
        console.log(error.message);
      } else {
        this.getPDFDocument(value);
      }
    })

2.通过加载任务对象获取PDF文档中的各个页面。

    loadingTask.promise.then((pdf) => {
      // 获取第一页pdf数据
     

猜你喜欢

转载自blog.csdn.net/qq_39132095/article/details/132787620