Giter VIP home page Giter VIP logo

androidpdfviewer's Introduction

Looking for new maintainer!

Android PdfViewer

AndroidPdfViewer 1.x is available on AndroidPdfViewerV1 repo, where can be developed independently. Version 1.x uses different engine for drawing document on canvas, so if you don't like 2.x version, try 1.x.

Library for displaying PDF documents on Android, with animations, gestures, zoom and double tap support. It is based on PdfiumAndroid for decoding PDF files. Works on API 11 (Android 3.0) and higher. Licensed under Apache License 2.0.

What's new in 3.2.0-beta.1?

  • Merge PR #714 with optimized page load
  • Merge PR #776 with fix for max & min zoom level
  • Merge PR #722 with fix for showing right position when view size changed
  • Merge PR #703 with fix for too many threads
  • Merge PR #702 with fix for memory leak
  • Merge PR #689 with possibility to disable long click
  • Merge PR #628 with fix for hiding scroll handle
  • Merge PR #627 with fitEachPage option
  • Merge PR #638 and #406 with fixed NPE
  • Merge PR #780 with README fix
  • Update compile SDK and support library to 28
  • Update Gradle and Gradle Plugin

Changes in 3.0 API

  • Replaced Contants.PRELOAD_COUNT with PRELOAD_OFFSET
  • Removed PDFView#fitToWidth() (variant without arguments)
  • Removed Configurator#invalidPageColor(int) method as invalid pages are not rendered
  • Removed page size parameters from OnRenderListener#onInitiallyRendered(int) method, as document may have different page sizes
  • Removed PDFView#setSwipeVertical() method

Installation

Add to build.gradle:

implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

or if you want to use more stable version:

implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'

Library is available in jcenter repository, probably it'll be in Maven Central soon.

ProGuard

If you are using ProGuard, add following rule to proguard config file:

-keep class com.shockwave.**

Include PDFView in your layout

<com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Load a PDF file

All available options with default values:

pdfView.fromUri(Uri)
or
pdfView.fromFile(File)
or
pdfView.fromBytes(byte[])
or
pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
or
pdfView.fromSource(DocumentSource)
or
pdfView.fromAsset(String)
    .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
    .enableSwipe(true) // allows to block changing pages using swipe
    .swipeHorizontal(false)
    .enableDoubletap(true)
    .defaultPage(0)
    // allows to draw something on the current page, usually visible in the middle of the screen
    .onDraw(onDrawListener)
    // allows to draw something on all pages, separately for every page. Called only for visible pages
    .onDrawAll(onDrawListener)
    .onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
    .onPageChange(onPageChangeListener)
    .onPageScroll(onPageScrollListener)
    .onError(onErrorListener)
    .onPageError(onPageErrorListener)
    .onRender(onRenderListener) // called after document is rendered for the first time
    // called on single tap, return true if handled, false to toggle scroll handle visibility
    .onTap(onTapListener)
    .onLongPress(onLongPressListener)
    .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
    .password(null)
    .scrollHandle(null)
    .enableAntialiasing(true) // improve rendering a little bit on low-res screens
    // spacing between pages in dp. To define spacing color, set view background
    .spacing(0)
    .autoSpacing(false) // add dynamic spacing to fit each page on its own on the screen
    .linkHandler(DefaultLinkHandler)
    .pageFitPolicy(FitPolicy.WIDTH) // mode to fit pages in the view
    .fitEachPage(false) // fit each page to the view, else smaller pages are scaled relative to largest page.
    .pageSnap(false) // snap pages to screen boundaries
    .pageFling(false) // make a fling change only a single page like ViewPager
    .nightMode(false) // toggle night mode
    .load();
  • pages is optional, it allows you to filter and order the pages of the PDF as you need

Scroll handle

Scroll handle is replacement for ScrollBar from 1.x branch.

From version 2.1.0 putting PDFView in RelativeLayout to use ScrollHandle is not required, you can use any layout.

To use scroll handle just register it using method Configurator#scrollHandle(). This method accepts implementations of ScrollHandle interface.

There is default implementation shipped with AndroidPdfViewer, and you can use it with .scrollHandle(new DefaultScrollHandle(this)). DefaultScrollHandle is placed on the right (when scrolling vertically) or on the bottom (when scrolling horizontally). By using constructor with second argument (new DefaultScrollHandle(this, true)), handle can be placed left or top.

