Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit dbaa980

Browse files
committed
Update PdfiumAndroid to 1.6.0
Add method fitToWidth() Fix rare IllegalArgumentException while rendering Add OnRenderListener Add Configurator.enableAntialiasing() Modify engine to not block UI when big documents are loaded Change Constants interface and inner interfaces to classes Change default cache size to 150 parts Update gradle version Update build tools version
1 parent 4f77803 commit dbaa980

File tree

11 files changed

+223
-63
lines changed

11 files changed

+223
-63
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2.5.0 (2017-03-23)
2+
* Update PdfiumAndroid to 1.6.0, which is based on newest Pdfium from Android 7.1.1. It should fix many rendering and fonts problems
3+
* Add method `pdfView.fitToWidth()`, which called in `OnRenderListener.onInitiallyRendered()` will fit document to width of the screen (inspired by [1stmetro](https://github.com/1stmetro))
4+
* Add change from pull request by [isanwenyu](https://github.com/isanwenyu) to get rid of rare IllegalArgumentException while rendering
5+
* Add `OnRenderListener`, that will be called once, right before document is drawn on the screen
6+
* Add `Configurator.enableAntialiasing()` to improve rendering on low-res screen a little bit (as suggested by [majkimester](majkimester))
7+
* Modify engine to not block UI when big documents are loaded
8+
* Change `Constants` interface and inner interfaces to static public classes, to allow modifying core config values
9+
110
## 2.4.0 (2016-12-30)
211
* Merge pull request by [hansinator85](https://github.com/hansinator85) which allows to enable/disable rendering during scale
312
* Make rendering during scale disabled by default (looks better)

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ repo, where can be developed independently. Version 1.x uses different engine fo
77
so if you don't like 2.x version, try 1.x.__
88

99
Library for displaying PDF documents on Android, with `animations`, `gestures`, `zoom` and `double tap` support.
10-
It is based on [PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid) for decoding PDF files. Works on API 11 and higher.
10+
It is based on [PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid) for decoding PDF files. Works on API 11 (Android 3.0) and higher.
1111
Licensed under Apache License 2.0.
1212

13-
## What's new in 2.4.0?
14-
* Merge pull request by [hansinator85](https://github.com/hansinator85) which allows to enable/disable rendering during scale
15-
* Make rendering during scale disabled by default (looks better)
16-
* Merge pull request by [cesquivias](https://github.com/cesquivias) which replaces RenderingAsyncTask with Handler to simply code and work with testing frameworks
13+
## What's new in 2.5.0?
14+
* Update PdfiumAndroid to 1.6.0, which is based on newest Pdfium from Android 7.1.1. It should fix many rendering and fonts problems
15+
* Add method `pdfView.fitToWidth()`, which called in `OnRenderListener.onInitiallyRendered()` will fit document to width of the screen (inspired by [1stmetro](https://github.com/1stmetro))
16+
* Add change from pull request by [isanwenyu](https://github.com/isanwenyu) to get rid of rare IllegalArgumentException while rendering
17+
* Add `OnRenderListener`, that will be called once, right before document is drawn on the screen
18+
* Add `Configurator.enableAntialiasing()` to improve rendering on low-res screen a little bit (as suggested by [majkimester](majkimester))
19+
* Modify engine to not block UI when big documents are loaded
20+
* Change `Constants` interface and inner interfaces to static public classes, to allow modifying core config values
1721

1822
## Changes in 2.0 API
1923
* `Configurator#defaultPage(int)` and `PDFView#jumpTo(int)` now require page index (i.e. starting from 0)
@@ -28,7 +32,7 @@ Licensed under Apache License 2.0.
2832

2933
Add to _build.gradle_:
3034

31-
`compile 'com.github.barteksc:android-pdf-viewer:2.4.0'`
35+
`compile 'com.github.barteksc:android-pdf-viewer:2.5.0'`
3236

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

@@ -51,30 +55,30 @@ pdfView.fromFile(File)
5155
or
5256
pdfView.fromBytes(byte[])
5357
or
54-
pdfView.fromStream(InputStream)
58+
pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
5559
or
5660
pdfView.fromSource(DocumentSource)
5761
or
5862
pdfView.fromAsset(String)
5963
.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
60-
.enableSwipe(true)
64+
.enableSwipe(true) // allows to block changing pages using swipe
6165
.swipeHorizontal(false)
6266
.enableDoubletap(true)
6367
.defaultPage(0)
64-
.onDraw(onDrawListener)
65-
.onLoad(onLoadCompleteListener)
68+
.onDraw(onDrawListener) // allows to draw something on a provided canvas, above the current page
69+
.onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
6670
.onPageChange(onPageChangeListener)
6771
.onPageScroll(onPageScrollListener)
6872
.onError(onErrorListener)
69-
.enableAnnotationRendering(false)
73+
.onRender(onRenderListener) // called after document is rendered for the first time
74+
.enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
7075
.password(null)
7176
.scrollHandle(null)
77+
.enableAntialiasing(true) // improve rendering a little bit on low-res screens
7278
.load();
7379
```
7480

75-
* `enableSwipe` is optional, it allows you to block changing pages using swipe
7681
* `pages` is optional, it allows you to filter and order the pages of the PDF as you need
77-
* `onDraw` is also optional, and allows you to draw something on a provided canvas, above the current page
7882

7983
## Scroll handle
8084

@@ -138,6 +142,24 @@ available [here](http://ph0b.com/android-studio-gradle-and-ndk-integration/).
138142
Most important section is _Improving multiple APKs creation and versionCode handling with APK Splits_, but whole article is worth reading.
139143
You only need to do this in your application, no need for forking PdfiumAndroid or so.
140144

145+
### Why I cannot open PDF from URL?
146+
Downloading files is long running process which must be aware of Activity lifecycle, must support some configuration,
147+
data cleanup and caching, so creating such module will probably end up as new library.
148+
149+
### How can I show last opened page after configuration change?
150+
You have to store current page number and then set it with `pdfView.defaultPage(page)`, refer to sample app
151+
152+
### How can I fit document to screen width (eg. on orientation change)?
153+
Use this code snippet:
154+
``` java
155+
pdfView.onRender(new OnRenderListener() {
156+
@Override
157+
public void onInitiallyRendered(int pages, float pageWidth, float pageHeight) {
158+
pdfView.fitToWidth(); // optionally pass page number
159+
}
160+
});
161+
```
162+
141163
## One more thing
142164
If you have any suggestions on making this lib better, write me, create issue or write some code and send pull request.
143165

android-pdf-viewer/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ext {
1313
siteUrl = 'https://github.com/barteksc/AndroidPdfViewer'
1414
gitUrl = 'https://github.com/barteksc/AndroidPdfViewer.git'
1515

16-
libraryVersion = '2.4.0'
16+
libraryVersion = '2.5.0'
1717

1818
developerId = 'barteksc'
1919
developerName = 'Bartosz Schiller'
@@ -25,20 +25,20 @@ ext {
2525
}
2626

2727
android {
28-
compileSdkVersion 23
29-
buildToolsVersion '23.0.3'
28+
compileSdkVersion 25
29+
buildToolsVersion '25.0.2'
3030

3131
defaultConfig {
3232
minSdkVersion 11
33-
targetSdkVersion 23
33+
targetSdkVersion 25
3434
versionCode 1
35-
versionName "2.4.0"
35+
versionName "2.5.0"
3636
}
3737

3838
}
3939

4040
dependencies {
41-
compile 'com.github.barteksc:pdfium-android:1.5.0'
41+
compile 'com.github.barteksc:pdfium-android:1.6.0'
4242
}
4343

4444
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DecodingAsyncTask.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ class DecodingAsyncTask extends AsyncTask<Void, Void, Throwable> {
3333
private PdfDocument pdfDocument;
3434
private String password;
3535
private DocumentSource docSource;
36+
private int firstPageIdx;
37+
private int pageWidth;
38+
private int pageHeight;
3639

37-
public DecodingAsyncTask(DocumentSource docSource, String password, PDFView pdfView, PdfiumCore pdfiumCore) {
40+
DecodingAsyncTask(DocumentSource docSource, String password, PDFView pdfView, PdfiumCore pdfiumCore, int firstPageIdx) {
3841
this.docSource = docSource;
42+
this.firstPageIdx = firstPageIdx;
3943
this.cancelled = false;
4044
this.pdfView = pdfView;
4145
this.password = password;
@@ -47,6 +51,10 @@ public DecodingAsyncTask(DocumentSource docSource, String password, PDFView pdfV
4751
protected Throwable doInBackground(Void... params) {
4852
try {
4953
pdfDocument = docSource.createDocument(context, pdfiumCore, password);
54+
// We assume all the pages are the same size
55+
pdfiumCore.openPage(pdfDocument, firstPageIdx);
56+
pageWidth = pdfiumCore.getPageWidth(pdfDocument, firstPageIdx);
57+
pageHeight = pdfiumCore.getPageHeight(pdfDocument, firstPageIdx);
5058
return null;
5159
} catch (Throwable t) {
5260
return t;
@@ -60,7 +68,7 @@ protected void onPostExecute(Throwable t) {
6068
return;
6169
}
6270
if (!cancelled) {
63-
pdfView.loadComplete(pdfDocument);
71+
pdfView.loadComplete(pdfDocument, pageWidth, pageHeight);
6472
}
6573
}
6674

0 commit comments

Comments
 (0)