MuPDF Android Pdf suitable for screen

I have successfully installed MuPDF for one of my Android apps. But the problem is that when rendering, I can not put the PDF on the screen. Can anyone suggest me how to achieve this. Thanks!

+4
source share
4 answers

Change 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));
    }
+4
source

the page size will be resized if the load is too large from the view. here is the "measureview" method in my code:

    private void measureView(View v) {
    // See what size the view wants to be
    v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    if (!mReflow) {
        // Work out a scale that will fit it to this view
        float 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(MeasureSpec.AT_MOST | (int) (v.getMeasuredWidth() * (scale + 0.8f) * mScale),
                MeasureSpec.AT_MOST | (int) (v.getMeasuredHeight() * (scale+0.8f) * mScale));
    } else {
        v.measure(View.MeasureSpec.EXACTLY | (int) (v.getMeasuredWidth()),
                View.MeasureSpec.EXACTLY | (int) (v.getMeasuredHeight()));
    }
}

this is what I need, load the page that should be selected in the view, load with readable text.

0
source

MAX MIN, @hassan83. MuPDF 1.9a

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;
    //landscape orientation
    if (getWidth() > getHeight())
    {
        scale = (float)getWidth()/(float)v.getMeasuredWidth() * (1.0f ); //make sure that we fill the page by multiplying with a scale factor of one
    }
    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));
}
0
source

In addition to the answer fooobar.com/questions/1521324 / ... , you can redisplay the view by adding the following code at the end:

requestLayout();
post(this);

again.

So, the full code is as follows (attribution for the code before the last comment: accepted answer to this question ):

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));

        // last comment
        // to force the initial rendering to the new scale

        requestLayout();
        post(this);
    }

Hope this helps.

-1
source

All Articles