0
  • 为了在我的 Android 应用程序中显示 PDF,我现在使用PSPDFKittoolkit( trial version) PSPDFKit来使用注释工具。
  • 我需要在片段中显示 PDF,因为我正在关注本指南Here但它不显示注释工具并且仅显示 pdf。任何帮助将不胜感激

PdfKitFragmentDemo.kt

class PdfKitFragmentDemo : AppCompatActivity(), AnnotationManager.OnAnnotationCreationModeChangeListener {

    lateinit var pdfFragment: PdfFragment
    lateinit var annotationCreationToolbar: AnnotationCreationToolbar
    lateinit var toolbarCoordinatorLayout: ToolbarCoordinatorLayout
    var uri: Uri? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_pdf_kit_fragment_demo)
        //var fragment = supportFragmentManager.findFragmentById(R.id.fragmentContainer) as PdfFragment
        uri = Uri.parse("file:///android_asset/sample.pdf")
        toolbarCoordinatorLayout = findViewById(R.id.toolbarCoordinatorLayout)
        annotationCreationToolbar = AnnotationCreationToolbar(this)

        val configuration = PdfConfiguration.Builder()
            .scrollDirection(PageScrollDirection.VERTICAL)
            .fitMode(PageFitMode.FIT_TO_WIDTH)
            .scrollOnEdgeTapMargin(1)
            .scrollMode(PageScrollMode.CONTINUOUS)
            .layoutMode(PageLayoutMode.SINGLE)
            .autosaveEnabled(true)
            .redoEnabled(true)
            .undoEnabled(true)
            .scrollbarsEnabled(true)
            .textSelectionEnabled(false)
            .enableFormEditing()
            .enableAnnotationEditing()
            .textSelectionPopupToolbarEnabled(true)
            .animateScrollOnEdgeTaps(true)
            .editableAnnotationTypes(listOf(AnnotationType.FREETEXT, AnnotationType.INK))
            .enabledAnnotationTools(listOf(AnnotationTool.SIGNATURE, AnnotationTool.ERASER, AnnotationTool.FREETEXT))
            .build()

        pdfFragment = PdfFragment.newInstance(uri!!, configuration)
        supportFragmentManager
            .beginTransaction()
            .replace(R.id.fragmentContainer, pdfFragment)
            .commit();
        pdfFragment.addOnAnnotationCreationModeChangeListener(this)

    }

    override fun onEnterAnnotationCreationMode(controller: AnnotationCreationController) {
        annotationCreationToolbar.bindController(controller)
        toolbarCoordinatorLayout.displayContextualToolbar(annotationCreationToolbar, true)
    }

    override fun onChangeAnnotationCreationMode(p0: AnnotationCreationController) {

    }

    override fun onExitAnnotationCreationMode(p0: AnnotationCreationController) {

    }
}

activity_pdf_kit_fragment_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PdfKitFragmentDemo"
    tools:ignore="UnusedAttribute">

    <FrameLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <com.pspdfkit.ui.toolbar.ToolbarCoordinatorLayout
            android:id="@+id/toolbarCoordinatorLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </FrameLayout>

</FrameLayout>
4

0 回答 0