在OpenHarmony設(shè)備上呈現(xiàn)PDF文件內(nèi)容pdfjs
簡(jiǎn)介
JavaScript實(shí)現(xiàn)解析和展示PDF,可以在OpenHarmony設(shè)備上呈現(xiàn)PDF文件內(nèi)容。
安裝模塊
使用npm install 安裝文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-744230.html
npm install @ohos/pdfjs
使用說(shuō)明
配置全局resourceManager
pdfjs 獲取資源文件需要在EntryAbility文件配置全局resourceManager文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-744230.html
globalThis.resourceManager = this.context.resourceManager;
1.使用getDocument(src:Uint8Array)方式加載要打開(kāi)的PDF文件數(shù)據(jù)。
globalThis.resourceManager.getRawFile(pdfFilePath, (error, value) => {
if (error != null) {
console.log(error.message);
} else {
this.getPDFDocument(value);
}
})
2.通過(guò)加載任務(wù)對(duì)象獲取PDF文檔中的各個(gè)頁(yè)面。
loadingTask.promise.then((pdf) => {
// 獲取第一頁(yè)pdf數(shù)據(jù)
到了這里,關(guān)于在OpenHarmony設(shè)備上呈現(xiàn)PDF文件內(nèi)容pdfjs 【堅(jiān)果派】的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!