智能客服
你问我答,随时在线为你解决问题

























pdfViewManager为PDF文档提供了丰富的预览特定特性。
图1:提供了双页预览布局,页面宽度适配和连续滚动的预览方式

接口名 | 描述 |
|---|---|
setPageLayout(columnCount: PageLayout): void | 设置页面布局模式。其中“columnCount”取值如下:
|
setPageContinuous(isContinuous: boolean): void | 设置页面滚动是否连续排列。 |
setPageFit(pageFit: PageFit): void | 设置页面的适配模式。 |
goToPage(pageIndex: number): void | 跳转到指定页。 |
setPageZoom(zoom: number): void | 设置视图的缩放比例。 |
import { pdfService, PdfView, pdfViewManager } from '@kit.PDFKit';
import { common } from '@kit.AbilityKit';
@Entry
@Component
struct PdfPage {
private controller: pdfViewManager.PdfController = new pdfViewManager.PdfController();
private context = getContext() as common.UIAbilityContext;
private loadResult: pdfService.ParseResult = pdfService.ParseResult.PARSE_ERROR_FORMAT;
aboutToAppear(): void {
// 确保沙箱目录有input.pdf文档
let filePath = this.context.filesDir + '/input.pdf';
(async () => {
this.loadResult = await this.controller.loadDocument(filePath);
// 注意:这里刚加载文档,请不要在这里立即设置PDF文档的预览方法。
})()
}
build() {
Column() {
Row() {
// 设置预览方式
Button('setPreviewMode').onClick(() => {
if (this.loadResult === pdfService.ParseResult.PARSE_SUCCESS) {
// 单页布局
this.controller.setPageLayout(pdfService.PageLayout.LAYOUT_SINGLE);
// 是否连续滚动预览
this.controller.setPageContinuous(true);
// 适配页的预览方式
this.controller.setPageFit(pdfService.PageFit.FIT_PAGE);
}
})
// 跳转到第11页
Button('goTopage').onClick(() => {
if (this.loadResult === pdfService.ParseResult.PARSE_SUCCESS) {
this.controller.goToPage(10);
}
})
// 页面放大2倍
Button('zoomPage2').onClick(() => {
if (this.loadResult === pdfService.ParseResult.PARSE_SUCCESS) {
this.controller.setPageZoom(2);
}
})
}
PdfView({
controller: this.controller,
pageFit: pdfService.PageFit.FIT_WIDTH,
showScroll: true
})
.id('pdfview_app_view')
.layoutWeight(1);
}
}
} 智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功