You can also create custom scroll handles, just implement ScrollHandle interface. All methods are documented as Javadoc comments on interface source.

Document sources

Version 2.3.0 introduced document sources, which are just providers for PDF documents. Every provider implements DocumentSource interface. Predefined providers are available in com.github.barteksc.pdfviewer.source package and can be used as samples for creating custom ones.

Predefined providers can be used with shorthand methods:

pdfView.fromUri(Uri)
pdfView.fromFile(File)
pdfView.fromBytes(byte[])
pdfView.fromStream(InputStream)
pdfView.fromAsset(String)

Custom providers may be used with pdfView.fromSource(DocumentSource) method.

Links

Version 3.0.0 introduced support for links in PDF documents. By default, DefaultLinkHandler is used and clicking on link that references page in same document causes jump to destination page and clicking on link that targets some URI causes opening it in default application.

You can also create custom link handlers, just implement LinkHandler interface and set it using Configurator#linkHandler(LinkHandler) method. Take a look at DefaultLinkHandler source to implement custom behavior.

Pages fit policy

Since version 3.0.0, library supports fitting pages into the screen in 3 modes:

  • WIDTH - width of widest page is equal to screen width
  • HEIGHT - height of highest page is equal to screen height
  • BOTH - based on widest and highest pages, every page is scaled to be fully visible on screen

Apart from selected policy, every page is scaled to have size relative to other pages.

Fit policy can be set using Configurator#pageFitPolicy(FitPolicy). Default policy is WIDTH.

Additional options

Bitmap quality

By default, generated bitmaps are compressed with RGB_565 format to reduce memory consumption. Rendering with ARGB_8888 can be forced by using pdfView.useBestQuality(true) method.

Double tap zooming

There are three zoom levels: min (default 1), mid (default 1.75) and max (default 3). On first double tap, view is zoomed to mid level, on second to max level, and on third returns to min level. If you are between mid and max levels, double tapping causes zooming to max and so on.

Zoom levels can be changed using following methods:

void setMinZoom(float zoom);
void setMidZoom(float zoom);
void setMaxZoom(float zoom);

Possible questions

Why resulting apk is so big?

Android PdfViewer depends on PdfiumAndroid, which is set of native libraries (almost 16 MB) for many architectures. Apk must contain all this libraries to run on every device available on market. Fortunately, Google Play allows us to upload multiple apks, e.g. one per every architecture. There is good article on automatically splitting your application into multiple apks, available here. Most important section is Improving multiple APKs creation and versionCode handling with APK Splits, but whole article is worth reading. You only need to do this in your application, no need for forking PdfiumAndroid or so.

Why I cannot open PDF from URL?

Downloading files is long running process which must be aware of Activity lifecycle, must support some configuration, data cleanup and caching, so creating such module will probably end up as new library.

How can I show last opened page after configuration change?

You have to store current page number and then set it with pdfView.defaultPage(page), refer to sample app

How can I fit document to screen width (eg. on orientation change)?

Use FitPolicy.WIDTH policy or add following snippet when you want to fit desired page in document with different page sizes:

Configurator.onRender(new OnRenderListener() {
    @Override
    public void onInitiallyRendered(int pages, float pageWidth, float pageHeight) {
        pdfView.fitToWidth(pageIndex);
    }
});

How can I scroll through single pages like a ViewPager?

You can use a combination of the following settings to get scroll and fling behaviour similar to a ViewPager:

    .swipeHorizontal(true)
    .pageSnap(true)
    .autoSpacing(true)
    .pageFling(true)

One more thing

If you have any suggestions on making this lib better, write me, create issue or write some code and send pull request.

License

Created with the help of android-pdfview by Joan Zapata

Copyright 2017 Bartosz Schiller

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

androidpdfviewer's People

Contributors

alierdogan7 avatar andrewgrow avatar barteksc avatar cesquivias avatar flamedek avatar hansinator85 avatar lucianoreul avatar mclillill avatar miha-x64 avatar owurman avatar skarempudi avatar yuriyskulskiy avatar yusefmaali avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidpdfviewer's Issues

