能打开PDF第一页,但是无法查看其他页。pdfview自己实现了滑动操作,在pdfview组件外套scroll会导致事件被scroll抢占导致无法滑动
import { pdfService, pdfViewManager, PdfView } from '@kit.PDFKit'
import { common } from '@kit.AbilityKit';
import { fileIo } from '@kit.CoreFileKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { router } from '@kit.ArkUI';
@Entry
@Component
struct PDFPage {
private controller: pdfViewManager.PdfController = new pdfViewManager.PdfController();
private params?:PDFPageData
aboutToAppear(): void {
let context = getContext() as common.UIAbilityContext;
let option = router.getParams()
if ((option as PDFPageData).filePath != undefined){
this.params = option as PDFPageData
}
// 确保rawfile里面有pdf文件
let filePath: string =""
if(this.params!=undefined){
filePath=this.params.filePath
}
this.controller.loadDocument(filePath, '', 0, (progress: number) => {
return progress;
}).then((v)=>{
// let loadResult: pdfService.ParseResult = v
// if (pdfService.ParseResult.PARSE_SUCCESS === loadResult) {
// this.controller.setViewOffset(0.5, 0.5, true);
// }
})
}
build() {
Scroll() {
PdfView({
controller: this.controller,
pageFit: pdfService.PageFit.FIT_WIDTH,
showScroll: true
})
}
.width('100%')
.height('100%')
}
}
export interface PDFPageData{
filePath:string
title:string
}
将scroll组件去除
pdf预览demo:
https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/tutorials\_PDFKit-Codelab-Clientdemo-ArkTS