Skip to content

Commit

Permalink
Add support for links
Browse files Browse the repository at this point in the history
Add support for getting page size without opening page
Add javadoc comments to PdfiumCore methods
Add utility classes for storing size
Update README and CHANGELOG
Update version
  • Loading branch information
barteksc committed Nov 11, 2017
1 parent f396da4 commit 1388325
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.8.0 (2017-11-11)
* Add method for reading links from given page
* Add method for mapping page coordinates to screen coordinates
* Add `PdfiumCore#getPageSize(...)` method, which does not require page to be opened
* Add `Size` and `SizeF` utility classes
* Add javadoc comments to `PdfiumCore`

## 1.7.1 (2017-10-28)
* Merge pull request by [Phaestion](https://github.com/Phaestion) which prevents `UnsatisfiedLinkError`

Expand Down
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,57 @@ Forked for use with [AndroidPdfViewer](https://github.com/barteksc/AndroidPdfVie

API is highly compatible with original version, only additional methods were created.

## What's new in 1.7.0?
* Add rendering bitmap in RGB 565 format, which reduces memory usage (about twice)

1.7.1 merges pull request by [Phaestion](https://github.com/Phaestion) which prevents `UnsatisfiedLinkError`
## What's new in 1.8.0?
* Add method for reading links from given page
* Add method for mapping page coordinates to screen coordinates
* Add `PdfiumCore#getPageSize(...)` method, which does not require page to be opened
* Add `Size` and `SizeF` utility classes
* Add javadoc comments to `PdfiumCore`

## Installation
Add to _build.gradle_:

`compile 'com.github.barteksc:pdfium-android:1.7.1'`
`compile 'com.github.barteksc:pdfium-android:1.8.0'`

Library is available in jcenter and Maven Central repositories.

## Methods inconsistency
Version 1.8.0 added method for getting page size - `PdfiumCore#getPageSize(...)`.
It is important to note, that this method does not require page to be opened. However, there are also
old `PdfiumCore#getPageWidth(...)`, `PdfiumCore#getPageWidthPoint(...)`, `PdfiumCore#getPageHeight()`
and `PdfiumCore#getPageHeightPoint()` which require page to be opened.

This inconsistency will be resolved in next major version, which aims to redesign API.

## Reading links
Version 1.8.0 introduces `PdfiumCore#getPageLinks(PdfDocument, int)` method, which allows to get list
of links from given page. Links are returned as `List` of type `PdfDocument.Link`.
`PdfDocument.Link` holds destination page (may be null), action URI (may be null or empty)
and link bounds in document page coordinates. To map page coordinates to screen coordinates you may use
`PdfiumCore#mapRectToDevice(...)`. See `PdfiumCore#mapPageCoordsToDevice(...)` for parameters description.

Sample usage:
``` java
PdfiumCore core = ...;
PdfDocument document = ...;
int pageIndex = 0;
core.openPage(document, pageIndex);
List<PdfDocument.Link> links = core.getPageLinks(document, pageIndex);
for (PdfDocument.Link link : links) {
RectF mappedRect = core.mapRectToDevice(document, pageIndex, ..., link.getBounds())

if (clickedArea(mappedRect)) {
String uri = link.getUri();
if (link.getDestPageIdx() != null) {
// jump to page
} else if (uri != null && !uri.isEmpty()) {
// open URI using Intent
}
}
}

```

## Simple example
``` java
void openPdf() {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ext {
siteUrl = 'https://github.com/barteksc/PdfiumAndroid'
gitUrl = 'https://github.com/barteksc/PdfiumAndroid.git'

libraryVersion = '1.7.1'
libraryVersion = '1.8.0'

developerId = 'barteksc'
developerName = 'Bartosz Schiller'
Expand All @@ -44,7 +44,7 @@ android {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.7.1"
versionName "1.8.0"
}
buildTypes {
release {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/shockwave/pdfium/PdfDocument.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shockwave.pdfium;

import android.graphics.RectF;
import android.os.ParcelFileDescriptor;
import android.support.v4.util.ArrayMap;

Expand Down Expand Up @@ -75,6 +76,30 @@ public long getPageIdx() {
}
}

public static class Link {
private RectF bounds;
private Integer destPageIdx;
private String uri;

public Link(RectF bounds, Integer destPageIdx, String uri) {
this.bounds = bounds;
this.destPageIdx = destPageIdx;
this.uri = uri;
}

public Integer getDestPageIdx() {
return destPageIdx;
}

public String getUri() {
return uri;
}

public RectF getBounds() {
return bounds;
}
}

/*package*/ PdfDocument() {
}

Expand Down
Loading

0 comments on commit 1388325

Please sign in to comment.