DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.05k stars 1.85k forks source link

get the total height of pdf document #1001

Closed Dante3887 closed 3 years ago

Dante3887 commented 3 years ago

Hello, I am a beginner on developing android app. And now I am trying to add a button on the pdfview, since I have been successful to merge pdfview into scrollview after getting help from #396 And how should I get the height of the pdfview since I always get 0 when using PDFView.height??

val PDFView = binding.pdfView
       PDFView.fromAsset("secrets.pdf").onTap(OnTapListen()).enableSwipe(true)
            .swipeHorizontal(false).pageFitPolicy(FitPolicy.BOTH).load()
    //Wrong Height
    val height = PDFView.height

    PDFView.getViewTreeObserver()
        .addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
            @Override
            override fun onGlobalLayout() {
                PDFView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                val params: ViewGroup.LayoutParams = PDFView.getLayoutParams();
                params.width = Resources.getSystem().displayMetrics.widthPixels;
                //should not be fixed height
                params.height = 10000;
                PDFView.setLayoutParams(params);

            }

        });
DoveBarnett commented 2 years ago

Can you get the PDF height correctly now?