Search code examples
androidmupdf

MuPDF Android Pdf fit to the screen


I succesfully installed MuPDF for one of my Android Apps. But the problems is, while rendering I cannot fit the PDF to the screen. Can anybody please suggest me how to achieve this. Thanks!


Solution

  • Edit the measureView method in ReaderView.java to become.

    private void measureView(View v) {
            // See what size the view wants to be
            v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            // Work out a scale that will fit it to this view
            float scale;
            if (getWidth()>getHeight())
            {
                scale = (float)getWidth()/(float)v.getMeasuredWidth();
                MIN_SCALE = (float)v.getMeasuredWidth()/(float)getWidth();
                MAX_SCALE = MIN_SCALE*5.0f;
            }
            else
                scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
                            (float)getHeight()/(float)v.getMeasuredHeight());
    
            // Use the fitting values scaled by our current scale factor
            v.measure(View.MeasureSpec.EXACTLY | (int)(v.getMeasuredWidth()*scale*mScale),
                    View.MeasureSpec.EXACTLY | (int)(v.getMeasuredHeight()*scale*mScale));
        }