AndroidPdfViewer icon indicating copy to clipboard operation
AndroidPdfViewer copied to clipboard

ScrollBy for scrolling PDF blurs images and wont scroll past first page, any work around?

Open ghost opened this issue 4 years ago • 19 comments

Hi all, I am building an android app that uses the scrollBy function for scrolling through a PDF document.

For instance...

pdfView.scrollBy(0, 20);

The problem I am having is that anything not immediately on screen (as in text found lower in the pdf that you would have to scroll to to see) is blurry.

Further to this, scroll by this method seems to only load and scroll through one page of a pdf file. Is there a way to make the viewer treat the different pages of the pdf as one long page?

Hopefully I am explaining that well. If anyone has any ideas, it would be much appreciated!

ghost avatar Jul 30 '20 15:07 ghost

Hello, I have encountered the same problem with you. Do you have a solution now

OneCats avatar Aug 05 '20 02:08 OneCats

Hi @OneCats, my main focus is trying to fix the blurring. My thoughts are that upon loading the pdf, the whole document needs rendered. I am struggling to find a means of doing this though, but if I find anything I will let you know.

ghost avatar Aug 05 '20 10:08 ghost

Yes, I have tried the author's method of changing the value of variables before. The effect is to load the current number of pages without blurring, but only the first page, because it slides to a page and loads again.At present, I do not have a good way to deal with it.Use the author's source code, Constants file, THUMBNAIL_RATIO = 1f

OneCats avatar Aug 05 '20 11:08 OneCats

Have you used the pdfView.scrollTo() method ?

1stmetro avatar Aug 05 '20 11:08 1stmetro

I tried ScrollBy MoveTo, which were MoveTo, but ScrollTo did not move

OneCats avatar Aug 05 '20 11:08 OneCats

Are you trying to use a button to scroll a set amount, not sure what you are trying to do exactly..

1stmetro avatar Aug 05 '20 11:08 1stmetro

@1stmetro I am using head gestures to trigger a scroll... so if my head tilts right the method pdfView.scrollBy(0, 20); is invoked. I have tried scrollTo(0, pdfView.getY()+20) as well, but hit the same issue.

ghost avatar Aug 05 '20 11:08 ghost

Ahh i see what you mean i dont use the standard constants so i dont really get a blur issue, but i can see what you mean.

1stmetro avatar Aug 05 '20 11:08 1stmetro

@alanscott Try call pdfView.loadPages(); AFTER pdfView.moveTo(x, y); It will refresh page rendering avoiding blurred issue, even if pages is zoomed in.

You should also try this with different pdf documents to test if it is working.

Il Mer 5 Ago 2020, 13:32 1stmetro [email protected] ha scritto:

Ahh i see what you mean i dont use the standard constants so i dont really get a blur issue, but i can see what you mean.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/barteksc/AndroidPdfViewer/issues/919#issuecomment-669141077, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQ634COXIRRALHIF6QBYKTR7E7LVANCNFSM4PN6KZLQ .

simonbellu avatar Aug 05 '20 11:08 simonbellu

Okay here is your fix,

Create the int and increase everytime you do the action, button move your head etc, 25 is the pixels to move.

Really interested in the code to change pages on a head movement if you wish to share or point me in the right direction never thought of it before.

            test=test+25;
            pdfView.scrollTo(0,test);
            pdfView.refreshDrawableState();

Second thoughts, not sure on this development tablet if thats 100% redrawing,

1stmetro avatar Aug 05 '20 11:08 1stmetro

@simonbellu for some reason the moveTo wont scroll with my head movements. I have tried loadPages() after the scrollBy call though and it still blurs. Thank you though!

ghost avatar Aug 05 '20 11:08 ghost

@alanscott my code will scroll on a button but i find it doesnt redraw and rerender the pdf so you will see issues with your pdf as you scroll,

It will do the same with your head guesture.

1stmetro avatar Aug 05 '20 11:08 1stmetro