Occasional NullPointerException when showing a PDF

Occasionally, I get a NullPointerException when trying to show a PDF. I haven't really found a pattern yet - it doesn't seem related to the PDF, or if it is, the same PDF still works fine most of the time.

Version 1.1.1.

I suppose it's caused by an (internal) call to public void removeAllTasks(), which is not synchronized.

06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Draw Ver: 1536
06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Start X: 0
06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Start Y: -256
06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Canvas Hor: 256
06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Canvas Ver: 256
06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Draw Hor: 1280
06-24 15:52:03.663 17306-17422/com.xxxx.android.beta D/jniPdfium: Draw Ver: 1536
06-24 15:52:03.673 17306-17422/com.xxxx.android.beta E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
                                                                        Process: com.xxxx.android.beta, PID: 17306
                                                                        java.lang.RuntimeException: An error occured while executing doInBackground()
                                                                            at android.os.AsyncTask$3.done(AsyncTask.java:300)
                                                                            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                                                                            at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
                                                                            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                            at java.lang.Thread.run(Thread.java:818)
                                                                         Caused by: java.lang.NullPointerException: Attempt to read from field 'float com.github.barteksc.pdfviewer.RenderingAsyncTask$RenderingTask.width' on a null object reference
                                                                            at com.github.barteksc.pdfviewer.RenderingAsyncTask.proceed(RenderingAsyncTask.java:103)
                                                                            at com.github.barteksc.pdfviewer.RenderingAsyncTask.doInBackground(RenderingAsyncTask.java:67)
                                                                            at com.github.barteksc.pdfviewer.RenderingAsyncTask.doInBackground(RenderingAsyncTask.java:31)
                                                                            at android.os.AsyncTask$2.call(AsyncTask.java:288)
                                                                            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587at java.lang.Thread.run(Thread.java:818

Fatal signal 11 (SIGSEGV) at 0x00000000 (code=128)

Hello,

I am getting "Fatal signal 11 (SIGSEGV) at 0x00000000 (code=128), thread 29948 (AsyncTask #3)" error while trying to load a 4MB pdf file. I don't encounter this error with smaller pdf files. Can you help me with this?

This is my code.

pdfView.fromAsset("brochure-eclassic.pdf")
                .enableSwipe(true)
                .enableDoubletap(true)
                .swipeVertical(false)
                .showMinimap(false)
                .onError(new OnErrorListener() {
                    @Override
                    public void onError(Throwable t) {
                        Log.e("pdf", "error", t);
                    }
                })
                .load();

Thank you

Certificate

Is it possible to see issued certificate of PDF with this library?

PDFView, setBackground transparent become black

Hello,

When I set the background of the PDFView to transparent it turn to black.

        <com.github.barteksc.pdfviewer.PDFView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/transparent"/>

where transparent is:

<color name="transparent">#00000000</color>

flip animation

how can i add flip animation like google play book? i try some library but i can't get animation like google play book. i put animation on onPageChange.

DocumentFile

Is it possible to make AndroidPdfViewer read a DocumentFile?

Right now, there are fromFile() and fromAsset() but I was thinking it would be great if we have something like fromDocumentFile().

  public Configurator fromDocumentFile(Context context, DocumentFile document_file) {
    if (!document_file.exists()) {
      throw new FileNotFoundException(document_file.getUri().getPath().toString() + " does not exist.");
    }
    return new Configurator(context, document_file);
  }

What I want to do is that I let a user pick up a PDF file using Android's Storage Access Framework and display it on the screen using AndroidPdfViewer.

Right now, I can do this by copying DocumentFile to a temp File instance and pass it to fromFile(). However, I was thinking if I could avoid making a temporary file.

App crushing

I'm getting following error and app become crushed while swipe 30-35 page of any pdf file:

AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pdf, PID: 11626
java.lang.ArithmeticException: divide by zero
at

Get Bitmaps from every page of PDF file

Is there any way to get Bitmap from every page of PDF file? I need to render pdf and also get Bitmaps to do some extra operations with them (e.g. save).

There is onLayerDrawn event, but it call not only once, but every time pdf is scrolled.

I know, that storing many Bitmaps in memory is not good idea, but it is important feature and will work for files with a few pages.

Fill a PDF form

Hi there
Great library for viewing a PDF file.
Just a request for new feature, can you add Fill a PDF form feature?
I think no open source library has that feature available.

Thanks

mContext Null Error

Hi

@barteksc Can you please help me on below (PFB)

E/com.shockwave.pdfium.PdfiumCore: mContext may be null

  • I am not sure why it is coming and not able to load pdf in viewpager at this moment.

Thanks

Can i get thumbnail bitmap of pages of pdf

Hi,

Is there any way for getting thumbnails of pdf using this library. I want to show them in scrollview so that user can jump to a page by tapping on particular thumbnail.

Thanks
Shubham Vishnoi

sometimes crash with:An error occured while executing doInBackground

FATAL EXCEPTION: AsyncTask #7
Process: com.dkhs.portfolio, PID: 11044
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at com.github.barteksc.pdfviewer.RenderingAsyncTask.proceed(RenderingAsyncTask.java:103)
at com.github.barteksc.pdfviewer.RenderingAsyncTask.doInBackground(RenderingAsyncTask.java:67)
at com.github.barteksc.pdfviewer.RenderingAsyncTask.doInBackground(RenderingAsyncTask.java:31)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:841) 

