Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ src/main/obj
.idea/
.DS_Store
/build
/captures
/captures


# build directories
builddir/*
freetype-*
libpng
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## 2.0.2 (2025-09-27)
* Android 16 (16KB page size support)

## 1.9.2 (2025-03-15)
* Upgrade libfreetype to 2.13.3
* It is a security update, see [here](https://nvd.nist.gov/vuln/detail/CVE-2025-27363) for more details.

## 1.9.1 (2025-01-06)
* Upgrade to latest [PDFium 133.0.6927.0](https://github.com/bblanchon/pdfium-binaries/releases/tag/chromium%2F6927)
* Upgrade `include` folder
* Upgrade `libmodpdfium.so` for `arm32`, `arm64`, `x86` and `x86_64`(`mips` binary not included)
* Use new Pdfium API in `mainJNILib.cpp`
* Add `CMakeLists.txt` for building the PdfiumAndroid library
* Example cmake command
```bash
export ABI=arm64-v8a && \
export NDK_ROOT=PATH/TO/NDK && \
cmake -B builddir/${ANDROID_ABI}/ \
-S . \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_NDK=${NDK_ROOT} \
-DCMAKE_ANDROID_NDK=${NDK_ROOT} \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI} \
-DANDROID_ABI=${ANDROID_ABI} \
-DANDROID_PLATFORM=android-26 \
-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON
```
* Add [libpng v1.6.44](https://github.com/pnggroup/libpng/releases/tag/v1.6.44) and [libfreetype2 v2.10.0](https://download.savannah.gnu.org/releases/freetype/) binaries for building PdfiumAndroid library.
* Add `build.sh` script for building `libpng` and `libfreetype2`

## 1.9.0 (2018-06-29)
* Updated Pdfium library to 7.1.2_r36
* Changed `gnustl_static` to `c++_shared`
Expand Down
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Set the minimum required version of CMake
cmake_minimum_required(VERSION 3.22)

# Set the project name and language
project(jniPdfium LANGUAGES CXX)

message(STATUS "ANDROID_NDK: ${ANDROID_NDK}")
message(STATUS "CMAKE_ANDROID_NDK: ${CMAKE_ANDROID_NDK}")
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_ANDROID_ARCH_ABI: ${CMAKE_ANDROID_ARCH_ABI}")
message(STATUS "ANDROID_ABI: ${ANDROID_ABI}")
message(STATUS "ANDROID_PLATFORM: ${ANDROID_PLATFORM}")


# Add the source files for the library
set(SOURCES
src/main/jni/src/mainJNILib.cpp
src/main/jni/src/util.hpp
)

# Create the shared library target
add_library(jniPdfium SHARED ${SOURCES})

# Specify include directories if necessary
target_include_directories(jniPdfium
PRIVATE ${CMAKE_SOURCE_DIR}/src/main/jni/include
)

# Specify the dependent dynamic libraries to link against
target_link_libraries(jniPdfium
PRIVATE ${CMAKE_SOURCE_DIR}/src/main/jni/lib/${ANDROID_ABI}/libmodft2.so
PRIVATE ${CMAKE_SOURCE_DIR}/src/main/jni/lib/${ANDROID_ABI}/libmodpdfium.so
PRIVATE ${CMAKE_SOURCE_DIR}/src/main/jni/lib/${ANDROID_ABI}/libmodpng.so
PRIVATE ${CMAKE_SOURCE_DIR}/src/main/jni/lib/${ANDROID_ABI}/libc++_shared.so
)

# Specify additional compile options if required
target_compile_options(jniPdfium PRIVATE
-Wall -Wextra -DHAVE_PTHREADS
)

# Specify additional linker flags if necessary
target_link_options(jniPdfium PRIVATE
-Wl,--no-undefined -llog -landroid -ljnigraphics
)
224 changes: 111 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,123 @@
# Pdfium Android binding with Bitmap rendering
Uses pdfium library [from AOSP](https://android.googlesource.com/platform/external/pdfium/)

The demo app (for not modified lib) is [here](https://github.com/mshockwave/PdfiumAndroid-Demo-App)

Forked for use with [AndroidPdfViewer](https://github.com/barteksc/AndroidPdfViewer) project.

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

## What's new in 1.9.0?
* Updated Pdfium library to 7.1.2_r36
* Changed `gnustl_static` to `c++_shared`
* Update Gradle plugins
* Update compile SDK and support library to 26
* Change minimum SDK to 14
* Add support for mips64

## Installation
Add to _build.gradle_:

`compile 'com.github.barteksc:pdfium-android:1.9.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
}
}
}
# PdfiumAndroid - SDK 36 / Android 16 Compatible

This repository is a fork of [meganz/PdfiumAndroid](https://github.com/meganz/PdfiumAndroid), which itself is based on [barteksc/PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid).

## What's New in This Fork

This fork is updated to **SDK 35 / NDK 28** and delivers a working AAR compatible with **Android 15 (16KB page size support)**.

**Version 2.0.2** - Significant updates to the build layer and compatibility improvements warrant a major version bump from the original 1.9.0.

### Key Updates:
- **Android SDK 36** and **NDK 28** compatibility
- **Android Gradle Plugin 8.13.0** support
- **Java 17** requirement (configured via `gradle.properties`)
- **BuildConfig generation** fixed for library modules
- **Native library packaging** corrected in AAR
- **16KB page size support** for Android 15
- **Windows Git Bash** compatible build script

## Requirements

- **Java 17+** (required for AGP 8.13.0+)
- **Android NDK 28.2.13676358**
- **Git Bash** (for Windows users)
- **Ninja build tool** - https://github.com/ninja-build/ninja/releases

## Building the Library

### 1. Build Native Libraries

Remark: you might need to update the `NDK_ROOT` environment variable in the `build.sh` script to point to your NDK (preferrably v28+)

```bash
# Run the build script to compile native libraries
./build.sh

# Optional: Build specific components
./build.sh --build-png --build-freetype

```

## Simple example
``` java
void openPdf() {
ImageView iv = (ImageView) findViewById(R.id.imageView);
ParcelFileDescriptor fd = ...;
int pageNum = 0;
PdfiumCore pdfiumCore = new PdfiumCore(context);
try {
PdfDocument pdfDocument = pdfiumCore.newDocument(fd);

pdfiumCore.openPage(pdfDocument, pageNum);

int width = pdfiumCore.getPageWidthPoint(pdfDocument, pageNum);
int height = pdfiumCore.getPageHeightPoint(pdfDocument, pageNum);

// ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError
// RGB_565 - little worse quality, twice less memory usage
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageNum, 0, 0,
width, height);
//if you need to render annotations and form fields, you can use
//the same method above adding 'true' as last param

iv.setImageBitmap(bitmap);

printInfo(pdfiumCore, pdfDocument);

pdfiumCore.closeDocument(pdfDocument); // important!
} catch(IOException ex) {
ex.printStackTrace();
}
}
### 2. Build AAR

public void printInfo(PdfiumCore core, PdfDocument doc) {
PdfDocument.Meta meta = core.getDocumentMeta(doc);
Log.e(TAG, "title = " + meta.getTitle());
Log.e(TAG, "author = " + meta.getAuthor());
Log.e(TAG, "subject = " + meta.getSubject());
Log.e(TAG, "keywords = " + meta.getKeywords());
Log.e(TAG, "creator = " + meta.getCreator());
Log.e(TAG, "producer = " + meta.getProducer());
Log.e(TAG, "creationDate = " + meta.getCreationDate());
Log.e(TAG, "modDate = " + meta.getModDate());
Remark: you might need to update the 'javaHome' environment variable in the `gradle.properties` file to point to your Java 17 installation

printBookmarksTree(core.getTableOfContents(doc), "-");
```bash
# Build debug AAR
./gradlew assembleDebug

}
# Build release AAR
./gradlew assembleRelease

# Output: build/outputs/aar/PdfiumAndroid-2.0.0-release.aar
```

public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
for (PdfDocument.Bookmark b : tree) {
## Using in Your Project

Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));
### Method 1: Local AAR
1. Copy `PdfiumAndroid-2.0.2-release.aar` to your app's `libs/` folder
2. Add to your app's `build.gradle`:
```groovy
dependencies {
implementation files('libs/PdfiumAndroid-2.0.2-release.aar')
implementation 'androidx.core:core:1.16.0'
}
```

if (b.hasChildren()) {
printBookmarksTree(b.getChildren(), sep + "-");
}
}
### Method 2: JitPack (if published)
```groovy
repositories {
maven { url 'https://jitpack.io' }
}

dependencies {
implementation 'com.github.aiuspaktyn:PdfiumAndroid:2.0.2'
}
```

## Usage Example

```java
import com.shockwave.pdfium.PdfiumCore;
import com.shockwave.pdfium.PdfDocument;

// Initialize
PdfiumCore pdfiumCore = new PdfiumCore(context);

// Open PDF
PdfDocument pdfDocument = pdfiumCore.newDocument(parcelFileDescriptor);

// Use the library...
```
## Build native part
Go to `PROJECT_PATH/src/main/jni` and run command `$ ndk-build`.
This step may be executed only once, every future `.aar` build will use generated libs.

## Changes Made

### Build System Updates
- Updated `build.gradle` for AGP 8.13.0 compatibility
- Added `buildFeatures { buildConfig = true }`
- Added `buildConfigField` for `VERSION_NAME`
- Fixed `jniLibs.srcDir` path for native libraries
- Configured Java 17 in `gradle.properties`

### Native Library Fixes
- Updated `build.sh` to use ninja (for windows)
- Updated `build.sh` to copy `libjniPdfium.so` to correct location
- Fixed AAR packaging to include all required `.so` files
- Ensured compatibility with NDK 28

### Android 15 Compatibility
- Added 16KB page size support via `ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON`
- Updated manifest and build configuration

## Original Credits

- Original work: [barteksc/PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid)
- 16KB page size foundation: [meganz/PdfiumAndroid](https://github.com/meganz/PdfiumAndroid)
- Upgrade to [PDFium 133.0.6927.0](https://github.com/bblanchon/pdfium-binaries/releases/tag/chromium%2F6927)
- Add a `CMakeLists.txt` for building PdfiumAndroid `.so` file.
- Update [libpng v1.6.44](https://github.com/pnggroup/libpng/releases/tag/v1.6.44) and [libfreetype2 v2.10.0](https://download.savannah.gnu.org/releases/freetype/) binaries for building PdfiumAndroid library.

## License

Same as original project - check the LICENSE file.
Loading