目录

Annotations

You can enter the annotation mode to add highlighted, underlined, and strikethrough annotations.

API Description

API Name Description
enableAnnotation(annotationType: SupportedAnnotationType, color?: number): void Switches between common operations and adds annotations.

Sample Code

  1. Load the PDF document.

  2. Call the PdfView preview component to render the display.

  3. Call the enableAnnotation method to enter the annotation mode.

import { pdfService, pdfViewManager, PdfView } from '@kit.PDFKit';
// ...

@Entry
@Component
struct AnnotationPage {
  private pdfController = new pdfViewManager.PdfController();
  private context = this.getUIContext().getHostContext() as Context;

  aboutToAppear(): void {
    // Ensure that the input.pdf document exists in the src/main/resources/resfile project directory.
    let filePath = this.context.resourceDir + '/input.pdf';
    (async () => {
      let loadResult: pdfService.ParseResult = await this.pdfController.loadDocument(filePath);
      if (pdfService.ParseResult.PARSE_SUCCESS === loadResult) {
        this.pdfController.enableAnnotation(pdfViewManager.SupportedAnnotationType.STRIKETHROUGH, 0xAAFF0000);
      }
    })()
  }

  build() {
  // ...
      Column() {
        PdfView({
          controller: this.pdfController,
          pageFit: pdfService.PageFit.FIT_WIDTH,
          showScroll: true
        })
          .id('pdfview_app_view')
          .layoutWeight(1);
      }
      // ...
  }
}