Dragging (when zoomed) in ViewPager not working as expected

I have a few pdfs displayed in a view pager. When I zoom one and try to drag to the left/right, the pdf does not pan, but the view pager immediately takes hold of the scrolling and switches to the next page.

If I first drag up/down and then (without lifting my finger) drag left/right, it seems to work as expected.

Any ideas, how I can pass the touch events first to the PDFView and then to the view pager?

Password PDF

Password PDF are not asking, for password to enter.
07-08 15:21:57.020 13331-13331/com.jagdiv.android.gogleapplication E/PDFView: load pdf error
07-08 15:21:57.020 13331-13331/com.jagdiv.android.gogleapplication E/PDFView: java.io.IOException: cannot create document: Incorrect password.
07-08 15:21:57.020 13331-13331/com.jagdiv.android.gogleapplication E/PDFView: at com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(Native Method)
07-08 15:21:57.020 13331-13331/com.jagdiv.android.gogleapplication E/PDFView: at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:87)
07-08 15:21:57.020 13331-13331/com.jagdiv.android.gogleapplication E/PDFView: at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:59)

Pixelation

@barteksc - Awesome work.

I see pixelation on the top/middle of the page, while on certain devices.

For example:-

Galaxy S6 & S7 Edge - I can see pixelation at the top.

screen shot 2016-07-18 at 4 42 49 pm

On other devices like HTC M8 it happens when I pinch/tap to zoom. Is there any way around this at the moment?

PDFView in a ScrollView

Hello,

I need to put the PDFView in a ScrollView, how should I do it?

So far, either the PDFView is not showing or the scroll is not working.

Thank you

Turn pages when zooming.

It would be great if we can turn pages when the view is being zoomed.
I checked DragPinchManager.java and realized that onDrag() and endDrag() methods ignore events when isZooming() returns true.
Is it possible to handle these events?
What changes should be made on PDFView.java for that?

rendering change

i hope to change rendering pdf file. example, i want to make 5 pages of file that is recognized 4 pages.
ex) 1 2 3 4 pdf file -> 4 1 2 3 4 pdf file
pages() method is likely my wish. but that's animation is incorrect that my wants.

Horizontal page indicator

Hi, a simple question, I would like to set my scroll indicator on the bottom of the PDF view. How do I flip the scrollBar indicator so that the user has to scoot from left to right instead of vertically from upper side to bottom?
Thanks

Two pages at once

Hello!
Is there any opportunity to show two pages at once with swapping between two-page turns, like a magazine or book?

Fille corrupted when loading pdf files from the Android Device folder

I have done as below:

  • Directory: pdf_file
  • pdf files: page.pdf, page2.pdf
  • Permission for file access in manifest file

When I am trying to render the pdf file, below crash is not allowing to render