@1stmetro Yes for some reason it wont allow for a continuous scroll, I get one small movement then it stops. It seems the scroll/move TO methods don't play well with the gestures, the scrollBy seems most effective (minus the blur of course).

As for the code for using head gestures, I am just using the google vision api. It has a pre-trained model to detect faces. I have thresholds set for where the camera sees the face position, and so at a particular x coordinate it will cause the scroll to happen.

@Override
       public void onUpdate(Detector.Detections<Face> detections, Face face) {
           float width = face.getWidth();
           if (face.getIsLeftEyeOpenProbability() > THRESHOLD || face.getIsRightEyeOpenProbability() > THRESHOLD) {
               if (width < farThresh) {
                   dispAction.setText("Move Closer");
               } else if (width > closerThresh) {
                   dispAction.setText("Too Close");
               } else {
                   dispAction.setText("Ready");
                   if (face.getPosition().x < 100) {
                       pdfView.scrollBy(0, 20);
                       pdfView.loadPages();
                   } else if (face.getPosition().x > 250) {
                       pdfView.scrollBy(0, -20);
                       pdfView.loadPages();
                   }
               }
           }
       }

ghost avatar Aug 05 '20 12:08 ghost

If you loop within your head tilt you can of course increase or decrease the value of Y on a scroll and it should scroll continuous in one direction, probably better to hook into the scrollbar and manipulate that which will then re-render everything as normal.

How are you initialising the detector ?

I really need to look this up,

1stmetro avatar Aug 05 '20 12:08 1stmetro

@1stmetro unfortunately none of that seemed to work. Finding myself at a loss.

Here is my implementation for google vision...

`private class EyesTracker extends Tracker<Face> {

    private final float THRESHOLD = 0.75f;

    private EyesTracker() {

    }
    @Override
    public void onUpdate(Detector.Detections<Face> detections, Face face) {
        //code here to scroll depending on what landmarks/methods you have example:
        // face.getIsLeftEyeOpenProbability>0.75 could be used to trigger etc
    }
    @Override
    public void onMissing(Detector.Detections<Face> detections) {
        super.onMissing(detections);
    }

    @Override
    public void onDone() {
        super.onDone();
    }
}

private class FaceTrackerFactory implements MultiProcessor.Factory<Face> {

    private FaceTrackerFactory() {

    }

    @Override
    public Tracker<Face> create(Face face) {
        return new EyesTracker();
    }
}

public void createCameraSource() {
    FaceDetector detector = new FaceDetector.Builder(this)
            .setTrackingEnabled(true)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
            .setMode(FaceDetector.FAST_MODE)
            .build();
    detector.setProcessor(new MultiProcessor.Builder(new FaceTrackerFactory()).build());

    cameraSource = new CameraSource.Builder(this, detector)
            .setRequestedPreviewSize(1024, 768)
            .setFacing(CameraSource.CAMERA_FACING_FRONT)
            .setRequestedFps(30.0f)
            .build();

    try {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        cameraSource.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if (cameraSource != null) {
        try {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            cameraSource.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

@Override
protected void onPause() {
    super.onPause();
    if (cameraSource != null) {
        cameraSource.stop();
    }

}


@Override
protected void onDestroy() {
    super.onDestroy();
    if (cameraSource != null) {
        cameraSource.release();
    }
}`

ghost avatar Aug 05 '20 13:08 ghost

having same issue in 3.2.0-beta.1

arunmandal53 avatar Aug 14 '20 22:08 arunmandal53

Has anyone had any success with a work around for this yet? @arunmandal53 @1stmetro @simonbellu @OneCats I have been trying but still no luck unfortunately

ghost avatar Aug 26 '20 14:08 ghost

Hello, Has anyone fixed yet ?

Florian6451 avatar May 10 '21 23:05 Florian6451

For posterity's sake I have found a workaround that works on my end. Using pdfView.moveRelativeTo(0, num); followed by pdfView.loadPages(); has fixed the blur and pages not loading issue on my end.

SegaSaturnity avatar May 21 '23 14:05 SegaSaturnity