Skip to content

Commit

Permalink
Add opening documents with password
Browse files Browse the repository at this point in the history
Fixed bug with SIGSEV when closing document
Update README and CHANGELOG
Update version
  • Loading branch information
barteksc committed Jul 10, 2016
1 parent ea97a4b commit 7ff43ba
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.0 (2016-07-10)
* added support for opening documents with password
* fixed bug with SIGSEV when closing document

## 1.2.0 (2016-07-06)
* `libmodpdfium` compiled with methods for retrieving bookmarks and metadata
* added `PdfiumCore#getDocumentMeta()` for retrieving document metadata
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ 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.2.0?
* `libmodpdfium` compiled with methods for retrieving bookmarks and metadata
* added `PdfiumCore#getDocumentMeta` for retrieving document metadata
* added `PdfiumCore#getTableOfContents` for reading whole tree of bookmarks
* comment out native rendering debug
## What's new in 1.3.0?
* added support for opening documents with password
* fixed bug with SIGSEV when closing document

## Installation
Add to _build.gradle_:

`compile 'com.github.barteksc:pdfium-android:1.2.0'`
`compile 'com.github.barteksc:pdfium-android:1.3.0'`

Library is available in jcenter and Maven Central repositories.

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.2.0'
libraryVersion = '1.3.0'

developerId = 'barteksc'
developerName = 'Bartosz Schiller'
Expand All @@ -44,7 +44,7 @@ android {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.2.0"
versionName "1.3.0"
}
buildTypes {
release {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/shockwave/pdfium/PdfiumCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PdfiumCore {
System.loadLibrary("jniPdfium");
}

private native long nativeOpenDocument(int fd);
private native long nativeOpenDocument(int fd, String password);

private native void nativeCloseDocument(long docPtr);

Expand Down Expand Up @@ -93,10 +93,14 @@ public static int getNumFd(ParcelFileDescriptor fdObj) {
}

public PdfDocument newDocument(ParcelFileDescriptor fd) throws IOException {
return newDocument(fd, null);
}

public PdfDocument newDocument(ParcelFileDescriptor fd, String password) throws IOException {
PdfDocument document = new PdfDocument();
document.parcelFileDescriptor = fd;
synchronized (lock) {
document.mNativeDocPtr = nativeOpenDocument(getNumFd(fd));
document.mNativeDocPtr = nativeOpenDocument(getNumFd(fd), password);
}

return document;
Expand Down
15 changes: 12 additions & 3 deletions src/main/jni/src/mainJNILib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DocumentFile {
int fileFd;

public:
FPDF_DOCUMENT pdfDocument;
FPDF_DOCUMENT pdfDocument = NULL;
size_t fileSize;

DocumentFile() { initLibraryIfNeed(); }
Expand Down Expand Up @@ -148,7 +148,7 @@ static int getBlock(void* param, unsigned long position, unsigned char* outBuffe
return 1;
}

JNI_FUNC(jlong, PdfiumCore, nativeOpenDocument)(JNI_ARGS, jint fd){
JNI_FUNC(jlong, PdfiumCore, nativeOpenDocument)(JNI_ARGS, jint fd, jstring password){

size_t fileLength = (size_t)getFileSize(fd);
if(fileLength <= 0) {
Expand All @@ -164,7 +164,16 @@ JNI_FUNC(jlong, PdfiumCore, nativeOpenDocument)(JNI_ARGS, jint fd){
loader.m_Param = reinterpret_cast<void*>(intptr_t(fd));
loader.m_GetBlock = &getBlock;

FPDF_DOCUMENT document = FPDF_LoadCustomDocument(&loader, NULL);
const char *cpassword = NULL;
if(password != NULL) {
cpassword = env->GetStringUTFChars(password, NULL);
}

FPDF_DOCUMENT document = FPDF_LoadCustomDocument(&loader, cpassword);

if(cpassword != NULL) {
env->ReleaseStringUTFChars(password, cpassword);
}

if (!document) {
delete docFile;
Expand Down

0 comments on commit 7ff43ba

Please sign in to comment.