06-25 12:04:46.229 20365-20365/? I/applock: launch broadcast taken: com.joanzapata.pdfview.sample
06-25 12:04:46.291 19545-19545/? D/pdf file path:: /storage/emulated/0/pdf_files/page1.pdf
06-25 12:04:46.297 19545-19560/? D/PdfDroid: initializing PdfRender JNI library based on MuPDF
06-25 12:04:46.303 19545-19560/? I/PdfDroid: Corrupted file '/storage/emulated/0/pdf_files/page1.pdf', trying to repair
06-25 12:04:46.303 19545-19560/? D/PdfDroid: Exception 'java/lang/RuntimeException', Message: 'PDF file is corrupted'
06-25 12:04:46.303 19545-19560/? D/PdfDroid: PdfDocument.nativeOpen(): return handle = 0x74f5211050

I tried to render using other applications adobe etc... its good to go and render smoothly

Can you please provide or suggest me what is happening here?

Thanks

Zoom width to container size

Is there any way to set initial zoom of an open document so that width matches its container (the PDFView) ?
In other words... when rotating to landscape, I would like the document to have the width matching the container, no worries for the height.
Thank you!

Manually instantiating a new PDFView

I don't know if this is a NativeScript issue or an AndroidPdfViewer issue, but since the app only crashes when I try to create an instance of PDFView, I'm asking the question here first.

I'm building a NativeScript plugin, in which I need to manually create an instance of PDFView by calling its constructor. However, the plugin seems to crash, and I have no stack trace to follow. With NativeScript I have a TypeScript/JavaScript bridge to the native Android package, which allows me to instantiate the view this way inside _createUI:

import * as view from 'ui/core/view';
import AndroidPdfView = com.github.barteksc.pdfviewer.PDFView;

export class PDFView extends view.View {
  _android: AndroidPdfView;

  _createUI() {
    log(1);
    this._android = new AndroidPdfView(this._context);
    log(2);   // never reaches this
  }
}

In terms of logs, this is all I got:

I/DEBUG   (   84):     #34 pc 002597db  /data/app/com.merott.NativeScriptPDFViewDemo-1/lib/x86/libNativeScript.so (tns::CallbackHandlers::CallJSMethod(v8::Isolate*, _JNIEnv*, v8::Local<v8::Object> const&, std::string const&, _jobjectArray*)+635)
I/DEBUG   (   84):     #35 pc 002abd26  /data/app/com.merott.NativeScriptPDFViewDemo-1/lib/x86/libNativeScript.so (tns::Runtime::CallJSMethodNative(_JNIEnv*, _jobject*, int, _jstring*, int, unsigned char, _jobjectArray*)+406)
I/DEBUG   (   84):     #36 pc 002b6b8e  /data/app/com.merott.NativeScriptPDFViewDemo-1/lib/x86/libNativeScript.so (Java_com_tns_Runtime_callJSMethodNative+222)

If instantiate a new SurfaceView instead of AndroidPdfView, the plugin doesn't crash. I realise that doesn't necessarily mean this is an issue with AndroidPdfViewer but I'm asking for help here first.

Double tap zoom

Hi @barteksc

I am planning to zoom in the pdf page on the point user double tapped. but as of now it is zooming from the center of the page.

How can I achieve my solutions. It's good to have such a library you provided but as per my requirement please suggest and want to achieve this.

Thanks
Vinod

unable to use setOnLongClickListener()

I want to select the text on which the user makes long click, but
pdfView.setOnLongClickListener(new View.OnLongClickListener() {
@OverRide
public boolean onLongClick(View v) {
//code
return true;
}
});
is not working, could you please tell me how to do this?

MaxZoom not work

Hello,

I use this library and setMaxZoom, but when I test app, I can zoom to max zoom (10f).

Code:

       int page = Integer.valueOf(path.replace("page_", "").replace(".pdf", ""));

        switch (page) {
            case 1: scaleSize = 1.5f; maxZoom = 2f; break;
            case 2: scaleSize = 1.5f; maxZoom = 2.5f; break;
            case 3: scaleSize = 3.5f; maxZoom = 4.5f; break;
            case 4: scaleSize = 1f; maxZoom = 2f; break;
            case 5: scaleSize = 1.7f; maxZoom = 2.5f; break;
            case 6: scaleSize = 1.7f; maxZoom = 2.5f; break;
        }


        pdfView.fromAsset(path)
                .showMinimap(false)
                .onDraw(new OnDrawListener() {
                    @Override
                    public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {
                        x = pageWidth / 4;
                    }
                })
                .load();

        pdfView.setSwipeVertical(true);
        pdfView.useBestQuality(true);
        pdfView.setMaxZoom(maxZoom);
        pdfView.setMidZoom(maxZoom);

Fatal signal 11 on large files

Good day!
Getting Fatal signal 11 at opening 70 mb size pdf.
Error - A/libc: Fatal signal 11 (SIGSEGV), code 128, fault addr 0x0 in tid 7413 (AsyncTask #4)
or
Error - A/libc: Fatal signal 11 (SIGSEGV), code 128, fault addr 0x0 in tid 7021 (AsyncTask #2)

Stacktrace:
`pid: 32022, tid: 32308, name: AsyncTask #4 >>> package.name <<<
signal 11 (SIGSEGV), code 128 (SI_KERNEL), fault addr 0x0
eax 00000000 ebx d4e9c20c ecx 00000000 edx cde485b8
esi 00000000 edi 00000001
xcs 00000023 xds 0000002b xes 0000002b xfs 000000ff xss 0000002b
eip d4c125a0 ebp d44f8df8 esp d44f8dbc flags 00210246

backtrace:
#00 pc 002af5a0 /data/app/package.name-1/lib/x86/libmodpdfium.so
#1 pc 002b2990 /data/app/package.name-1/lib/x86/libmodpdfium.so (opj_dwt_decode_real+1456)
#2 pc 002029ee /data/app/package.name-1/lib/x86/libmodpdfium.so (opj_tcd_decode_tile+414)
#3 pc 001f161b /data/app/package.name-1/lib/x86/libmodpdfium.so (opj_j2k_decode_tile+123)
#4 pc 001f1b67 /data/app/package.name-1/lib/x86/libmodpdfium.so
#5 pc 001e56b4 /data/app/package.name-1/lib/x86/libmodpdfium.so (opj_j2k_decode+180)
#6 pc 001f8360 /data/app/package.name-1/lib/x86/libmodpdfium.so (opj_jp2_decode+80)
#7 pc 001f529f /data/app/package.name-1/lib/x86/libmodpdfium.so (opj_decode+63)
#8 pc 00149a74 /data/app/package.name-1/lib/x86/libmodpdfium.so (CJPX_Decoder::Init(unsigned char const, int)+532)
#9 pc 00149bf9 /data/app/package.name-1/lib/x86/libmodpdfium.so (CCodec_JpxModule::CreateDecoder(unsigned char const, unsigned int, int)+73)
#10 pc 0011dd61 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_DIBSource::LoadJpxBitmap()+129)
#11 pc 0011e9f3 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_DIBSource::CreateDecoder()+579)
#12 pc 00120c87 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_DIBSource::StartLoadDIBSource(CPDF_Document, CPDF_Stream const, int, CPDF_Dictionary, CPDF_Dictionary, int, unsigned int, int)+487)
#13 pc 001172c9 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ImageCache::StartGetCachedBitmap(CPDF_Dictionary, CPDF_Dictionary, int, unsigned int, int, CPDF_RenderStatus, int, int)+169)
#14 pc 001173b2 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_PageRenderCache::StartGetCachedBitmap(CPDF_Stream, int, unsigned int, int, CPDF_RenderStatus, int, int)+130)
#15 pc 00120ec9 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ProgressiveImageLoaderHandle::Start(CPDF_ImageLoader, CPDF_ImageObject const, CPDF_PageRenderCache, int, unsigned int, int, CPDF_RenderStatus, int, int)+121)
#16 pc 00121032 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ImageLoader::StartLoadImage(CPDF_ImageObject const, CPDF_PageRenderCache, void&, int, unsigned int, int, CPDF_RenderStatus, int, int)+130)
#17 pc 001184f3 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ImageRenderer::StartLoadDIBSource()+179)
#18 pc 0011a3cd /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ImageRenderer::Start(CPDF_RenderStatus, CPDF_PageObject const, CFX_Matrix const, int, int)+173)
#19 pc 00115a10 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_RenderStatus::ContinueSingleObject(CPDF_PageObject const, CFX_Matrix const, IFX_Pause)+400)
#20 pc 00115bee /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ProgressiveRenderer::Continue(IFX_Pause)+414)
#21 pc 00115f51 /data/app/package.name-1/lib/x86/libmodpdfium.so (CPDF_ProgressiveRenderer::Start(CPDF_RenderContext, CFX_RenderDevice, CPDF_RenderOptions const, IFX_Pause, int)+129)
#22 pc 00082352 /data/app/package.name-1/lib/x86/libmodpdfium.so (FPDF_RenderPage_Retail(CRenderContext, void, int, int, int, int, int, int, int, IFSDK_PAUSE_Adapter*)+626)
#23 pc 00082d99 /data/app/package.name-1/lib/x86/libmodpdfium.so (FPDF_RenderPageBitmap+345)
#24 pc 0000654b /data/app/package.name-1/lib/x86/libjniPdfium.so (Java_com_shockwave_pdfium_PdfiumCore_nativeRenderPageBitmap+779)
#25 pc 002c9ded /data/dalvik-cache/x86/data@[email protected]@[email protected]`

Thanks for your help.
Best, Nick.

Rendering quality when zooming/dezooming

First, thank you very much for your work, I think a lot of people are waiting for a library like yours.

I was wondering if it could be possible to improve the render when loading the tiles? I have noticed that the library displays bad quality of the tiles when "re-calculating" the render for the given zoom (I suppose!). You'll find a screenshot in attachment.

Thank you,

untitled

Blank pdf

Hi
I use pdfview and load a pdf file from assent folder.
It was working very good. I approve my app and now I don’t see my pdf file.
Pdfview load it, (I can change its pages and log it) but show only blank page (white screen).
Please help me.
thanks a lot.

Accessing a pdf from internal storage throws file not found exception

Am trying a populate a pdf which is stored in internal storage is throwing FileNotFoundException.

    File file1 = new File(Environment.getExternalStorageDirectory()+"/pdf/Read.pdf");
    pdfView.fromFile(file1)
            .defaultPage(1)
            .onPageChange(this)
            .swipeVertical(true)
            .showMinimap(false)
            .load();

But when I manually check the directory, I could see that file exist. Or some times its giving me com.shockwave.pdfium.PdfOpenException: Open document failed in my log

How we can add bookmarks in pdf

Hi,

I want to use this awesome library unable to find a method for adding bookmark.
Can you please help me?

Thanks
Shubham

Sliding Animation

Hello, it seems that the library is locking me into using default animations thru .swipeVertical(false) upon rendering a PDF.

Is there a way to disable this slide animation all in all? We just want our PDF to show up, and not slide from right to left (or bottom to top). The readme implies that the only possible configurations are here.

Page navigation with thumbnails

Im looking forward a way to implement a scrolling navigation which will contain thumbs of all pages. Can I incorporate thumbs with scroller or can I get a list of thumbs of all pages?

Pages get stretched when viewing pdf-files with variable page width.

I have a pdf file with mostly normal document pages but with a few large image-based pages. All the following pages seem to get stretched based on the width of the first page.

Is there a way to mix horizontal and vertical pages without either of them getting stretched?

Page Gap

How to add some gap between pages?

[GestureDetector]

Hi,

As docs, the following callback is called when user uses swipe to change page:
void onPageChanged(int page, int pageCount);
But in some common gestures (such as single tap), actually the page is not changed but onPageChanged is still invoked.
I hope your lib can support some common gestures such as onSingleTapConfirmed, onSingleTapUp...With these events, we can exit/enter full screen while reading pdf file.

Best Regards.

Open document failed

Hi, recently i got this error

com.shockwave.pdfium.PdfOpenException: Open document failed
at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:72)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:61)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:32)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)

Do you have any idea why? How could i fix this? Thanks

Fatal Signal

Hi, sometimes i got this error:

A/libc: Fatal signal 11 (SIGSEGV) at 0xffffffff (code=1), thread 16929 (AsyncTask #5)

This happened after i open -> exit -> reopen -> exit -> reopen... the activity.
This caused the activity to exit.

Scrollbar indicator do not appears on pre-Lollipop

Good day. Today found out few problems with showing ScrollbarIndicator on Android 4.2.2. It does not appears the first time when pdf opened, but returning back after rotation. Another thing that it can show 0 or number < 0 on first tap on indicator, and then it shows as expected. Does anyone has the same problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.