├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── proguard-rules.pro ├── settings.gradle └── src └── main ├── AndroidManifest.xml ├── cpp ├── CMakeLists.txt ├── include │ ├── cpp │ │ ├── fpdf_deleters.h │ │ └── fpdf_scopers.h │ ├── fpdf_annot.h │ ├── fpdf_attachment.h │ ├── fpdf_catalog.h │ ├── fpdf_dataavail.h │ ├── fpdf_doc.h │ ├── fpdf_edit.h │ ├── fpdf_ext.h │ ├── fpdf_flatten.h │ ├── fpdf_formfill.h │ ├── fpdf_fwlevent.h │ ├── fpdf_javascript.h │ ├── fpdf_ppo.h │ ├── fpdf_progressive.h │ ├── fpdf_save.h │ ├── fpdf_searchex.h │ ├── fpdf_signature.h │ ├── fpdf_structtree.h │ ├── fpdf_sysfontinfo.h │ ├── fpdf_text.h │ ├── fpdf_thumbnail.h │ ├── fpdf_transformpage.h │ ├── fpdfview.h │ └── utils │ │ ├── Errors.h │ │ └── Mutex.h ├── mainJNILib.cpp └── util.hpp ├── java └── com │ └── shockwave │ └── pdfium │ ├── PdfDocument.java │ ├── PdfPasswordException.java │ ├── PdfiumCore.java │ └── util │ ├── Size.java │ └── SizeF.java └── jniLibs ├── arm64-v8a └── libpdfium.cr.so ├── armeabi-v7a └── libpdfium.cr.so ├── x86 └── libpdfium.cr.so └── x86_64 └── libpdfium.cr.so /.gitignore: -------------------------------------------------------------------------------- 1 | src/main/libs 2 | src/main/obj 3 | 4 | *.iml 5 | .gradle 6 | /local.properties 7 | .idea/ 8 | .DS_Store 9 | .cxx 10 | /build 11 | /captures -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.9.4 (2024-03-19) 2 | * Fix issue for the newest Android devices with API 34+ 3 | 4 | ## 1.9.3 (2024-03-18) 5 | * Update Gradle plugins and configurations 6 | * Change minimum SDK to 21 7 | * Update pdfium libs 8 | 9 | ## 1.9.1 (2024-03-10) 10 | * Update Gradle plugins and configurations 11 | * Update compile sdk to 34 12 | * Change minimum SDK to 23 13 | * Remove support-v4 library 14 | * Drop support for mips 15 | * Update pdfium libs and refactor to cmake 16 | 17 | ## 1.9.0 (2018-06-29) 18 | * Updated Pdfium library to 7.1.2_r36 19 | * Changed `gnustl_static` to `c++_shared` 20 | * Update Gradle plugins 21 | * Update compile SDK and support library to 26 22 | * Change minimum SDK to 14 23 | * Add support for mips64 24 | 25 | ## 1.8.2 (2017-12-15) 26 | * Merge pull request by [mcsong](https://github.com/mcsong) fixing potential NPE when getting links 27 | 28 | ## 1.8.1 (2017-11-15) 29 | * Handle `PdfiumCore#getPageSize()` errors and return `Size(0, 0)` 30 | 31 | ## 1.8.0 (2017-11-11) 32 | * Add method for reading links from given page 33 | * Add method for mapping page coordinates to screen coordinates 34 | * Add `PdfiumCore#getPageSize(...)` method, which does not require page to be opened 35 | * Add `Size` and `SizeF` utility classes 36 | * Add javadoc comments to `PdfiumCore` 37 | 38 | ## 1.7.1 (2017-10-28) 39 | * Merge pull request by [Phaestion](https://github.com/Phaestion) which prevents `UnsatisfiedLinkError` 40 | 41 | ## 1.7.0 (2017-06-21) 42 | * Add rendering bitmap in RGB 565 format, which reduces memory usage (about twice) 43 | 44 | ## 1.6.1 (2017-06-09) 45 | * Fix bug from 1.6.0 - not embedded fonts was not rendered 46 | 47 | ## 1.6.0 (2017-03-22) 48 | * Pdfium updated to newest version, from Android 7.1.1. 49 | It should fix many rendering issues and (thanks to freetype support) fix problems with fonts. 50 | 51 | ## 1.5.0 (2016-11-18) 52 | * Add method `PdfiumCore#newDocument(byte[])` for reading PDF documents from memory 53 | * Cleanup AndroidManifest.xml to solve problems with manifest merger 54 | 55 | ## 1.4.0 (2016-07-12) 56 | * merge pull request by [usef](https://github.com/usef) with added support for rendering annotations. Due to limitations of _Pdfium_, messages from comments cannot be read and are rendered only as speech balloons. 57 | 58 | ## 1.3.1 (2016-07-11) 59 | * `PdfiumCore#newDocument()` may throw `PdfPasswordException` to help with recognition of password requirement or incorrect password. 60 | 61 | ## 1.3.0 (2016-07-10) 62 | * added support for opening documents with password 63 | * fixed bug with SIGSEV when closing document 64 | 65 | ## 1.2.0 (2016-07-06) 66 | * `libmodpdfium` compiled with methods for retrieving bookmarks and metadata 67 | * added `PdfiumCore#getDocumentMeta()` for retrieving document metadata 68 | * added `PdfiumCore#getTableOfContents()` for reading whole tree of bookmarks 69 | * comment out native rendering debug 70 | 71 | ## 1.1.0 (2016-06-27) 72 | * fixed rendering multiple PDFs at the same time thanks to synchronization between instances 73 | * compile Pdfium with SONAME `libmodpdfium` to prevent loading `libpdfium` from Lollipop and higher 74 | * `newDocument()` requires `ParcelFileDescriptor` instead of `FileDescriptor` to keep file descriptor open 75 | * changed method of loading PDFs, which should be more stable 76 | 77 | ## 1.0.3 (2016-06-17) 78 | * probably fixed bug when pdf should open as normal but was throwing exception 79 | * added much more descriptive exception messages 80 | 81 | ## 1.0.2 (2016-06-04) 82 | * `newDocument()` throws IOException 83 | 84 | ## 1.0.1 (2016-06-04) 85 | * fix loading `libpdfium` on devices with < Lollipop 86 | 87 | ## Initial changes 88 | * Added method for rendering PDF page on bitmap 89 | 90 | ``` java 91 | void renderPageBitmap(PdfDocument doc, Bitmap bitmap, int pageIndex, 92 | int startX, int startY, int drawSizeX, int drawSizeY); 93 | ``` 94 | * Added methods to get width and height of page in points (1/72") (like in `PdfRenderer.Page` class): 95 | * `int getPageWidthPoint(PdfDocument doc, int index);` 96 | * `int getPageHeightPoint(PdfDocument doc, int index);` 97 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Original work Copyright 2015 Bekket McClane 2 | Modified work Copyright 2016 Bartosz Schiller 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | // Copyright 2014 PDFium Authors. All rights reserved. 17 | // 18 | // Redistribution and use in source and binary forms, with or without 19 | // modification, are permitted provided that the following conditions are 20 | // met: 21 | // 22 | // * Redistributions of source code must retain the above copyright 23 | // notice, this list of conditions and the following disclaimer. 24 | // * Redistributions in binary form must reproduce the above 25 | // copyright notice, this list of conditions and the following disclaimer 26 | // in the documentation and/or other materials provided with the 27 | // distribution. 28 | // * Neither the name of Google Inc. nor the names of its 29 | // contributors may be used to endorse or promote products derived from 30 | // this software without specific prior written permission. 31 | // 32 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 35 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 37 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 38 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 39 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 40 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 41 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 42 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The purpose is to remove old support libraries so we no longer need to use jetifier. 2 | 3 | It will be used with the forked [AndroidPdFViewer](https://github.com/lion1988dev/AndroidPdfViewer) 4 | 5 | ## What's new in 1.9.4 6 | * Fix issue for the newest Android devices with API 34+ 7 | 8 | ## What's new in 1.9.3 9 | * Update Gradle plugins and configurations 10 | * Change minimum SDK to 21 11 | * Update pdfium libs 12 | 13 | ## What's new in 1.9.1 14 | * Update Gradle plugins and configurations 15 | * Update compile sdk to 34 16 | * Change minimum SDK to 23 17 | * Remove support-v4 library 18 | * Drop support for mips 19 | * Update pdfium libs and refactor to cmake 20 | 21 | ## What's new in 1.9.0? 22 | * Updated Pdfium library to 7.1.2_r36 23 | * Changed `gnustl_static` to `c++_shared` 24 | * Update Gradle plugins 25 | * Update compile SDK and support library to 26 26 | * Change minimum SDK to 14 27 | * Add support for mips64 28 | 29 | ## Installation 30 | Add to the root _build.gradle_: 31 | 32 | ```groovy 33 | dependencyResolutionManagement { 34 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 35 | repositories { 36 | mavenCentral() 37 | maven { url 'https://jitpack.io' } 38 | } 39 | } 40 | ``` 41 | 42 | Add to the app _build.gradle_: 43 | 44 | `implementation 'com.github.lion1988dev:PdfiumAndroid:1.9.4'` 45 | 46 | Library is available in jcenter and Maven Central repositories. 47 | 48 | ## Methods inconsistency 49 | Version 1.8.0 added method for getting page size - `PdfiumCore#getPageSize(...)`. 50 | It is important to note, that this method does not require page to be opened. However, there are also 51 | old `PdfiumCore#getPageWidth(...)`, `PdfiumCore#getPageWidthPoint(...)`, `PdfiumCore#getPageHeight()` 52 | and `PdfiumCore#getPageHeightPoint()` which require page to be opened. 53 | 54 | This inconsistency will be resolved in next major version, which aims to redesign API. 55 | 56 | ## Reading links 57 | Version 1.8.0 introduces `PdfiumCore#getPageLinks(PdfDocument, int)` method, which allows to get list 58 | of links from given page. Links are returned as `List` of type `PdfDocument.Link`. 59 | `PdfDocument.Link` holds destination page (may be null), action URI (may be null or empty) 60 | and link bounds in document page coordinates. To map page coordinates to screen coordinates you may use 61 | `PdfiumCore#mapRectToDevice(...)`. See `PdfiumCore#mapPageCoordsToDevice(...)` for parameters description. 62 | 63 | Sample usage: 64 | ``` java 65 | PdfiumCore core = ...; 66 | PdfDocument document = ...; 67 | int pageIndex = 0; 68 | core.openPage(document, pageIndex); 69 | List links = core.getPageLinks(document, pageIndex); 70 | for (PdfDocument.Link link : links) { 71 | RectF mappedRect = core.mapRectToDevice(document, pageIndex, ..., link.getBounds()) 72 | 73 | if (clickedArea(mappedRect)) { 74 | String uri = link.getUri(); 75 | if (link.getDestPageIdx() != null) { 76 | // jump to page 77 | } else if (uri != null && !uri.isEmpty()) { 78 | // open URI using Intent 79 | } 80 | } 81 | } 82 | 83 | ``` 84 | 85 | ## Simple example 86 | ``` java 87 | void openPdf() { 88 | ImageView iv = (ImageView) findViewById(R.id.imageView); 89 | ParcelFileDescriptor fd = ...; 90 | int pageNum = 0; 91 | PdfiumCore pdfiumCore = new PdfiumCore(context); 92 | try { 93 | PdfDocument pdfDocument = pdfiumCore.newDocument(fd); 94 | 95 | pdfiumCore.openPage(pdfDocument, pageNum); 96 | 97 | int width = pdfiumCore.getPageWidthPoint(pdfDocument, pageNum); 98 | int height = pdfiumCore.getPageHeightPoint(pdfDocument, pageNum); 99 | 100 | // ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError 101 | // RGB_565 - little worse quality, twice less memory usage 102 | Bitmap bitmap = Bitmap.createBitmap(width, height, 103 | Bitmap.Config.RGB_565); 104 | pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageNum, 0, 0, 105 | width, height); 106 | //if you need to render annotations and form fields, you can use 107 | //the same method above adding 'true' as last param 108 | 109 | iv.setImageBitmap(bitmap); 110 | 111 | printInfo(pdfiumCore, pdfDocument); 112 | 113 | pdfiumCore.closeDocument(pdfDocument); // important! 114 | } catch(IOException ex) { 115 | ex.printStackTrace(); 116 | } 117 | } 118 | 119 | public void printInfo(PdfiumCore core, PdfDocument doc) { 120 | PdfDocument.Meta meta = core.getDocumentMeta(doc); 121 | Log.e(TAG, "title = " + meta.getTitle()); 122 | Log.e(TAG, "author = " + meta.getAuthor()); 123 | Log.e(TAG, "subject = " + meta.getSubject()); 124 | Log.e(TAG, "keywords = " + meta.getKeywords()); 125 | Log.e(TAG, "creator = " + meta.getCreator()); 126 | Log.e(TAG, "producer = " + meta.getProducer()); 127 | Log.e(TAG, "creationDate = " + meta.getCreationDate()); 128 | Log.e(TAG, "modDate = " + meta.getModDate()); 129 | 130 | printBookmarksTree(core.getTableOfContents(doc), "-"); 131 | 132 | } 133 | 134 | public void printBookmarksTree(List tree, String sep) { 135 | for (PdfDocument.Bookmark b : tree) { 136 | 137 | Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx())); 138 | 139 | if (b.hasChildren()) { 140 | printBookmarksTree(b.getChildren(), sep + "-"); 141 | } 142 | } 143 | } 144 | 145 | ``` 146 | ## Build native part 147 | Go to `PROJECT_PATH/src/main/jni` and run command `$ ndk-build`. 148 | This step may be executed only once, every future `.aar` build will use generated libs. 149 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' version '8.3.0' 3 | id 'maven-publish' 4 | } 5 | 6 | ext { 7 | tools = [ 8 | minSdk : 21, 9 | targetSdk : 34, 10 | compileSdk : 34, 11 | versionCode: 3, 12 | versionName: '1.9.4' 13 | ] 14 | } 15 | 16 | group "com.github.lion1988dev" 17 | 18 | android { 19 | namespace "com.shockwave.pdfium" 20 | 21 | compileSdk rootProject.tools.compileSdk 22 | 23 | defaultConfig { 24 | minSdkVersion rootProject.tools.minSdkVersion 25 | targetSdk rootProject.tools.targetSdk 26 | 27 | versionCode rootProject.tools.versionCode 28 | versionName "${rootProject.tools.versionName}" 29 | 30 | buildConfigField 'String', 'VERSION_NAME', "\"${defaultConfig.versionName}\"" 31 | 32 | externalNativeBuild { 33 | cmake { 34 | cppFlags "" 35 | } 36 | } 37 | } 38 | 39 | buildFeatures { 40 | buildConfig = true 41 | } 42 | 43 | buildTypes { 44 | release { 45 | minifyEnabled false 46 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 47 | } 48 | } 49 | 50 | compileOptions { 51 | sourceCompatibility JavaVersion.VERSION_17 52 | targetCompatibility JavaVersion.VERSION_17 53 | } 54 | 55 | publishing { 56 | publishing { 57 | singleVariant("release") { 58 | withSourcesJar() 59 | withJavadocJar() 60 | } 61 | } 62 | } 63 | 64 | ndkVersion '25.2.9519653' 65 | 66 | externalNativeBuild { 67 | cmake { 68 | path "src/main/cpp/CMakeLists.txt" 69 | version "3.22.1" 70 | } 71 | } 72 | 73 | sourceSets { 74 | main { 75 | jniLibs.srcDirs = ['src/main/jniLibs'] 76 | } 77 | } 78 | } 79 | 80 | dependencies { 81 | implementation 'androidx.appcompat:appcompat:1.6.1' 82 | } 83 | 84 | publishing { 85 | publications { 86 | release(MavenPublication) { 87 | groupId = 'com.github.lion1988dev' 88 | artifactId = 'PdfiumAndroid' 89 | version = "1.9.4" 90 | 91 | afterEvaluate { 92 | from components.release 93 | } 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | android.enableJetifier=false 2 | android.useAndroidX=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lion1988dev/PdfiumAndroid/5b0980bd396b801d4bc2a79c4833298a811b63e1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 09 21:57:57 EET 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 -------------------------------------------------------------------------------- /proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/mac/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | 9 | dependencyResolutionManagement { 10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 11 | repositories { 12 | google() 13 | mavenCentral() 14 | } 15 | } 16 | 17 | rootProject.name = "PdfiumAndroid" 18 | -------------------------------------------------------------------------------- /src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about using CMake with Android Studio, read the 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html 3 | 4 | # Sets the minimum version of CMake required to build the native library. 5 | 6 | cmake_minimum_required(VERSION 3.22.1) 7 | 8 | # Declares and names the project. 9 | 10 | project("pdfiumandroid") 11 | 12 | # Creates and names a library, sets it as either STATIC 13 | # or SHARED, and provides the relative paths to its source code. 14 | # You can define multiple libraries, and CMake builds them for you. 15 | # Gradle automatically packages shared libraries with your APK. 16 | 17 | add_library( # Sets the name of the library. 18 | pdfiumandroid 19 | 20 | # Sets the library as a shared library. 21 | SHARED 22 | 23 | # Provides a relative path to your source file(s). 24 | mainJNILib.cpp) 25 | 26 | # Searches for a specified prebuilt library and stores the path as a 27 | # variable. Because CMake includes system libraries in the search path by 28 | # default, you only need to specify the name of the public NDK library 29 | # you want to add. CMake verifies that the library exists before 30 | # completing its build. 31 | 32 | find_library( # Sets the name of the path variable. 33 | log-lib 34 | 35 | # Specifies the name of the NDK library that 36 | # you want CMake to locate. 37 | log) 38 | 39 | find_library( # Sets the name of the path variable. 40 | android-lib 41 | 42 | # Specifies the name of the NDK library that 43 | # you want CMake to locate. 44 | android) 45 | 46 | find_library( # Sets the name of the path variable. 47 | jnigraphics-lib 48 | 49 | # Specifies the name of the NDK library that 50 | # you want CMake to locate. 51 | jnigraphics) 52 | 53 | # Specifies libraries CMake should link to your target library. You 54 | # can link multiple libraries, such as libraries you define in this 55 | # build script, prebuilt third-party libraries, or system libraries. 56 | 57 | target_link_libraries( # Specifies the target library. 58 | pdfiumandroid 59 | 60 | libpdfium 61 | 62 | # Links the target library to the log library 63 | # included in the NDK. 64 | ${log-lib} 65 | ${android-lib} 66 | ${jnigraphics-lib} 67 | ) 68 | 69 | 70 | add_library( libpdfium SHARED IMPORTED ) 71 | 72 | set_target_properties( libpdfium PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libpdfium.cr.so) 73 | -------------------------------------------------------------------------------- /src/main/cpp/include/cpp/fpdf_deleters.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_CPP_FPDF_DELETERS_H_ 6 | #define PUBLIC_CPP_FPDF_DELETERS_H_ 7 | 8 | #include "../fpdf_annot.h" 9 | #include "../fpdf_dataavail.h" 10 | #include "../fpdf_edit.h" 11 | #include "../fpdf_formfill.h" 12 | #include "../fpdf_javascript.h" 13 | #include "../fpdf_structtree.h" 14 | #include "../fpdf_text.h" 15 | #include "../fpdf_transformpage.h" 16 | #include "../fpdfview.h" 17 | 18 | // Custom deleters for using FPDF_* types with std::unique_ptr<>. 19 | 20 | struct FPDFAnnotationDeleter { 21 | inline void operator()(FPDF_ANNOTATION annot) { FPDFPage_CloseAnnot(annot); } 22 | }; 23 | 24 | struct FPDFAvailDeleter { 25 | inline void operator()(FPDF_AVAIL avail) { FPDFAvail_Destroy(avail); } 26 | }; 27 | 28 | struct FPDFBitmapDeleter { 29 | inline void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); } 30 | }; 31 | 32 | struct FPDFClipPathDeleter { 33 | inline void operator()(FPDF_CLIPPATH clip_path) { 34 | FPDF_DestroyClipPath(clip_path); 35 | } 36 | }; 37 | 38 | struct FPDFDocumentDeleter { 39 | inline void operator()(FPDF_DOCUMENT doc) { FPDF_CloseDocument(doc); } 40 | }; 41 | 42 | struct FPDFFontDeleter { 43 | inline void operator()(FPDF_FONT font) { FPDFFont_Close(font); } 44 | }; 45 | 46 | struct FPDFFormHandleDeleter { 47 | inline void operator()(FPDF_FORMHANDLE form) { 48 | FPDFDOC_ExitFormFillEnvironment(form); 49 | } 50 | }; 51 | 52 | struct FPDFJavaScriptActionDeleter { 53 | inline void operator()(FPDF_JAVASCRIPT_ACTION javascript) { 54 | FPDFDoc_CloseJavaScriptAction(javascript); 55 | } 56 | }; 57 | 58 | struct FPDFPageDeleter { 59 | inline void operator()(FPDF_PAGE page) { FPDF_ClosePage(page); } 60 | }; 61 | 62 | struct FPDFPageLinkDeleter { 63 | inline void operator()(FPDF_PAGELINK pagelink) { 64 | FPDFLink_CloseWebLinks(pagelink); 65 | } 66 | }; 67 | 68 | struct FPDFPageObjectDeleter { 69 | inline void operator()(FPDF_PAGEOBJECT object) { 70 | FPDFPageObj_Destroy(object); 71 | } 72 | }; 73 | 74 | struct FPDFStructTreeDeleter { 75 | inline void operator()(FPDF_STRUCTTREE tree) { FPDF_StructTree_Close(tree); } 76 | }; 77 | 78 | struct FPDFTextFindDeleter { 79 | inline void operator()(FPDF_SCHHANDLE handle) { FPDFText_FindClose(handle); } 80 | }; 81 | 82 | struct FPDFTextPageDeleter { 83 | inline void operator()(FPDF_TEXTPAGE text) { FPDFText_ClosePage(text); } 84 | }; 85 | 86 | #endif // PUBLIC_CPP_FPDF_DELETERS_H_ 87 | -------------------------------------------------------------------------------- /src/main/cpp/include/cpp/fpdf_scopers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_CPP_FPDF_SCOPERS_H_ 6 | #define PUBLIC_CPP_FPDF_SCOPERS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "fpdf_deleters.h" 12 | 13 | // Versions of FPDF types that clean up the object at scope exit. 14 | 15 | using ScopedFPDFAnnotation = 16 | std::unique_ptr::type, 17 | FPDFAnnotationDeleter>; 18 | 19 | using ScopedFPDFAvail = 20 | std::unique_ptr::type, FPDFAvailDeleter>; 21 | 22 | using ScopedFPDFBitmap = 23 | std::unique_ptr::type, FPDFBitmapDeleter>; 24 | 25 | using ScopedFPDFClipPath = 26 | std::unique_ptr::type, 27 | FPDFClipPathDeleter>; 28 | 29 | using ScopedFPDFDocument = 30 | std::unique_ptr::type, 31 | FPDFDocumentDeleter>; 32 | 33 | using ScopedFPDFFont = 34 | std::unique_ptr::type, FPDFFontDeleter>; 35 | 36 | using ScopedFPDFFormHandle = 37 | std::unique_ptr::type, 38 | FPDFFormHandleDeleter>; 39 | 40 | using ScopedFPDFJavaScriptAction = 41 | std::unique_ptr::type, 42 | FPDFJavaScriptActionDeleter>; 43 | 44 | using ScopedFPDFPage = 45 | std::unique_ptr::type, FPDFPageDeleter>; 46 | 47 | using ScopedFPDFPageLink = 48 | std::unique_ptr::type, 49 | FPDFPageLinkDeleter>; 50 | 51 | using ScopedFPDFPageObject = 52 | std::unique_ptr::type, 53 | FPDFPageObjectDeleter>; 54 | 55 | using ScopedFPDFStructTree = 56 | std::unique_ptr::type, 57 | FPDFStructTreeDeleter>; 58 | 59 | using ScopedFPDFTextFind = 60 | std::unique_ptr::type, 61 | FPDFTextFindDeleter>; 62 | 63 | using ScopedFPDFTextPage = 64 | std::unique_ptr::type, 65 | FPDFTextPageDeleter>; 66 | 67 | #endif // PUBLIC_CPP_FPDF_SCOPERS_H_ 68 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_attachment.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_FPDF_ATTACHMENT_H_ 6 | #define PUBLIC_FPDF_ATTACHMENT_H_ 7 | 8 | // NOLINTNEXTLINE(build/include) 9 | #include "fpdfview.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif // __cplusplus 14 | 15 | // Experimental API. 16 | // Get the number of embedded files in |document|. 17 | // 18 | // document - handle to a document. 19 | // 20 | // Returns the number of embedded files in |document|. 21 | FPDF_EXPORT int FPDF_CALLCONV 22 | FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document); 23 | 24 | // Experimental API. 25 | // Add an embedded file with |name| in |document|. If |name| is empty, or if 26 | // |name| is the name of a existing embedded file in |document|, or if 27 | // |document|'s embedded file name tree is too deep (i.e. |document| has too 28 | // many embedded files already), then a new attachment will not be added. 29 | // 30 | // document - handle to a document. 31 | // name - name of the new attachment. 32 | // 33 | // Returns a handle to the new attachment object, or NULL on failure. 34 | FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV 35 | FPDFDoc_AddAttachment(FPDF_DOCUMENT document, FPDF_WIDESTRING name); 36 | 37 | // Experimental API. 38 | // Get the embedded attachment at |index| in |document|. Note that the returned 39 | // attachment handle is only valid while |document| is open. 40 | // 41 | // document - handle to a document. 42 | // index - the index of the requested embedded file. 43 | // 44 | // Returns the handle to the attachment object, or NULL on failure. 45 | FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV 46 | FPDFDoc_GetAttachment(FPDF_DOCUMENT document, int index); 47 | 48 | // Experimental API. 49 | // Delete the embedded attachment at |index| in |document|. Note that this does 50 | // not remove the attachment data from the PDF file; it simply removes the 51 | // file's entry in the embedded files name tree so that it does not appear in 52 | // the attachment list. This behavior may change in the future. 53 | // 54 | // document - handle to a document. 55 | // index - the index of the embedded file to be deleted. 56 | // 57 | // Returns true if successful. 58 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 59 | FPDFDoc_DeleteAttachment(FPDF_DOCUMENT document, int index); 60 | 61 | // Experimental API. 62 | // Get the name of the |attachment| file. |buffer| is only modified if |buflen| 63 | // is longer than the length of the file name. On errors, |buffer| is unmodified 64 | // and the returned length is 0. 65 | // 66 | // attachment - handle to an attachment. 67 | // buffer - buffer for holding the file name, encoded in UTF-16LE. 68 | // buflen - length of the buffer in bytes. 69 | // 70 | // Returns the length of the file name in bytes. 71 | FPDF_EXPORT unsigned long FPDF_CALLCONV 72 | FPDFAttachment_GetName(FPDF_ATTACHMENT attachment, 73 | FPDF_WCHAR* buffer, 74 | unsigned long buflen); 75 | 76 | // Experimental API. 77 | // Check if the params dictionary of |attachment| has |key| as a key. 78 | // 79 | // attachment - handle to an attachment. 80 | // key - the key to look for, encoded in UTF-8. 81 | // 82 | // Returns true if |key| exists. 83 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 84 | FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, FPDF_BYTESTRING key); 85 | 86 | // Experimental API. 87 | // Get the type of the value corresponding to |key| in the params dictionary of 88 | // the embedded |attachment|. 89 | // 90 | // attachment - handle to an attachment. 91 | // key - the key to look for, encoded in UTF-8. 92 | // 93 | // Returns the type of the dictionary value. 94 | FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV 95 | FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_BYTESTRING key); 96 | 97 | // Experimental API. 98 | // Set the string value corresponding to |key| in the params dictionary of the 99 | // embedded file |attachment|, overwriting the existing value if any. The value 100 | // type should be FPDF_OBJECT_STRING after this function call succeeds. 101 | // 102 | // attachment - handle to an attachment. 103 | // key - the key to the dictionary entry, encoded in UTF-8. 104 | // value - the string value to be set, encoded in UTF-16LE. 105 | // 106 | // Returns true if successful. 107 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 108 | FPDFAttachment_SetStringValue(FPDF_ATTACHMENT attachment, 109 | FPDF_BYTESTRING key, 110 | FPDF_WIDESTRING value); 111 | 112 | // Experimental API. 113 | // Get the string value corresponding to |key| in the params dictionary of the 114 | // embedded file |attachment|. |buffer| is only modified if |buflen| is longer 115 | // than the length of the string value. Note that if |key| does not exist in the 116 | // dictionary or if |key|'s corresponding value in the dictionary is not a 117 | // string (i.e. the value is not of type FPDF_OBJECT_STRING or 118 | // FPDF_OBJECT_NAME), then an empty string would be copied to |buffer| and the 119 | // return value would be 2. On other errors, nothing would be added to |buffer| 120 | // and the return value would be 0. 121 | // 122 | // attachment - handle to an attachment. 123 | // key - the key to the requested string value, encoded in UTF-8. 124 | // buffer - buffer for holding the string value encoded in UTF-16LE. 125 | // buflen - length of the buffer in bytes. 126 | // 127 | // Returns the length of the dictionary value string in bytes. 128 | FPDF_EXPORT unsigned long FPDF_CALLCONV 129 | FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment, 130 | FPDF_BYTESTRING key, 131 | FPDF_WCHAR* buffer, 132 | unsigned long buflen); 133 | 134 | // Experimental API. 135 | // Set the file data of |attachment|, overwriting the existing file data if any. 136 | // The creation date and checksum will be updated, while all other dictionary 137 | // entries will be deleted. Note that only contents with |len| smaller than 138 | // INT_MAX is supported. 139 | // 140 | // attachment - handle to an attachment. 141 | // contents - buffer holding the file data to write to |attachment|. 142 | // len - length of file data in bytes. 143 | // 144 | // Returns true if successful. 145 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 146 | FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment, 147 | FPDF_DOCUMENT document, 148 | const void* contents, 149 | unsigned long len); 150 | 151 | // Experimental API. 152 | // Get the file data of |attachment|. 153 | // When the attachment file data is readable, true is returned, and |out_buflen| 154 | // is updated to indicate the file data size. |buffer| is only modified if 155 | // |buflen| is non-null and long enough to contain the entire file data. Callers 156 | // must check both the return value and the input |buflen| is no less than the 157 | // returned |out_buflen| before using the data. 158 | // 159 | // Otherwise, when the attachment file data is unreadable or when |out_buflen| 160 | // is null, false is returned and |buffer| and |out_buflen| remain unmodified. 161 | // 162 | // attachment - handle to an attachment. 163 | // buffer - buffer for holding the file data from |attachment|. 164 | // buflen - length of the buffer in bytes. 165 | // out_buflen - pointer to the variable that will receive the minimum buffer 166 | // size to contain the file data of |attachment|. 167 | // 168 | // Returns true on success, false otherwise. 169 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 170 | FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, 171 | void* buffer, 172 | unsigned long buflen, 173 | unsigned long* out_buflen); 174 | 175 | #ifdef __cplusplus 176 | } // extern "C" 177 | #endif // __cplusplus 178 | 179 | #endif // PUBLIC_FPDF_ATTACHMENT_H_ 180 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_catalog.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_FPDF_CATALOG_H_ 6 | #define PUBLIC_FPDF_CATALOG_H_ 7 | 8 | // NOLINTNEXTLINE(build/include) 9 | #include "fpdfview.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif // __cplusplus 14 | 15 | /** 16 | * Experimental API. 17 | * 18 | * Determine if |document| represents a tagged PDF. 19 | * 20 | * For the definition of tagged PDF, See (see 10.7 "Tagged PDF" in PDF 21 | * Reference 1.7). 22 | * 23 | * document - handle to a document. 24 | * 25 | * Returns |true| iff |document| is a tagged PDF. 26 | */ 27 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 28 | FPDFCatalog_IsTagged(FPDF_DOCUMENT document); 29 | 30 | #ifdef __cplusplus 31 | } // extern "C" 32 | #endif // __cplusplus 33 | 34 | #endif // PUBLIC_FPDF_CATALOG_H_ 35 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_dataavail.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_DATAAVAIL_H_ 8 | #define PUBLIC_FPDF_DATAAVAIL_H_ 9 | 10 | #include 11 | 12 | // NOLINTNEXTLINE(build/include) 13 | #include "fpdfview.h" 14 | 15 | #define PDF_LINEARIZATION_UNKNOWN -1 16 | #define PDF_NOT_LINEARIZED 0 17 | #define PDF_LINEARIZED 1 18 | 19 | #define PDF_DATA_ERROR -1 20 | #define PDF_DATA_NOTAVAIL 0 21 | #define PDF_DATA_AVAIL 1 22 | 23 | #define PDF_FORM_ERROR -1 24 | #define PDF_FORM_NOTAVAIL 0 25 | #define PDF_FORM_AVAIL 1 26 | #define PDF_FORM_NOTEXIST 2 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif // __cplusplus 31 | 32 | // Interface for checking whether sections of the file are available. 33 | typedef struct _FX_FILEAVAIL { 34 | // Version number of the interface. Must be 1. 35 | int version; 36 | 37 | // Reports if the specified data section is currently available. A section is 38 | // available if all bytes in the section are available. 39 | // 40 | // Interface Version: 1 41 | // Implementation Required: Yes 42 | // 43 | // pThis - pointer to the interface structure. 44 | // offset - the offset of the data section in the file. 45 | // size - the size of the data section. 46 | // 47 | // Returns true if the specified data section at |offset| of |size| 48 | // is available. 49 | FPDF_BOOL (*IsDataAvail)(struct _FX_FILEAVAIL* pThis, 50 | size_t offset, 51 | size_t size); 52 | } FX_FILEAVAIL; 53 | 54 | // Create a document availability provider. 55 | // 56 | // file_avail - pointer to file availability interface. 57 | // file - pointer to a file access interface. 58 | // 59 | // Returns a handle to the document availability provider, or NULL on error. 60 | // 61 | // FPDFAvail_Destroy() must be called when done with the availability provider. 62 | FPDF_EXPORT FPDF_AVAIL FPDF_CALLCONV FPDFAvail_Create(FX_FILEAVAIL* file_avail, 63 | FPDF_FILEACCESS* file); 64 | 65 | // Destroy the |avail| document availability provider. 66 | // 67 | // avail - handle to document availability provider to be destroyed. 68 | FPDF_EXPORT void FPDF_CALLCONV FPDFAvail_Destroy(FPDF_AVAIL avail); 69 | 70 | // Download hints interface. Used to receive hints for further downloading. 71 | typedef struct _FX_DOWNLOADHINTS { 72 | // Version number of the interface. Must be 1. 73 | int version; 74 | 75 | // Add a section to be downloaded. 76 | // 77 | // Interface Version: 1 78 | // Implementation Required: Yes 79 | // 80 | // pThis - pointer to the interface structure. 81 | // offset - the offset of the hint reported to be downloaded. 82 | // size - the size of the hint reported to be downloaded. 83 | // 84 | // The |offset| and |size| of the section may not be unique. Part of the 85 | // section might be already available. The download manager must deal with 86 | // overlapping sections. 87 | void (*AddSegment)(struct _FX_DOWNLOADHINTS* pThis, 88 | size_t offset, 89 | size_t size); 90 | } FX_DOWNLOADHINTS; 91 | 92 | // Checks if the document is ready for loading, if not, gets download hints. 93 | // 94 | // avail - handle to document availability provider. 95 | // hints - pointer to a download hints interface. 96 | // 97 | // Returns one of: 98 | // PDF_DATA_ERROR: A common error is returned. Data availability unknown. 99 | // PDF_DATA_NOTAVAIL: Data not yet available. 100 | // PDF_DATA_AVAIL: Data available. 101 | // 102 | // Applications should call this function whenever new data arrives, and process 103 | // all the generated download hints, if any, until the function returns 104 | // |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|. 105 | // if hints is nullptr, the function just check current document availability. 106 | // 107 | // Once all data is available, call FPDFAvail_GetDocument() to get a document 108 | // handle. 109 | FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsDocAvail(FPDF_AVAIL avail, 110 | FX_DOWNLOADHINTS* hints); 111 | 112 | // Get document from the availability provider. 113 | // 114 | // avail - handle to document availability provider. 115 | // password - password for decrypting the PDF file. Optional. 116 | // 117 | // Returns a handle to the document. 118 | // 119 | // When FPDFAvail_IsDocAvail() returns TRUE, call FPDFAvail_GetDocument() to 120 | // retrieve the document handle. 121 | // See the comments for FPDF_LoadDocument() regarding the encoding for 122 | // |password|. 123 | FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV 124 | FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password); 125 | 126 | // Get the page number for the first available page in a linearized PDF. 127 | // 128 | // doc - document handle. 129 | // 130 | // Returns the zero-based index for the first available page. 131 | // 132 | // For most linearized PDFs, the first available page will be the first page, 133 | // however, some PDFs might make another page the first available page. 134 | // For non-linearized PDFs, this function will always return zero. 135 | FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc); 136 | 137 | // Check if |page_index| is ready for loading, if not, get the 138 | // |FX_DOWNLOADHINTS|. 139 | // 140 | // avail - handle to document availability provider. 141 | // page_index - index number of the page. Zero for the first page. 142 | // hints - pointer to a download hints interface. Populated if 143 | // |page_index| is not available. 144 | // 145 | // Returns one of: 146 | // PDF_DATA_ERROR: A common error is returned. Data availability unknown. 147 | // PDF_DATA_NOTAVAIL: Data not yet available. 148 | // PDF_DATA_AVAIL: Data available. 149 | // 150 | // This function can be called only after FPDFAvail_GetDocument() is called. 151 | // Applications should call this function whenever new data arrives and process 152 | // all the generated download |hints|, if any, until this function returns 153 | // |PDF_DATA_ERROR| or |PDF_DATA_AVAIL|. Applications can then perform page 154 | // loading. 155 | // if hints is nullptr, the function just check current availability of 156 | // specified page. 157 | FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsPageAvail(FPDF_AVAIL avail, 158 | int page_index, 159 | FX_DOWNLOADHINTS* hints); 160 | 161 | // Check if form data is ready for initialization, if not, get the 162 | // |FX_DOWNLOADHINTS|. 163 | // 164 | // avail - handle to document availability provider. 165 | // hints - pointer to a download hints interface. Populated if form is not 166 | // ready for initialization. 167 | // 168 | // Returns one of: 169 | // PDF_FORM_ERROR: A common eror, in general incorrect parameters. 170 | // PDF_FORM_NOTAVAIL: Data not available. 171 | // PDF_FORM_AVAIL: Data available. 172 | // PDF_FORM_NOTEXIST: No form data. 173 | // 174 | // This function can be called only after FPDFAvail_GetDocument() is called. 175 | // The application should call this function whenever new data arrives and 176 | // process all the generated download |hints|, if any, until the function 177 | // |PDF_FORM_ERROR|, |PDF_FORM_AVAIL| or |PDF_FORM_NOTEXIST|. 178 | // if hints is nullptr, the function just check current form availability. 179 | // 180 | // Applications can then perform page loading. It is recommend to call 181 | // FPDFDOC_InitFormFillEnvironment() when |PDF_FORM_AVAIL| is returned. 182 | FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsFormAvail(FPDF_AVAIL avail, 183 | FX_DOWNLOADHINTS* hints); 184 | 185 | // Check whether a document is a linearized PDF. 186 | // 187 | // avail - handle to document availability provider. 188 | // 189 | // Returns one of: 190 | // PDF_LINEARIZED 191 | // PDF_NOT_LINEARIZED 192 | // PDF_LINEARIZATION_UNKNOWN 193 | // 194 | // FPDFAvail_IsLinearized() will return |PDF_LINEARIZED| or |PDF_NOT_LINEARIZED| 195 | // when we have 1k of data. If the files size less than 1k, it returns 196 | // |PDF_LINEARIZATION_UNKNOWN| as there is insufficient information to determine 197 | // if the PDF is linearlized. 198 | FPDF_EXPORT int FPDF_CALLCONV FPDFAvail_IsLinearized(FPDF_AVAIL avail); 199 | 200 | #ifdef __cplusplus 201 | } // extern "C" 202 | #endif // __cplusplus 203 | 204 | #endif // PUBLIC_FPDF_DATAAVAIL_H_ 205 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_doc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_DOC_H_ 8 | #define PUBLIC_FPDF_DOC_H_ 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif // __cplusplus 16 | 17 | // Unsupported action type. 18 | #define PDFACTION_UNSUPPORTED 0 19 | // Go to a destination within current document. 20 | #define PDFACTION_GOTO 1 21 | // Go to a destination within another document. 22 | #define PDFACTION_REMOTEGOTO 2 23 | // URI, including web pages and other Internet resources. 24 | #define PDFACTION_URI 3 25 | // Launch an application or open a file. 26 | #define PDFACTION_LAUNCH 4 27 | // Go to a destination in an embedded file. 28 | #define PDFACTION_EMBEDDEDGOTO 5 29 | 30 | // View destination fit types. See pdfmark reference v9, page 48. 31 | #define PDFDEST_VIEW_UNKNOWN_MODE 0 32 | #define PDFDEST_VIEW_XYZ 1 33 | #define PDFDEST_VIEW_FIT 2 34 | #define PDFDEST_VIEW_FITH 3 35 | #define PDFDEST_VIEW_FITV 4 36 | #define PDFDEST_VIEW_FITR 5 37 | #define PDFDEST_VIEW_FITB 6 38 | #define PDFDEST_VIEW_FITBH 7 39 | #define PDFDEST_VIEW_FITBV 8 40 | 41 | // The file identifier entry type. See section 14.4 "File Identifiers" of the 42 | // ISO 32000-1:2008 spec. 43 | typedef enum { 44 | FILEIDTYPE_PERMANENT = 0, 45 | FILEIDTYPE_CHANGING = 1 46 | } FPDF_FILEIDTYPE; 47 | 48 | // Get the first child of |bookmark|, or the first top-level bookmark item. 49 | // 50 | // document - handle to the document. 51 | // bookmark - handle to the current bookmark. Pass NULL for the first top 52 | // level item. 53 | // 54 | // Returns a handle to the first child of |bookmark| or the first top-level 55 | // bookmark item. NULL if no child or top-level bookmark found. 56 | // Note that another name for the bookmarks is the document outline, as 57 | // described in ISO 32000-1:2008, section 12.3.3. 58 | FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV 59 | FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark); 60 | 61 | // Get the next sibling of |bookmark|. 62 | // 63 | // document - handle to the document. 64 | // bookmark - handle to the current bookmark. 65 | // 66 | // Returns a handle to the next sibling of |bookmark|, or NULL if this is the 67 | // last bookmark at this level. 68 | // 69 | // Note that the caller is responsible for handling circular bookmark 70 | // references, as may arise from malformed documents. 71 | FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV 72 | FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark); 73 | 74 | // Get the title of |bookmark|. 75 | // 76 | // bookmark - handle to the bookmark. 77 | // buffer - buffer for the title. May be NULL. 78 | // buflen - the length of the buffer in bytes. May be 0. 79 | // 80 | // Returns the number of bytes in the title, including the terminating NUL 81 | // character. The number of bytes is returned regardless of the |buffer| and 82 | // |buflen| parameters. 83 | // 84 | // Regardless of the platform, the |buffer| is always in UTF-16LE encoding. The 85 | // string is terminated by a UTF16 NUL character. If |buflen| is less than the 86 | // required length, or |buffer| is NULL, |buffer| will not be modified. 87 | FPDF_EXPORT unsigned long FPDF_CALLCONV 88 | FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark, 89 | void* buffer, 90 | unsigned long buflen); 91 | 92 | // Experimental API. 93 | // Get the number of chlidren of |bookmark|. 94 | // 95 | // bookmark - handle to the bookmark. 96 | // 97 | // Returns a signed integer that represents the number of sub-items the given 98 | // bookmark has. If the value is positive, child items shall be shown by default 99 | // (open state). If the value is negative, child items shall be hidden by 100 | // default (closed state). Please refer to PDF 32000-1:2008, Table 153. 101 | // Returns 0 if the bookmark has no children or is invalid. 102 | FPDF_EXPORT int FPDF_CALLCONV FPDFBookmark_GetCount(FPDF_BOOKMARK bookmark); 103 | 104 | // Find the bookmark with |title| in |document|. 105 | // 106 | // document - handle to the document. 107 | // title - the UTF-16LE encoded Unicode title for which to search. 108 | // 109 | // Returns the handle to the bookmark, or NULL if |title| can't be found. 110 | // 111 | // FPDFBookmark_Find() will always return the first bookmark found even if 112 | // multiple bookmarks have the same |title|. 113 | FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV 114 | FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title); 115 | 116 | // Get the destination associated with |bookmark|. 117 | // 118 | // document - handle to the document. 119 | // bookmark - handle to the bookmark. 120 | // 121 | // Returns the handle to the destination data, or NULL if no destination is 122 | // associated with |bookmark|. 123 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV 124 | FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark); 125 | 126 | // Get the action associated with |bookmark|. 127 | // 128 | // bookmark - handle to the bookmark. 129 | // 130 | // Returns the handle to the action data, or NULL if no action is associated 131 | // with |bookmark|. 132 | // If this function returns a valid handle, it is valid as long as |bookmark| is 133 | // valid. 134 | // If this function returns NULL, FPDFBookmark_GetDest() should be called to get 135 | // the |bookmark| destination data. 136 | FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV 137 | FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark); 138 | 139 | // Get the type of |action|. 140 | // 141 | // action - handle to the action. 142 | // 143 | // Returns one of: 144 | // PDFACTION_UNSUPPORTED 145 | // PDFACTION_GOTO 146 | // PDFACTION_REMOTEGOTO 147 | // PDFACTION_URI 148 | // PDFACTION_LAUNCH 149 | FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION action); 150 | 151 | // Get the destination of |action|. 152 | // 153 | // document - handle to the document. 154 | // action - handle to the action. |action| must be a |PDFACTION_GOTO| or 155 | // |PDFACTION_REMOTEGOTO|. 156 | // 157 | // Returns a handle to the destination data, or NULL on error, typically 158 | // because the arguments were bad or the action was of the wrong type. 159 | // 160 | // In the case of |PDFACTION_REMOTEGOTO|, you must first call 161 | // FPDFAction_GetFilePath(), then load the document at that path, then pass 162 | // the document handle from that document as |document| to FPDFAction_GetDest(). 163 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document, 164 | FPDF_ACTION action); 165 | 166 | // Get the file path of |action|. 167 | // 168 | // action - handle to the action. |action| must be a |PDFACTION_LAUNCH| or 169 | // |PDFACTION_REMOTEGOTO|. 170 | // buffer - a buffer for output the path string. May be NULL. 171 | // buflen - the length of the buffer, in bytes. May be 0. 172 | // 173 | // Returns the number of bytes in the file path, including the trailing NUL 174 | // character, or 0 on error, typically because the arguments were bad or the 175 | // action was of the wrong type. 176 | // 177 | // Regardless of the platform, the |buffer| is always in UTF-8 encoding. 178 | // If |buflen| is less than the returned length, or |buffer| is NULL, |buffer| 179 | // will not be modified. 180 | FPDF_EXPORT unsigned long FPDF_CALLCONV 181 | FPDFAction_GetFilePath(FPDF_ACTION action, void* buffer, unsigned long buflen); 182 | 183 | // Get the URI path of |action|. 184 | // 185 | // document - handle to the document. 186 | // action - handle to the action. Must be a |PDFACTION_URI|. 187 | // buffer - a buffer for the path string. May be NULL. 188 | // buflen - the length of the buffer, in bytes. May be 0. 189 | // 190 | // Returns the number of bytes in the URI path, including the trailing NUL 191 | // character, or 0 on error, typically because the arguments were bad or the 192 | // action was of the wrong type. 193 | // 194 | // The |buffer| may contain badly encoded data. The caller should validate the 195 | // output. e.g. Check to see if it is UTF-8. 196 | // 197 | // If |buflen| is less than the returned length, or |buffer| is NULL, |buffer| 198 | // will not be modified. 199 | // 200 | // Historically, the documentation for this API claimed |buffer| is always 201 | // encoded in 7-bit ASCII, but did not actually enforce it. 202 | // https://pdfium.googlesource.com/pdfium.git/+/d609e84cee2e14a18333247485af91df48a40592 203 | // added that enforcement, but that did not work well for real world PDFs that 204 | // used UTF-8. As of this writing, this API reverted back to its original 205 | // behavior prior to commit d609e84cee. 206 | FPDF_EXPORT unsigned long FPDF_CALLCONV 207 | FPDFAction_GetURIPath(FPDF_DOCUMENT document, 208 | FPDF_ACTION action, 209 | void* buffer, 210 | unsigned long buflen); 211 | 212 | // Get the page index of |dest|. 213 | // 214 | // document - handle to the document. 215 | // dest - handle to the destination. 216 | // 217 | // Returns the 0-based page index containing |dest|. Returns -1 on error. 218 | FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document, 219 | FPDF_DEST dest); 220 | 221 | // Experimental API. 222 | // Get the view (fit type) specified by |dest|. 223 | // 224 | // dest - handle to the destination. 225 | // pNumParams - receives the number of view parameters, which is at most 4. 226 | // pParams - buffer to write the view parameters. Must be at least 4 227 | // FS_FLOATs long. 228 | // Returns one of the PDFDEST_VIEW_* constants, PDFDEST_VIEW_UNKNOWN_MODE if 229 | // |dest| does not specify a view. 230 | FPDF_EXPORT unsigned long FPDF_CALLCONV 231 | FPDFDest_GetView(FPDF_DEST dest, unsigned long* pNumParams, FS_FLOAT* pParams); 232 | 233 | // Get the (x, y, zoom) location of |dest| in the destination page, if the 234 | // destination is in [page /XYZ x y zoom] syntax. 235 | // 236 | // dest - handle to the destination. 237 | // hasXVal - out parameter; true if the x value is not null 238 | // hasYVal - out parameter; true if the y value is not null 239 | // hasZoomVal - out parameter; true if the zoom value is not null 240 | // x - out parameter; the x coordinate, in page coordinates. 241 | // y - out parameter; the y coordinate, in page coordinates. 242 | // zoom - out parameter; the zoom value. 243 | // Returns TRUE on successfully reading the /XYZ value. 244 | // 245 | // Note the [x, y, zoom] values are only set if the corresponding hasXVal, 246 | // hasYVal or hasZoomVal flags are true. 247 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 248 | FPDFDest_GetLocationInPage(FPDF_DEST dest, 249 | FPDF_BOOL* hasXVal, 250 | FPDF_BOOL* hasYVal, 251 | FPDF_BOOL* hasZoomVal, 252 | FS_FLOAT* x, 253 | FS_FLOAT* y, 254 | FS_FLOAT* zoom); 255 | 256 | // Find a link at point (|x|,|y|) on |page|. 257 | // 258 | // page - handle to the document page. 259 | // x - the x coordinate, in the page coordinate system. 260 | // y - the y coordinate, in the page coordinate system. 261 | // 262 | // Returns a handle to the link, or NULL if no link found at the given point. 263 | // 264 | // You can convert coordinates from screen coordinates to page coordinates using 265 | // FPDF_DeviceToPage(). 266 | FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFLink_GetLinkAtPoint(FPDF_PAGE page, 267 | double x, 268 | double y); 269 | 270 | // Find the Z-order of link at point (|x|,|y|) on |page|. 271 | // 272 | // page - handle to the document page. 273 | // x - the x coordinate, in the page coordinate system. 274 | // y - the y coordinate, in the page coordinate system. 275 | // 276 | // Returns the Z-order of the link, or -1 if no link found at the given point. 277 | // Larger Z-order numbers are closer to the front. 278 | // 279 | // You can convert coordinates from screen coordinates to page coordinates using 280 | // FPDF_DeviceToPage(). 281 | FPDF_EXPORT int FPDF_CALLCONV FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, 282 | double x, 283 | double y); 284 | 285 | // Get destination info for |link|. 286 | // 287 | // document - handle to the document. 288 | // link - handle to the link. 289 | // 290 | // Returns a handle to the destination, or NULL if there is no destination 291 | // associated with the link. In this case, you should call FPDFLink_GetAction() 292 | // to retrieve the action associated with |link|. 293 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document, 294 | FPDF_LINK link); 295 | 296 | // Get action info for |link|. 297 | // 298 | // link - handle to the link. 299 | // 300 | // Returns a handle to the action associated to |link|, or NULL if no action. 301 | // If this function returns a valid handle, it is valid as long as |link| is 302 | // valid. 303 | FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK link); 304 | 305 | // Enumerates all the link annotations in |page|. 306 | // 307 | // page - handle to the page. 308 | // start_pos - the start position, should initially be 0 and is updated with 309 | // the next start position on return. 310 | // link_annot - the link handle for |startPos|. 311 | // 312 | // Returns TRUE on success. 313 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page, 314 | int* start_pos, 315 | FPDF_LINK* link_annot); 316 | 317 | // Experimental API. 318 | // Gets FPDF_ANNOTATION object for |link_annot|. 319 | // 320 | // page - handle to the page in which FPDF_LINK object is present. 321 | // link_annot - handle to link annotation. 322 | // 323 | // Returns FPDF_ANNOTATION from the FPDF_LINK and NULL on failure, 324 | // if the input link annot or page is NULL. 325 | FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV 326 | FPDFLink_GetAnnot(FPDF_PAGE page, FPDF_LINK link_annot); 327 | 328 | // Get the rectangle for |link_annot|. 329 | // 330 | // link_annot - handle to the link annotation. 331 | // rect - the annotation rectangle. 332 | // 333 | // Returns true on success. 334 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot, 335 | FS_RECTF* rect); 336 | 337 | // Get the count of quadrilateral points to the |link_annot|. 338 | // 339 | // link_annot - handle to the link annotation. 340 | // 341 | // Returns the count of quadrilateral points. 342 | FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountQuadPoints(FPDF_LINK link_annot); 343 | 344 | // Get the quadrilateral points for the specified |quad_index| in |link_annot|. 345 | // 346 | // link_annot - handle to the link annotation. 347 | // quad_index - the specified quad point index. 348 | // quad_points - receives the quadrilateral points. 349 | // 350 | // Returns true on success. 351 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 352 | FPDFLink_GetQuadPoints(FPDF_LINK link_annot, 353 | int quad_index, 354 | FS_QUADPOINTSF* quad_points); 355 | 356 | // Experimental API 357 | // Gets an additional-action from |page|. 358 | // 359 | // page - handle to the page, as returned by FPDF_LoadPage(). 360 | // aa_type - the type of the page object's addtional-action, defined 361 | // in public/fpdf_formfill.h 362 | // 363 | // Returns the handle to the action data, or NULL if there is no 364 | // additional-action of type |aa_type|. 365 | // If this function returns a valid handle, it is valid as long as |page| is 366 | // valid. 367 | FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDF_GetPageAAction(FPDF_PAGE page, 368 | int aa_type); 369 | 370 | // Experimental API. 371 | // Get the file identifer defined in the trailer of |document|. 372 | // 373 | // document - handle to the document. 374 | // id_type - the file identifier type to retrieve. 375 | // buffer - a buffer for the file identifier. May be NULL. 376 | // buflen - the length of the buffer, in bytes. May be 0. 377 | // 378 | // Returns the number of bytes in the file identifier, including the NUL 379 | // terminator. 380 | // 381 | // The |buffer| is always a byte string. The |buffer| is followed by a NUL 382 | // terminator. If |buflen| is less than the returned length, or |buffer| is 383 | // NULL, |buffer| will not be modified. 384 | FPDF_EXPORT unsigned long FPDF_CALLCONV 385 | FPDF_GetFileIdentifier(FPDF_DOCUMENT document, 386 | FPDF_FILEIDTYPE id_type, 387 | void* buffer, 388 | unsigned long buflen); 389 | 390 | // Get meta-data |tag| content from |document|. 391 | // 392 | // document - handle to the document. 393 | // tag - the tag to retrieve. The tag can be one of: 394 | // Title, Author, Subject, Keywords, Creator, Producer, 395 | // CreationDate, or ModDate. 396 | // For detailed explanations of these tags and their respective 397 | // values, please refer to PDF Reference 1.6, section 10.2.1, 398 | // 'Document Information Dictionary'. 399 | // buffer - a buffer for the tag. May be NULL. 400 | // buflen - the length of the buffer, in bytes. May be 0. 401 | // 402 | // Returns the number of bytes in the tag, including trailing zeros. 403 | // 404 | // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two 405 | // bytes of zeros indicating the end of the string. If |buflen| is less than 406 | // the returned length, or |buffer| is NULL, |buffer| will not be modified. 407 | // 408 | // For linearized files, FPDFAvail_IsFormAvail must be called before this, and 409 | // it must have returned PDF_FORM_AVAIL or PDF_FORM_NOTEXIST. Before that, there 410 | // is no guarantee the metadata has been loaded. 411 | FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document, 412 | FPDF_BYTESTRING tag, 413 | void* buffer, 414 | unsigned long buflen); 415 | 416 | // Get the page label for |page_index| from |document|. 417 | // 418 | // document - handle to the document. 419 | // page_index - the 0-based index of the page. 420 | // buffer - a buffer for the page label. May be NULL. 421 | // buflen - the length of the buffer, in bytes. May be 0. 422 | // 423 | // Returns the number of bytes in the page label, including trailing zeros. 424 | // 425 | // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two 426 | // bytes of zeros indicating the end of the string. If |buflen| is less than 427 | // the returned length, or |buffer| is NULL, |buffer| will not be modified. 428 | FPDF_EXPORT unsigned long FPDF_CALLCONV 429 | FPDF_GetPageLabel(FPDF_DOCUMENT document, 430 | int page_index, 431 | void* buffer, 432 | unsigned long buflen); 433 | 434 | #ifdef __cplusplus 435 | } // extern "C" 436 | #endif // __cplusplus 437 | 438 | #endif // PUBLIC_FPDF_DOC_H_ 439 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_ext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_EXT_H_ 8 | #define PUBLIC_FPDF_EXT_H_ 9 | 10 | #include 11 | 12 | // NOLINTNEXTLINE(build/include) 13 | #include "fpdfview.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif // __cplusplus 18 | 19 | // Unsupported XFA form. 20 | #define FPDF_UNSP_DOC_XFAFORM 1 21 | // Unsupported portable collection. 22 | #define FPDF_UNSP_DOC_PORTABLECOLLECTION 2 23 | // Unsupported attachment. 24 | #define FPDF_UNSP_DOC_ATTACHMENT 3 25 | // Unsupported security. 26 | #define FPDF_UNSP_DOC_SECURITY 4 27 | // Unsupported shared review. 28 | #define FPDF_UNSP_DOC_SHAREDREVIEW 5 29 | // Unsupported shared form, acrobat. 30 | #define FPDF_UNSP_DOC_SHAREDFORM_ACROBAT 6 31 | // Unsupported shared form, filesystem. 32 | #define FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM 7 33 | // Unsupported shared form, email. 34 | #define FPDF_UNSP_DOC_SHAREDFORM_EMAIL 8 35 | // Unsupported 3D annotation. 36 | #define FPDF_UNSP_ANNOT_3DANNOT 11 37 | // Unsupported movie annotation. 38 | #define FPDF_UNSP_ANNOT_MOVIE 12 39 | // Unsupported sound annotation. 40 | #define FPDF_UNSP_ANNOT_SOUND 13 41 | // Unsupported screen media annotation. 42 | #define FPDF_UNSP_ANNOT_SCREEN_MEDIA 14 43 | // Unsupported screen rich media annotation. 44 | #define FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA 15 45 | // Unsupported attachment annotation. 46 | #define FPDF_UNSP_ANNOT_ATTACHMENT 16 47 | // Unsupported signature annotation. 48 | #define FPDF_UNSP_ANNOT_SIG 17 49 | 50 | // Interface for unsupported feature notifications. 51 | typedef struct _UNSUPPORT_INFO { 52 | // Version number of the interface. Must be 1. 53 | int version; 54 | 55 | // Unsupported object notification function. 56 | // Interface Version: 1 57 | // Implementation Required: Yes 58 | // 59 | // pThis - pointer to the interface structure. 60 | // nType - the type of unsupported object. One of the |FPDF_UNSP_*| entries. 61 | void (*FSDK_UnSupport_Handler)(struct _UNSUPPORT_INFO* pThis, int nType); 62 | } UNSUPPORT_INFO; 63 | 64 | // Setup an unsupported object handler. 65 | // 66 | // unsp_info - Pointer to an UNSUPPORT_INFO structure. 67 | // 68 | // Returns TRUE on success. 69 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 70 | FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info); 71 | 72 | // Set replacement function for calls to time(). 73 | // 74 | // This API is intended to be used only for testing, thus may cause PDFium to 75 | // behave poorly in production environments. 76 | // 77 | // func - Function pointer to alternate implementation of time(), or 78 | // NULL to restore to actual time() call itself. 79 | FPDF_EXPORT void FPDF_CALLCONV FSDK_SetTimeFunction(time_t (*func)()); 80 | 81 | // Set replacement function for calls to localtime(). 82 | // 83 | // This API is intended to be used only for testing, thus may cause PDFium to 84 | // behave poorly in production environments. 85 | // 86 | // func - Function pointer to alternate implementation of localtime(), or 87 | // NULL to restore to actual localtime() call itself. 88 | FPDF_EXPORT void FPDF_CALLCONV 89 | FSDK_SetLocaltimeFunction(struct tm* (*func)(const time_t*)); 90 | 91 | // Unknown page mode. 92 | #define PAGEMODE_UNKNOWN -1 93 | // Document outline, and thumbnails hidden. 94 | #define PAGEMODE_USENONE 0 95 | // Document outline visible. 96 | #define PAGEMODE_USEOUTLINES 1 97 | // Thumbnail images visible. 98 | #define PAGEMODE_USETHUMBS 2 99 | // Full-screen mode, no menu bar, window controls, or other decorations visible. 100 | #define PAGEMODE_FULLSCREEN 3 101 | // Optional content group panel visible. 102 | #define PAGEMODE_USEOC 4 103 | // Attachments panel visible. 104 | #define PAGEMODE_USEATTACHMENTS 5 105 | 106 | // Get the document's PageMode. 107 | // 108 | // doc - Handle to document. 109 | // 110 | // Returns one of the |PAGEMODE_*| flags defined above. 111 | // 112 | // The page mode defines how the document should be initially displayed. 113 | FPDF_EXPORT int FPDF_CALLCONV FPDFDoc_GetPageMode(FPDF_DOCUMENT document); 114 | 115 | #ifdef __cplusplus 116 | } // extern "C" 117 | #endif // __cplusplus 118 | 119 | #endif // PUBLIC_FPDF_EXT_H_ 120 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_flatten.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_FLATTEN_H_ 8 | #define PUBLIC_FPDF_FLATTEN_H_ 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | // Flatten operation failed. 14 | #define FLATTEN_FAIL 0 15 | // Flatten operation succeed. 16 | #define FLATTEN_SUCCESS 1 17 | // Nothing to be flattened. 18 | #define FLATTEN_NOTHINGTODO 2 19 | 20 | // Flatten for normal display. 21 | #define FLAT_NORMALDISPLAY 0 22 | // Flatten for print. 23 | #define FLAT_PRINT 1 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif // __cplusplus 28 | 29 | // Flatten annotations and form fields into the page contents. 30 | // 31 | // page - handle to the page. 32 | // nFlag - One of the |FLAT_*| values denoting the page usage. 33 | // 34 | // Returns one of the |FLATTEN_*| values. 35 | // 36 | // Currently, all failures return |FLATTEN_FAIL| with no indication of the 37 | // cause. 38 | FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag); 39 | 40 | #ifdef __cplusplus 41 | } // extern "C" 42 | #endif // __cplusplus 43 | 44 | #endif // PUBLIC_FPDF_FLATTEN_H_ 45 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_fwlevent.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_FWLEVENT_H_ 8 | #define PUBLIC_FPDF_FWLEVENT_H_ 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif // __cplusplus 16 | 17 | // Key flags. 18 | typedef enum { 19 | FWL_EVENTFLAG_ShiftKey = 1 << 0, 20 | FWL_EVENTFLAG_ControlKey = 1 << 1, 21 | FWL_EVENTFLAG_AltKey = 1 << 2, 22 | FWL_EVENTFLAG_MetaKey = 1 << 3, 23 | FWL_EVENTFLAG_KeyPad = 1 << 4, 24 | FWL_EVENTFLAG_AutoRepeat = 1 << 5, 25 | FWL_EVENTFLAG_LeftButtonDown = 1 << 6, 26 | FWL_EVENTFLAG_MiddleButtonDown = 1 << 7, 27 | FWL_EVENTFLAG_RightButtonDown = 1 << 8, 28 | } FWL_EVENTFLAG; 29 | 30 | // Virtual keycodes. 31 | typedef enum { 32 | FWL_VKEY_Back = 0x08, 33 | FWL_VKEY_Tab = 0x09, 34 | FWL_VKEY_NewLine = 0x0A, 35 | FWL_VKEY_Clear = 0x0C, 36 | FWL_VKEY_Return = 0x0D, 37 | FWL_VKEY_Shift = 0x10, 38 | FWL_VKEY_Control = 0x11, 39 | FWL_VKEY_Menu = 0x12, 40 | FWL_VKEY_Pause = 0x13, 41 | FWL_VKEY_Capital = 0x14, 42 | FWL_VKEY_Kana = 0x15, 43 | FWL_VKEY_Hangul = 0x15, 44 | FWL_VKEY_Junja = 0x17, 45 | FWL_VKEY_Final = 0x18, 46 | FWL_VKEY_Hanja = 0x19, 47 | FWL_VKEY_Kanji = 0x19, 48 | FWL_VKEY_Escape = 0x1B, 49 | FWL_VKEY_Convert = 0x1C, 50 | FWL_VKEY_NonConvert = 0x1D, 51 | FWL_VKEY_Accept = 0x1E, 52 | FWL_VKEY_ModeChange = 0x1F, 53 | FWL_VKEY_Space = 0x20, 54 | FWL_VKEY_Prior = 0x21, 55 | FWL_VKEY_Next = 0x22, 56 | FWL_VKEY_End = 0x23, 57 | FWL_VKEY_Home = 0x24, 58 | FWL_VKEY_Left = 0x25, 59 | FWL_VKEY_Up = 0x26, 60 | FWL_VKEY_Right = 0x27, 61 | FWL_VKEY_Down = 0x28, 62 | FWL_VKEY_Select = 0x29, 63 | FWL_VKEY_Print = 0x2A, 64 | FWL_VKEY_Execute = 0x2B, 65 | FWL_VKEY_Snapshot = 0x2C, 66 | FWL_VKEY_Insert = 0x2D, 67 | FWL_VKEY_Delete = 0x2E, 68 | FWL_VKEY_Help = 0x2F, 69 | FWL_VKEY_0 = 0x30, 70 | FWL_VKEY_1 = 0x31, 71 | FWL_VKEY_2 = 0x32, 72 | FWL_VKEY_3 = 0x33, 73 | FWL_VKEY_4 = 0x34, 74 | FWL_VKEY_5 = 0x35, 75 | FWL_VKEY_6 = 0x36, 76 | FWL_VKEY_7 = 0x37, 77 | FWL_VKEY_8 = 0x38, 78 | FWL_VKEY_9 = 0x39, 79 | FWL_VKEY_A = 0x41, 80 | FWL_VKEY_B = 0x42, 81 | FWL_VKEY_C = 0x43, 82 | FWL_VKEY_D = 0x44, 83 | FWL_VKEY_E = 0x45, 84 | FWL_VKEY_F = 0x46, 85 | FWL_VKEY_G = 0x47, 86 | FWL_VKEY_H = 0x48, 87 | FWL_VKEY_I = 0x49, 88 | FWL_VKEY_J = 0x4A, 89 | FWL_VKEY_K = 0x4B, 90 | FWL_VKEY_L = 0x4C, 91 | FWL_VKEY_M = 0x4D, 92 | FWL_VKEY_N = 0x4E, 93 | FWL_VKEY_O = 0x4F, 94 | FWL_VKEY_P = 0x50, 95 | FWL_VKEY_Q = 0x51, 96 | FWL_VKEY_R = 0x52, 97 | FWL_VKEY_S = 0x53, 98 | FWL_VKEY_T = 0x54, 99 | FWL_VKEY_U = 0x55, 100 | FWL_VKEY_V = 0x56, 101 | FWL_VKEY_W = 0x57, 102 | FWL_VKEY_X = 0x58, 103 | FWL_VKEY_Y = 0x59, 104 | FWL_VKEY_Z = 0x5A, 105 | FWL_VKEY_LWin = 0x5B, 106 | FWL_VKEY_Command = 0x5B, 107 | FWL_VKEY_RWin = 0x5C, 108 | FWL_VKEY_Apps = 0x5D, 109 | FWL_VKEY_Sleep = 0x5F, 110 | FWL_VKEY_NumPad0 = 0x60, 111 | FWL_VKEY_NumPad1 = 0x61, 112 | FWL_VKEY_NumPad2 = 0x62, 113 | FWL_VKEY_NumPad3 = 0x63, 114 | FWL_VKEY_NumPad4 = 0x64, 115 | FWL_VKEY_NumPad5 = 0x65, 116 | FWL_VKEY_NumPad6 = 0x66, 117 | FWL_VKEY_NumPad7 = 0x67, 118 | FWL_VKEY_NumPad8 = 0x68, 119 | FWL_VKEY_NumPad9 = 0x69, 120 | FWL_VKEY_Multiply = 0x6A, 121 | FWL_VKEY_Add = 0x6B, 122 | FWL_VKEY_Separator = 0x6C, 123 | FWL_VKEY_Subtract = 0x6D, 124 | FWL_VKEY_Decimal = 0x6E, 125 | FWL_VKEY_Divide = 0x6F, 126 | FWL_VKEY_F1 = 0x70, 127 | FWL_VKEY_F2 = 0x71, 128 | FWL_VKEY_F3 = 0x72, 129 | FWL_VKEY_F4 = 0x73, 130 | FWL_VKEY_F5 = 0x74, 131 | FWL_VKEY_F6 = 0x75, 132 | FWL_VKEY_F7 = 0x76, 133 | FWL_VKEY_F8 = 0x77, 134 | FWL_VKEY_F9 = 0x78, 135 | FWL_VKEY_F10 = 0x79, 136 | FWL_VKEY_F11 = 0x7A, 137 | FWL_VKEY_F12 = 0x7B, 138 | FWL_VKEY_F13 = 0x7C, 139 | FWL_VKEY_F14 = 0x7D, 140 | FWL_VKEY_F15 = 0x7E, 141 | FWL_VKEY_F16 = 0x7F, 142 | FWL_VKEY_F17 = 0x80, 143 | FWL_VKEY_F18 = 0x81, 144 | FWL_VKEY_F19 = 0x82, 145 | FWL_VKEY_F20 = 0x83, 146 | FWL_VKEY_F21 = 0x84, 147 | FWL_VKEY_F22 = 0x85, 148 | FWL_VKEY_F23 = 0x86, 149 | FWL_VKEY_F24 = 0x87, 150 | FWL_VKEY_NunLock = 0x90, 151 | FWL_VKEY_Scroll = 0x91, 152 | FWL_VKEY_LShift = 0xA0, 153 | FWL_VKEY_RShift = 0xA1, 154 | FWL_VKEY_LControl = 0xA2, 155 | FWL_VKEY_RControl = 0xA3, 156 | FWL_VKEY_LMenu = 0xA4, 157 | FWL_VKEY_RMenu = 0xA5, 158 | FWL_VKEY_BROWSER_Back = 0xA6, 159 | FWL_VKEY_BROWSER_Forward = 0xA7, 160 | FWL_VKEY_BROWSER_Refresh = 0xA8, 161 | FWL_VKEY_BROWSER_Stop = 0xA9, 162 | FWL_VKEY_BROWSER_Search = 0xAA, 163 | FWL_VKEY_BROWSER_Favorites = 0xAB, 164 | FWL_VKEY_BROWSER_Home = 0xAC, 165 | FWL_VKEY_VOLUME_Mute = 0xAD, 166 | FWL_VKEY_VOLUME_Down = 0xAE, 167 | FWL_VKEY_VOLUME_Up = 0xAF, 168 | FWL_VKEY_MEDIA_NEXT_Track = 0xB0, 169 | FWL_VKEY_MEDIA_PREV_Track = 0xB1, 170 | FWL_VKEY_MEDIA_Stop = 0xB2, 171 | FWL_VKEY_MEDIA_PLAY_Pause = 0xB3, 172 | FWL_VKEY_MEDIA_LAUNCH_Mail = 0xB4, 173 | FWL_VKEY_MEDIA_LAUNCH_MEDIA_Select = 0xB5, 174 | FWL_VKEY_MEDIA_LAUNCH_APP1 = 0xB6, 175 | FWL_VKEY_MEDIA_LAUNCH_APP2 = 0xB7, 176 | FWL_VKEY_OEM_1 = 0xBA, 177 | FWL_VKEY_OEM_Plus = 0xBB, 178 | FWL_VKEY_OEM_Comma = 0xBC, 179 | FWL_VKEY_OEM_Minus = 0xBD, 180 | FWL_VKEY_OEM_Period = 0xBE, 181 | FWL_VKEY_OEM_2 = 0xBF, 182 | FWL_VKEY_OEM_3 = 0xC0, 183 | FWL_VKEY_OEM_4 = 0xDB, 184 | FWL_VKEY_OEM_5 = 0xDC, 185 | FWL_VKEY_OEM_6 = 0xDD, 186 | FWL_VKEY_OEM_7 = 0xDE, 187 | FWL_VKEY_OEM_8 = 0xDF, 188 | FWL_VKEY_OEM_102 = 0xE2, 189 | FWL_VKEY_ProcessKey = 0xE5, 190 | FWL_VKEY_Packet = 0xE7, 191 | FWL_VKEY_Attn = 0xF6, 192 | FWL_VKEY_Crsel = 0xF7, 193 | FWL_VKEY_Exsel = 0xF8, 194 | FWL_VKEY_Ereof = 0xF9, 195 | FWL_VKEY_Play = 0xFA, 196 | FWL_VKEY_Zoom = 0xFB, 197 | FWL_VKEY_NoName = 0xFC, 198 | FWL_VKEY_PA1 = 0xFD, 199 | FWL_VKEY_OEM_Clear = 0xFE, 200 | FWL_VKEY_Unknown = 0, 201 | } FWL_VKEYCODE; 202 | 203 | #ifdef __cplusplus 204 | } // extern "C" 205 | #endif // __cplusplus 206 | 207 | #endif // PUBLIC_FPDF_FWLEVENT_H_ 208 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_javascript.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_FPDF_JAVASCRIPT_H_ 6 | #define PUBLIC_FPDF_JAVASCRIPT_H_ 7 | 8 | // NOLINTNEXTLINE(build/include) 9 | #include "fpdfview.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif // __cplusplus 14 | 15 | // Experimental API. 16 | // Get the number of JavaScript actions in |document|. 17 | // 18 | // document - handle to a document. 19 | // 20 | // Returns the number of JavaScript actions in |document| or -1 on error. 21 | FPDF_EXPORT int FPDF_CALLCONV 22 | FPDFDoc_GetJavaScriptActionCount(FPDF_DOCUMENT document); 23 | 24 | // Experimental API. 25 | // Get the JavaScript action at |index| in |document|. 26 | // 27 | // document - handle to a document. 28 | // index - the index of the requested JavaScript action. 29 | // 30 | // Returns the handle to the JavaScript action, or NULL on failure. 31 | // Caller owns the returned handle and must close it with 32 | // FPDFDoc_CloseJavaScriptAction(). 33 | FPDF_EXPORT FPDF_JAVASCRIPT_ACTION FPDF_CALLCONV 34 | FPDFDoc_GetJavaScriptAction(FPDF_DOCUMENT document, int index); 35 | 36 | // Experimental API. 37 | // Close a loaded FPDF_JAVASCRIPT_ACTION object. 38 | 39 | // javascript - Handle to a JavaScript action. 40 | FPDF_EXPORT void FPDF_CALLCONV 41 | FPDFDoc_CloseJavaScriptAction(FPDF_JAVASCRIPT_ACTION javascript); 42 | 43 | // Experimental API. 44 | // Get the name from the |javascript| handle. |buffer| is only modified if 45 | // |buflen| is longer than the length of the name. On errors, |buffer| is 46 | // unmodified and the returned length is 0. 47 | // 48 | // javascript - handle to an JavaScript action. 49 | // buffer - buffer for holding the name, encoded in UTF-16LE. 50 | // buflen - length of the buffer in bytes. 51 | // 52 | // Returns the length of the JavaScript action name in bytes. 53 | FPDF_EXPORT unsigned long FPDF_CALLCONV 54 | FPDFJavaScriptAction_GetName(FPDF_JAVASCRIPT_ACTION javascript, 55 | FPDF_WCHAR* buffer, 56 | unsigned long buflen); 57 | 58 | // Experimental API. 59 | // Get the script from the |javascript| handle. |buffer| is only modified if 60 | // |buflen| is longer than the length of the script. On errors, |buffer| is 61 | // unmodified and the returned length is 0. 62 | // 63 | // javascript - handle to an JavaScript action. 64 | // buffer - buffer for holding the name, encoded in UTF-16LE. 65 | // buflen - length of the buffer in bytes. 66 | // 67 | // Returns the length of the JavaScript action name in bytes. 68 | FPDF_EXPORT unsigned long FPDF_CALLCONV 69 | FPDFJavaScriptAction_GetScript(FPDF_JAVASCRIPT_ACTION javascript, 70 | FPDF_WCHAR* buffer, 71 | unsigned long buflen); 72 | 73 | #ifdef __cplusplus 74 | } // extern "C" 75 | #endif // __cplusplus 76 | 77 | #endif // PUBLIC_FPDF_JAVASCRIPT_H_ 78 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_ppo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_PPO_H_ 8 | #define PUBLIC_FPDF_PPO_H_ 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | // Experimental API. 18 | // Import pages to a FPDF_DOCUMENT. 19 | // 20 | // dest_doc - The destination document for the pages. 21 | // src_doc - The document to be imported. 22 | // page_indices - An array of page indices to be imported. The first page is 23 | // zero. If |page_indices| is NULL, all pages from |src_doc| 24 | // are imported. 25 | // length - The length of the |page_indices| array. 26 | // index - The page index at which to insert the first imported page 27 | // into |dest_doc|. The first page is zero. 28 | // 29 | // Returns TRUE on success. Returns FALSE if any pages in |page_indices| is 30 | // invalid. 31 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 32 | FPDF_ImportPagesByIndex(FPDF_DOCUMENT dest_doc, 33 | FPDF_DOCUMENT src_doc, 34 | const int* page_indices, 35 | unsigned long length, 36 | int index); 37 | 38 | // Import pages to a FPDF_DOCUMENT. 39 | // 40 | // dest_doc - The destination document for the pages. 41 | // src_doc - The document to be imported. 42 | // pagerange - A page range string, Such as "1,3,5-7". The first page is one. 43 | // If |pagerange| is NULL, all pages from |src_doc| are imported. 44 | // index - The page index at which to insert the first imported page into 45 | // |dest_doc|. The first page is zero. 46 | // 47 | // Returns TRUE on success. Returns FALSE if any pages in |pagerange| is 48 | // invalid or if |pagerange| cannot be read. 49 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_ImportPages(FPDF_DOCUMENT dest_doc, 50 | FPDF_DOCUMENT src_doc, 51 | FPDF_BYTESTRING pagerange, 52 | int index); 53 | 54 | // Experimental API. 55 | // Create a new document from |src_doc|. The pages of |src_doc| will be 56 | // combined to provide |num_pages_on_x_axis x num_pages_on_y_axis| pages per 57 | // |output_doc| page. 58 | // 59 | // src_doc - The document to be imported. 60 | // output_width - The output page width in PDF "user space" units. 61 | // output_height - The output page height in PDF "user space" units. 62 | // num_pages_on_x_axis - The number of pages on X Axis. 63 | // num_pages_on_y_axis - The number of pages on Y Axis. 64 | // 65 | // Return value: 66 | // A handle to the created document, or NULL on failure. 67 | // 68 | // Comments: 69 | // number of pages per page = num_pages_on_x_axis * num_pages_on_y_axis 70 | // 71 | FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV 72 | FPDF_ImportNPagesToOne(FPDF_DOCUMENT src_doc, 73 | float output_width, 74 | float output_height, 75 | size_t num_pages_on_x_axis, 76 | size_t num_pages_on_y_axis); 77 | 78 | // Experimental API. 79 | // Create a template to generate form xobjects from |src_doc|'s page at 80 | // |src_page_index|, for use in |dest_doc|. 81 | // 82 | // Returns a handle on success, or NULL on failure. Caller owns the newly 83 | // created object. 84 | FPDF_EXPORT FPDF_XOBJECT FPDF_CALLCONV 85 | FPDF_NewXObjectFromPage(FPDF_DOCUMENT dest_doc, 86 | FPDF_DOCUMENT src_doc, 87 | int src_page_index); 88 | 89 | // Experimental API. 90 | // Close an FPDF_XOBJECT handle created by FPDF_NewXObjectFromPage(). 91 | // FPDF_PAGEOBJECTs created from the FPDF_XOBJECT handle are not affected. 92 | FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseXObject(FPDF_XOBJECT xobject); 93 | 94 | // Experimental API. 95 | // Create a new form object from an FPDF_XOBJECT object. 96 | // 97 | // Returns a new form object on success, or NULL on failure. Caller owns the 98 | // newly created object. 99 | FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV 100 | FPDF_NewFormObjectFromXObject(FPDF_XOBJECT xobject); 101 | 102 | // Copy the viewer preferences from |src_doc| into |dest_doc|. 103 | // 104 | // dest_doc - Document to write the viewer preferences into. 105 | // src_doc - Document to read the viewer preferences from. 106 | // 107 | // Returns TRUE on success. 108 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 109 | FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, FPDF_DOCUMENT src_doc); 110 | 111 | #ifdef __cplusplus 112 | } // extern "C" 113 | #endif // __cplusplus 114 | 115 | #endif // PUBLIC_FPDF_PPO_H_ 116 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_progressive.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_PROGRESSIVE_H_ 8 | #define PUBLIC_FPDF_PROGRESSIVE_H_ 9 | 10 | // clang-format off 11 | // NOLINTNEXTLINE(build/include) 12 | #include "fpdfview.h" 13 | 14 | // Flags for progressive process status. 15 | #define FPDF_RENDER_READY 0 16 | #define FPDF_RENDER_TOBECONTINUED 1 17 | #define FPDF_RENDER_DONE 2 18 | #define FPDF_RENDER_FAILED 3 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // IFPDF_RENDERINFO interface. 25 | typedef struct _IFSDK_PAUSE { 26 | /* 27 | * Version number of the interface. Currently must be 1. 28 | */ 29 | int version; 30 | 31 | /* 32 | * Method: NeedToPauseNow 33 | * Check if we need to pause a progressive process now. 34 | * Interface Version: 35 | * 1 36 | * Implementation Required: 37 | * yes 38 | * Parameters: 39 | * pThis - Pointer to the interface structure itself 40 | * Return Value: 41 | * Non-zero for pause now, 0 for continue. 42 | */ 43 | FPDF_BOOL (*NeedToPauseNow)(struct _IFSDK_PAUSE* pThis); 44 | 45 | // A user defined data pointer, used by user's application. Can be NULL. 46 | void* user; 47 | } IFSDK_PAUSE; 48 | 49 | // Experimental API. 50 | // Function: FPDF_RenderPageBitmapWithColorScheme_Start 51 | // Start to render page contents to a device independent bitmap 52 | // progressively with a specified color scheme for the content. 53 | // Parameters: 54 | // bitmap - Handle to the device independent bitmap (as the 55 | // output buffer). Bitmap handle can be created by 56 | // FPDFBitmap_Create function. 57 | // page - Handle to the page as returned by FPDF_LoadPage 58 | // function. 59 | // start_x - Left pixel position of the display area in the 60 | // bitmap coordinate. 61 | // start_y - Top pixel position of the display area in the 62 | // bitmap coordinate. 63 | // size_x - Horizontal size (in pixels) for displaying the 64 | // page. 65 | // size_y - Vertical size (in pixels) for displaying the page. 66 | // rotate - Page orientation: 0 (normal), 1 (rotated 90 67 | // degrees clockwise), 2 (rotated 180 degrees), 68 | // 3 (rotated 90 degrees counter-clockwise). 69 | // flags - 0 for normal display, or combination of flags 70 | // defined in fpdfview.h. With FPDF_ANNOT flag, it 71 | // renders all annotations that does not require 72 | // user-interaction, which are all annotations except 73 | // widget and popup annotations. 74 | // color_scheme - Color scheme to be used in rendering the |page|. 75 | // If null, this function will work similar to 76 | // FPDF_RenderPageBitmap_Start(). 77 | // pause - The IFSDK_PAUSE interface. A callback mechanism 78 | // allowing the page rendering process. 79 | // Return value: 80 | // Rendering Status. See flags for progressive process status for the 81 | // details. 82 | FPDF_EXPORT int FPDF_CALLCONV 83 | FPDF_RenderPageBitmapWithColorScheme_Start(FPDF_BITMAP bitmap, 84 | FPDF_PAGE page, 85 | int start_x, 86 | int start_y, 87 | int size_x, 88 | int size_y, 89 | int rotate, 90 | int flags, 91 | const FPDF_COLORSCHEME* color_scheme, 92 | IFSDK_PAUSE* pause); 93 | 94 | // Function: FPDF_RenderPageBitmap_Start 95 | // Start to render page contents to a device independent bitmap 96 | // progressively. 97 | // Parameters: 98 | // bitmap - Handle to the device independent bitmap (as the 99 | // output buffer). Bitmap handle can be created by 100 | // FPDFBitmap_Create(). 101 | // page - Handle to the page, as returned by FPDF_LoadPage(). 102 | // start_x - Left pixel position of the display area in the 103 | // bitmap coordinates. 104 | // start_y - Top pixel position of the display area in the bitmap 105 | // coordinates. 106 | // size_x - Horizontal size (in pixels) for displaying the page. 107 | // size_y - Vertical size (in pixels) for displaying the page. 108 | // rotate - Page orientation: 0 (normal), 1 (rotated 90 degrees 109 | // clockwise), 2 (rotated 180 degrees), 3 (rotated 90 110 | // degrees counter-clockwise). 111 | // flags - 0 for normal display, or combination of flags 112 | // defined in fpdfview.h. With FPDF_ANNOT flag, it 113 | // renders all annotations that does not require 114 | // user-interaction, which are all annotations except 115 | // widget and popup annotations. 116 | // pause - The IFSDK_PAUSE interface.A callback mechanism 117 | // allowing the page rendering process 118 | // Return value: 119 | // Rendering Status. See flags for progressive process status for the 120 | // details. 121 | FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, 122 | FPDF_PAGE page, 123 | int start_x, 124 | int start_y, 125 | int size_x, 126 | int size_y, 127 | int rotate, 128 | int flags, 129 | IFSDK_PAUSE* pause); 130 | 131 | // Function: FPDF_RenderPage_Continue 132 | // Continue rendering a PDF page. 133 | // Parameters: 134 | // page - Handle to the page, as returned by FPDF_LoadPage(). 135 | // pause - The IFSDK_PAUSE interface (a callback mechanism 136 | // allowing the page rendering process to be paused 137 | // before it's finished). This can be NULL if you 138 | // don't want to pause. 139 | // Return value: 140 | // The rendering status. See flags for progressive process status for 141 | // the details. 142 | FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPage_Continue(FPDF_PAGE page, 143 | IFSDK_PAUSE* pause); 144 | 145 | // Function: FPDF_RenderPage_Close 146 | // Release the resource allocate during page rendering. Need to be 147 | // called after finishing rendering or 148 | // cancel the rendering. 149 | // Parameters: 150 | // page - Handle to the page, as returned by FPDF_LoadPage(). 151 | // Return value: 152 | // None. 153 | FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage_Close(FPDF_PAGE page); 154 | 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | #endif // PUBLIC_FPDF_PROGRESSIVE_H_ 160 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_save.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_SAVE_H_ 8 | #define PUBLIC_FPDF_SAVE_H_ 9 | 10 | // clang-format off 11 | // NOLINTNEXTLINE(build/include) 12 | #include "fpdfview.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | // Structure for custom file write 19 | typedef struct FPDF_FILEWRITE_ { 20 | // 21 | // Version number of the interface. Currently must be 1. 22 | // 23 | int version; 24 | 25 | // Method: WriteBlock 26 | // Output a block of data in your custom way. 27 | // Interface Version: 28 | // 1 29 | // Implementation Required: 30 | // Yes 31 | // Comments: 32 | // Called by function FPDF_SaveDocument 33 | // Parameters: 34 | // pThis - Pointer to the structure itself 35 | // pData - Pointer to a buffer to output 36 | // size - The size of the buffer. 37 | // Return value: 38 | // Should be non-zero if successful, zero for error. 39 | int (*WriteBlock)(struct FPDF_FILEWRITE_* pThis, 40 | const void* pData, 41 | unsigned long size); 42 | } FPDF_FILEWRITE; 43 | 44 | // Flags for FPDF_SaveAsCopy() 45 | #define FPDF_INCREMENTAL 1 46 | #define FPDF_NO_INCREMENTAL 2 47 | #define FPDF_REMOVE_SECURITY 3 48 | 49 | // Function: FPDF_SaveAsCopy 50 | // Saves the copy of specified document in custom way. 51 | // Parameters: 52 | // document - Handle to document, as returned by 53 | // FPDF_LoadDocument() or FPDF_CreateNewDocument(). 54 | // pFileWrite - A pointer to a custom file write structure. 55 | // flags - The creating flags. 56 | // Return value: 57 | // TRUE for succeed, FALSE for failed. 58 | // 59 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SaveAsCopy(FPDF_DOCUMENT document, 60 | FPDF_FILEWRITE* pFileWrite, 61 | FPDF_DWORD flags); 62 | 63 | // Function: FPDF_SaveWithVersion 64 | // Same as FPDF_SaveAsCopy(), except the file version of the 65 | // saved document can be specified by the caller. 66 | // Parameters: 67 | // document - Handle to document. 68 | // pFileWrite - A pointer to a custom file write structure. 69 | // flags - The creating flags. 70 | // fileVersion - The PDF file version. File version: 14 for 1.4, 71 | // 15 for 1.5, ... 72 | // Return value: 73 | // TRUE if succeed, FALSE if failed. 74 | // 75 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 76 | FPDF_SaveWithVersion(FPDF_DOCUMENT document, 77 | FPDF_FILEWRITE* pFileWrite, 78 | FPDF_DWORD flags, 79 | int fileVersion); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif // PUBLIC_FPDF_SAVE_H_ 86 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_searchex.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_SEARCHEX_H_ 8 | #define PUBLIC_FPDF_SEARCHEX_H_ 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif // __cplusplus 16 | 17 | // Get the character index in |text_page| internal character list. 18 | // 19 | // text_page - a text page information structure. 20 | // nTextIndex - index of the text returned from FPDFText_GetText(). 21 | // 22 | // Returns the index of the character in internal character list. -1 for error. 23 | FPDF_EXPORT int FPDF_CALLCONV 24 | FPDFText_GetCharIndexFromTextIndex(FPDF_TEXTPAGE text_page, int nTextIndex); 25 | 26 | // Get the text index in |text_page| internal character list. 27 | // 28 | // text_page - a text page information structure. 29 | // nCharIndex - index of the character in internal character list. 30 | // 31 | // Returns the index of the text returned from FPDFText_GetText(). -1 for error. 32 | FPDF_EXPORT int FPDF_CALLCONV 33 | FPDFText_GetTextIndexFromCharIndex(FPDF_TEXTPAGE text_page, int nCharIndex); 34 | 35 | #ifdef __cplusplus 36 | } // extern "C" 37 | #endif // __cplusplus 38 | 39 | #endif // PUBLIC_FPDF_SEARCHEX_H_ 40 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_signature.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_FPDF_SIGNATURE_H_ 6 | #define PUBLIC_FPDF_SIGNATURE_H_ 7 | 8 | // NOLINTNEXTLINE(build/include) 9 | #include "fpdfview.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif // __cplusplus 14 | 15 | // Experimental API. 16 | // Function: FPDF_GetSignatureCount 17 | // Get total number of signatures in the document. 18 | // Parameters: 19 | // document - Handle to document. Returned by FPDF_LoadDocument(). 20 | // Return value: 21 | // Total number of signatures in the document on success, -1 on error. 22 | FPDF_EXPORT int FPDF_CALLCONV FPDF_GetSignatureCount(FPDF_DOCUMENT document); 23 | 24 | // Experimental API. 25 | // Function: FPDF_GetSignatureObject 26 | // Get the Nth signature of the document. 27 | // Parameters: 28 | // document - Handle to document. Returned by FPDF_LoadDocument(). 29 | // index - Index into the array of signatures of the document. 30 | // Return value: 31 | // Returns the handle to the signature, or NULL on failure. The caller 32 | // does not take ownership of the returned FPDF_SIGNATURE. Instead, it 33 | // remains valid until FPDF_CloseDocument() is called for the document. 34 | FPDF_EXPORT FPDF_SIGNATURE FPDF_CALLCONV 35 | FPDF_GetSignatureObject(FPDF_DOCUMENT document, int index); 36 | 37 | // Experimental API. 38 | // Function: FPDFSignatureObj_GetContents 39 | // Get the contents of a signature object. 40 | // Parameters: 41 | // signature - Handle to the signature object. Returned by 42 | // FPDF_GetSignatureObject(). 43 | // buffer - The address of a buffer that receives the contents. 44 | // length - The size, in bytes, of |buffer|. 45 | // Return value: 46 | // Returns the number of bytes in the contents on success, 0 on error. 47 | // 48 | // For public-key signatures, |buffer| is either a DER-encoded PKCS#1 binary or 49 | // a DER-encoded PKCS#7 binary. If |length| is less than the returned length, or 50 | // |buffer| is NULL, |buffer| will not be modified. 51 | FPDF_EXPORT unsigned long FPDF_CALLCONV 52 | FPDFSignatureObj_GetContents(FPDF_SIGNATURE signature, 53 | void* buffer, 54 | unsigned long length); 55 | 56 | // Experimental API. 57 | // Function: FPDFSignatureObj_GetByteRange 58 | // Get the byte range of a signature object. 59 | // Parameters: 60 | // signature - Handle to the signature object. Returned by 61 | // FPDF_GetSignatureObject(). 62 | // buffer - The address of a buffer that receives the 63 | // byte range. 64 | // length - The size, in ints, of |buffer|. 65 | // Return value: 66 | // Returns the number of ints in the byte range on 67 | // success, 0 on error. 68 | // 69 | // |buffer| is an array of pairs of integers (starting byte offset, 70 | // length in bytes) that describes the exact byte range for the digest 71 | // calculation. If |length| is less than the returned length, or 72 | // |buffer| is NULL, |buffer| will not be modified. 73 | FPDF_EXPORT unsigned long FPDF_CALLCONV 74 | FPDFSignatureObj_GetByteRange(FPDF_SIGNATURE signature, 75 | int* buffer, 76 | unsigned long length); 77 | 78 | // Experimental API. 79 | // Function: FPDFSignatureObj_GetSubFilter 80 | // Get the encoding of the value of a signature object. 81 | // Parameters: 82 | // signature - Handle to the signature object. Returned by 83 | // FPDF_GetSignatureObject(). 84 | // buffer - The address of a buffer that receives the encoding. 85 | // length - The size, in bytes, of |buffer|. 86 | // Return value: 87 | // Returns the number of bytes in the encoding name (including the 88 | // trailing NUL character) on success, 0 on error. 89 | // 90 | // The |buffer| is always encoded in 7-bit ASCII. If |length| is less than the 91 | // returned length, or |buffer| is NULL, |buffer| will not be modified. 92 | FPDF_EXPORT unsigned long FPDF_CALLCONV 93 | FPDFSignatureObj_GetSubFilter(FPDF_SIGNATURE signature, 94 | char* buffer, 95 | unsigned long length); 96 | 97 | // Experimental API. 98 | // Function: FPDFSignatureObj_GetReason 99 | // Get the reason (comment) of the signature object. 100 | // Parameters: 101 | // signature - Handle to the signature object. Returned by 102 | // FPDF_GetSignatureObject(). 103 | // buffer - The address of a buffer that receives the reason. 104 | // length - The size, in bytes, of |buffer|. 105 | // Return value: 106 | // Returns the number of bytes in the reason on success, 0 on error. 107 | // 108 | // Regardless of the platform, the |buffer| is always in UTF-16LE encoding. The 109 | // string is terminated by a UTF16 NUL character. If |length| is less than the 110 | // returned length, or |buffer| is NULL, |buffer| will not be modified. 111 | FPDF_EXPORT unsigned long FPDF_CALLCONV 112 | FPDFSignatureObj_GetReason(FPDF_SIGNATURE signature, 113 | void* buffer, 114 | unsigned long length); 115 | 116 | // Experimental API. 117 | // Function: FPDFSignatureObj_GetTime 118 | // Get the time of signing of a signature object. 119 | // Parameters: 120 | // signature - Handle to the signature object. Returned by 121 | // FPDF_GetSignatureObject(). 122 | // buffer - The address of a buffer that receives the time. 123 | // length - The size, in bytes, of |buffer|. 124 | // Return value: 125 | // Returns the number of bytes in the encoding name (including the 126 | // trailing NUL character) on success, 0 on error. 127 | // 128 | // The |buffer| is always encoded in 7-bit ASCII. If |length| is less than the 129 | // returned length, or |buffer| is NULL, |buffer| will not be modified. 130 | // 131 | // The format of time is expected to be D:YYYYMMDDHHMMSS+XX'YY', i.e. it's 132 | // percision is seconds, with timezone information. This value should be used 133 | // only when the time of signing is not available in the (PKCS#7 binary) 134 | // signature. 135 | FPDF_EXPORT unsigned long FPDF_CALLCONV 136 | FPDFSignatureObj_GetTime(FPDF_SIGNATURE signature, 137 | char* buffer, 138 | unsigned long length); 139 | 140 | // Experimental API. 141 | // Function: FPDFSignatureObj_GetDocMDPPermission 142 | // Get the DocMDP permission of a signature object. 143 | // Parameters: 144 | // signature - Handle to the signature object. Returned by 145 | // FPDF_GetSignatureObject(). 146 | // Return value: 147 | // Returns the permission (1, 2 or 3) on success, 0 on error. 148 | FPDF_EXPORT unsigned int FPDF_CALLCONV 149 | FPDFSignatureObj_GetDocMDPPermission(FPDF_SIGNATURE signature); 150 | 151 | #ifdef __cplusplus 152 | } // extern "C" 153 | #endif // __cplusplus 154 | 155 | #endif // PUBLIC_FPDF_SIGNATURE_H_ 156 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_structtree.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_STRUCTTREE_H_ 8 | #define PUBLIC_FPDF_STRUCTTREE_H_ 9 | 10 | // clang-format off 11 | // NOLINTNEXTLINE(build/include) 12 | #include "fpdfview.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | // Function: FPDF_StructTree_GetForPage 19 | // Get the structure tree for a page. 20 | // Parameters: 21 | // page - Handle to the page, as returned by FPDF_LoadPage(). 22 | // Return value: 23 | // A handle to the structure tree or NULL on error. 24 | FPDF_EXPORT FPDF_STRUCTTREE FPDF_CALLCONV 25 | FPDF_StructTree_GetForPage(FPDF_PAGE page); 26 | 27 | // Function: FPDF_StructTree_Close 28 | // Release a resource allocated by FPDF_StructTree_GetForPage(). 29 | // Parameters: 30 | // struct_tree - Handle to the structure tree, as returned by 31 | // FPDF_StructTree_LoadPage(). 32 | // Return value: 33 | // None. 34 | FPDF_EXPORT void FPDF_CALLCONV 35 | FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree); 36 | 37 | // Function: FPDF_StructTree_CountChildren 38 | // Count the number of children for the structure tree. 39 | // Parameters: 40 | // struct_tree - Handle to the structure tree, as returned by 41 | // FPDF_StructTree_LoadPage(). 42 | // Return value: 43 | // The number of children, or -1 on error. 44 | FPDF_EXPORT int FPDF_CALLCONV 45 | FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree); 46 | 47 | // Function: FPDF_StructTree_GetChildAtIndex 48 | // Get a child in the structure tree. 49 | // Parameters: 50 | // struct_tree - Handle to the structure tree, as returned by 51 | // FPDF_StructTree_LoadPage(). 52 | // index - The index for the child, 0-based. 53 | // Return value: 54 | // The child at the n-th index or NULL on error. 55 | FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV 56 | FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index); 57 | 58 | // Function: FPDF_StructElement_GetAltText 59 | // Get the alt text for a given element. 60 | // Parameters: 61 | // struct_element - Handle to the struct element. 62 | // buffer - A buffer for output the alt text. May be NULL. 63 | // buflen - The length of the buffer, in bytes. May be 0. 64 | // Return value: 65 | // The number of bytes in the alt text, including the terminating NUL 66 | // character. The number of bytes is returned regardless of the 67 | // |buffer| and |buflen| parameters. 68 | // Comments: 69 | // Regardless of the platform, the |buffer| is always in UTF-16LE 70 | // encoding. The string is terminated by a UTF16 NUL character. If 71 | // |buflen| is less than the required length, or |buffer| is NULL, 72 | // |buffer| will not be modified. 73 | FPDF_EXPORT unsigned long FPDF_CALLCONV 74 | FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element, 75 | void* buffer, 76 | unsigned long buflen); 77 | 78 | // Experimental API. 79 | // Function: FPDF_StructElement_GetActualText 80 | // Get the actual text for a given element. 81 | // Parameters: 82 | // struct_element - Handle to the struct element. 83 | // buffer - A buffer for output the actual text. May be NULL. 84 | // buflen - The length of the buffer, in bytes. May be 0. 85 | // Return value: 86 | // The number of bytes in the actual text, including the terminating 87 | // NUL character. The number of bytes is returned regardless of the 88 | // |buffer| and |buflen| parameters. 89 | // Comments: 90 | // Regardless of the platform, the |buffer| is always in UTF-16LE 91 | // encoding. The string is terminated by a UTF16 NUL character. If 92 | // |buflen| is less than the required length, or |buffer| is NULL, 93 | // |buffer| will not be modified. 94 | FPDF_EXPORT unsigned long FPDF_CALLCONV 95 | FPDF_StructElement_GetActualText(FPDF_STRUCTELEMENT struct_element, 96 | void* buffer, 97 | unsigned long buflen); 98 | 99 | // Function: FPDF_StructElement_GetID 100 | // Get the ID for a given element. 101 | // Parameters: 102 | // struct_element - Handle to the struct element. 103 | // buffer - A buffer for output the ID string. May be NULL. 104 | // buflen - The length of the buffer, in bytes. May be 0. 105 | // Return value: 106 | // The number of bytes in the ID string, including the terminating NUL 107 | // character. The number of bytes is returned regardless of the 108 | // |buffer| and |buflen| parameters. 109 | // Comments: 110 | // Regardless of the platform, the |buffer| is always in UTF-16LE 111 | // encoding. The string is terminated by a UTF16 NUL character. If 112 | // |buflen| is less than the required length, or |buffer| is NULL, 113 | // |buffer| will not be modified. 114 | FPDF_EXPORT unsigned long FPDF_CALLCONV 115 | FPDF_StructElement_GetID(FPDF_STRUCTELEMENT struct_element, 116 | void* buffer, 117 | unsigned long buflen); 118 | 119 | // Experimental API. 120 | // Function: FPDF_StructElement_GetLang 121 | // Get the case-insensitive IETF BCP 47 language code for an element. 122 | // Parameters: 123 | // struct_element - Handle to the struct element. 124 | // buffer - A buffer for output the lang string. May be NULL. 125 | // buflen - The length of the buffer, in bytes. May be 0. 126 | // Return value: 127 | // The number of bytes in the ID string, including the terminating NUL 128 | // character. The number of bytes is returned regardless of the 129 | // |buffer| and |buflen| parameters. 130 | // Comments: 131 | // Regardless of the platform, the |buffer| is always in UTF-16LE 132 | // encoding. The string is terminated by a UTF16 NUL character. If 133 | // |buflen| is less than the required length, or |buffer| is NULL, 134 | // |buffer| will not be modified. 135 | FPDF_EXPORT unsigned long FPDF_CALLCONV 136 | FPDF_StructElement_GetLang(FPDF_STRUCTELEMENT struct_element, 137 | void* buffer, 138 | unsigned long buflen); 139 | 140 | // Experimental API. 141 | // Function: FPDF_StructElement_GetStringAttribute 142 | // Get a struct element attribute of type "name" or "string". 143 | // Parameters: 144 | // struct_element - Handle to the struct element. 145 | // attr_name - The name of the attribute to retrieve. 146 | // buffer - A buffer for output. May be NULL. 147 | // buflen - The length of the buffer, in bytes. May be 0. 148 | // Return value: 149 | // The number of bytes in the attribute value, including the 150 | // terminating NUL character. The number of bytes is returned 151 | // regardless of the |buffer| and |buflen| parameters. 152 | // Comments: 153 | // Regardless of the platform, the |buffer| is always in UTF-16LE 154 | // encoding. The string is terminated by a UTF16 NUL character. If 155 | // |buflen| is less than the required length, or |buffer| is NULL, 156 | // |buffer| will not be modified. 157 | FPDF_EXPORT unsigned long FPDF_CALLCONV 158 | FPDF_StructElement_GetStringAttribute(FPDF_STRUCTELEMENT struct_element, 159 | FPDF_BYTESTRING attr_name, 160 | void* buffer, 161 | unsigned long buflen); 162 | 163 | // Function: FPDF_StructElement_GetMarkedContentID 164 | // Get the marked content ID for a given element. 165 | // Parameters: 166 | // struct_element - Handle to the struct element. 167 | // Return value: 168 | // The marked content ID of the element. If no ID exists, returns 169 | // -1. 170 | FPDF_EXPORT int FPDF_CALLCONV 171 | FPDF_StructElement_GetMarkedContentID(FPDF_STRUCTELEMENT struct_element); 172 | 173 | // Function: FPDF_StructElement_GetType 174 | // Get the type (/S) for a given element. 175 | // Parameters: 176 | // struct_element - Handle to the struct element. 177 | // buffer - A buffer for output. May be NULL. 178 | // buflen - The length of the buffer, in bytes. May be 0. 179 | // Return value: 180 | // The number of bytes in the type, including the terminating NUL 181 | // character. The number of bytes is returned regardless of the 182 | // |buffer| and |buflen| parameters. 183 | // Comments: 184 | // Regardless of the platform, the |buffer| is always in UTF-16LE 185 | // encoding. The string is terminated by a UTF16 NUL character. If 186 | // |buflen| is less than the required length, or |buffer| is NULL, 187 | // |buffer| will not be modified. 188 | FPDF_EXPORT unsigned long FPDF_CALLCONV 189 | FPDF_StructElement_GetType(FPDF_STRUCTELEMENT struct_element, 190 | void* buffer, 191 | unsigned long buflen); 192 | 193 | // Experimental API. 194 | // Function: FPDF_StructElement_GetObjType 195 | // Get the object type (/Type) for a given element. 196 | // Parameters: 197 | // struct_element - Handle to the struct element. 198 | // buffer - A buffer for output. May be NULL. 199 | // buflen - The length of the buffer, in bytes. May be 0. 200 | // Return value: 201 | // The number of bytes in the object type, including the terminating 202 | // NUL character. The number of bytes is returned regardless of the 203 | // |buffer| and |buflen| parameters. 204 | // Comments: 205 | // Regardless of the platform, the |buffer| is always in UTF-16LE 206 | // encoding. The string is terminated by a UTF16 NUL character. If 207 | // |buflen| is less than the required length, or |buffer| is NULL, 208 | // |buffer| will not be modified. 209 | FPDF_EXPORT unsigned long FPDF_CALLCONV 210 | FPDF_StructElement_GetObjType(FPDF_STRUCTELEMENT struct_element, 211 | void* buffer, 212 | unsigned long buflen); 213 | 214 | // Function: FPDF_StructElement_GetTitle 215 | // Get the title (/T) for a given element. 216 | // Parameters: 217 | // struct_element - Handle to the struct element. 218 | // buffer - A buffer for output. May be NULL. 219 | // buflen - The length of the buffer, in bytes. May be 0. 220 | // Return value: 221 | // The number of bytes in the title, including the terminating NUL 222 | // character. The number of bytes is returned regardless of the 223 | // |buffer| and |buflen| parameters. 224 | // Comments: 225 | // Regardless of the platform, the |buffer| is always in UTF-16LE 226 | // encoding. The string is terminated by a UTF16 NUL character. If 227 | // |buflen| is less than the required length, or |buffer| is NULL, 228 | // |buffer| will not be modified. 229 | FPDF_EXPORT unsigned long FPDF_CALLCONV 230 | FPDF_StructElement_GetTitle(FPDF_STRUCTELEMENT struct_element, 231 | void* buffer, 232 | unsigned long buflen); 233 | 234 | // Function: FPDF_StructElement_CountChildren 235 | // Count the number of children for the structure element. 236 | // Parameters: 237 | // struct_element - Handle to the struct element. 238 | // Return value: 239 | // The number of children, or -1 on error. 240 | FPDF_EXPORT int FPDF_CALLCONV 241 | FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element); 242 | 243 | // Function: FPDF_StructElement_GetChildAtIndex 244 | // Get a child in the structure element. 245 | // Parameters: 246 | // struct_element - Handle to the struct element. 247 | // index - The index for the child, 0-based. 248 | // Return value: 249 | // The child at the n-th index or NULL on error. 250 | // Comments: 251 | // If the child exists but is not an element, then this function will 252 | // return NULL. This will also return NULL for out of bounds indices. 253 | FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV 254 | FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element, 255 | int index); 256 | 257 | // Experimental API. 258 | // Function: FPDF_StructElement_GetChildMarkedContentID 259 | // Get the child's content id 260 | // Parameters: 261 | // struct_element - Handle to the struct element. 262 | // index - The index for the child, 0-based. 263 | // Return value: 264 | // The marked content ID of the child. If no ID exists, returns -1. 265 | // Comments: 266 | // If the child exists but is not a stream or object, then this 267 | // function will return -1. This will also return -1 for out of bounds 268 | // indices. Compared to FPDF_StructElement_GetMarkedContentIdAtIndex, 269 | // it is scoped to the current page. 270 | FPDF_EXPORT int FPDF_CALLCONV 271 | FPDF_StructElement_GetChildMarkedContentID(FPDF_STRUCTELEMENT struct_element, 272 | int index); 273 | 274 | // Experimental API. 275 | // Function: FPDF_StructElement_GetParent 276 | // Get the parent of the structure element. 277 | // Parameters: 278 | // struct_element - Handle to the struct element. 279 | // Return value: 280 | // The parent structure element or NULL on error. 281 | // Comments: 282 | // If structure element is StructTreeRoot, then this function will 283 | // return NULL. 284 | FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV 285 | FPDF_StructElement_GetParent(FPDF_STRUCTELEMENT struct_element); 286 | 287 | // Function: FPDF_StructElement_GetAttributeCount 288 | // Count the number of attributes for the structure element. 289 | // Parameters: 290 | // struct_element - Handle to the struct element. 291 | // Return value: 292 | // The number of attributes, or -1 on error. 293 | FPDF_EXPORT int FPDF_CALLCONV 294 | FPDF_StructElement_GetAttributeCount(FPDF_STRUCTELEMENT struct_element); 295 | 296 | // Experimental API. 297 | // Function: FPDF_StructElement_GetAttributeAtIndex 298 | // Get an attribute object in the structure element. 299 | // Parameters: 300 | // struct_element - Handle to the struct element. 301 | // index - The index for the attribute object, 0-based. 302 | // Return value: 303 | // The attribute object at the n-th index or NULL on error. 304 | // Comments: 305 | // If the attribute object exists but is not a dict, then this 306 | // function will return NULL. This will also return NULL for out of 307 | // bounds indices. 308 | FPDF_EXPORT FPDF_STRUCTELEMENT_ATTR FPDF_CALLCONV 309 | FPDF_StructElement_GetAttributeAtIndex(FPDF_STRUCTELEMENT struct_element, int index); 310 | 311 | // Experimental API. 312 | // Function: FPDF_StructElement_Attr_GetCount 313 | // Count the number of attributes in a structure element attribute map. 314 | // Parameters: 315 | // struct_attribute - Handle to the struct element attribute. 316 | // Return value: 317 | // The number of attributes, or -1 on error. 318 | FPDF_EXPORT int FPDF_CALLCONV 319 | FPDF_StructElement_Attr_GetCount(FPDF_STRUCTELEMENT_ATTR struct_attribute); 320 | 321 | 322 | // Experimental API. 323 | // Function: FPDF_StructElement_Attr_GetName 324 | // Get the name of an attribute in a structure element attribute map. 325 | // Parameters: 326 | // struct_attribute - Handle to the struct element attribute. 327 | // index - The index of attribute in the map. 328 | // buffer - A buffer for output. May be NULL. This is only 329 | // modified if |buflen| is longer than the length 330 | // of the key. Optional, pass null to just 331 | // retrieve the size of the buffer needed. 332 | // buflen - The length of the buffer. 333 | // out_buflen - A pointer to variable that will receive the 334 | // minimum buffer size to contain the key. Not 335 | // filled if FALSE is returned. 336 | // Return value: 337 | // TRUE if the operation was successful, FALSE otherwise. 338 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 339 | FPDF_StructElement_Attr_GetName(FPDF_STRUCTELEMENT_ATTR struct_attribute, 340 | int index, 341 | void* buffer, 342 | unsigned long buflen, 343 | unsigned long* out_buflen); 344 | 345 | // Experimental API. 346 | // Function: FPDF_StructElement_Attr_GetType 347 | // Get the type of an attribute in a structure element attribute map. 348 | // Parameters: 349 | // struct_attribute - Handle to the struct element attribute. 350 | // name - The attribute name. 351 | // Return value: 352 | // Returns the type of the value, or FPDF_OBJECT_UNKNOWN in case of 353 | // failure. 354 | FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV 355 | FPDF_StructElement_Attr_GetType(FPDF_STRUCTELEMENT_ATTR struct_attribute, 356 | FPDF_BYTESTRING name); 357 | 358 | // Experimental API. 359 | // Function: FPDF_StructElement_Attr_GetBooleanValue 360 | // Get the value of a boolean attribute in an attribute map by name as 361 | // FPDF_BOOL. FPDF_StructElement_Attr_GetType() should have returned 362 | // FPDF_OBJECT_BOOLEAN for this property. 363 | // Parameters: 364 | // struct_attribute - Handle to the struct element attribute. 365 | // name - The attribute name. 366 | // out_value - A pointer to variable that will receive the 367 | // value. Not filled if false is returned. 368 | // Return value: 369 | // Returns TRUE if the name maps to a boolean value, FALSE otherwise. 370 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 371 | FPDF_StructElement_Attr_GetBooleanValue( 372 | FPDF_STRUCTELEMENT_ATTR struct_attribute, 373 | FPDF_BYTESTRING name, 374 | FPDF_BOOL* out_value); 375 | 376 | // Experimental API. 377 | // Function: FPDF_StructElement_Attr_GetNumberValue 378 | // Get the value of a number attribute in an attribute map by name as 379 | // float. FPDF_StructElement_Attr_GetType() should have returned 380 | // FPDF_OBJECT_NUMBER for this property. 381 | // Parameters: 382 | // struct_attribute - Handle to the struct element attribute. 383 | // name - The attribute name. 384 | // out_value - A pointer to variable that will receive the 385 | // value. Not filled if false is returned. 386 | // Return value: 387 | // Returns TRUE if the name maps to a number value, FALSE otherwise. 388 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 389 | FPDF_StructElement_Attr_GetNumberValue(FPDF_STRUCTELEMENT_ATTR struct_attribute, 390 | FPDF_BYTESTRING name, 391 | float* out_value); 392 | 393 | // Experimental API. 394 | // Function: FPDF_StructElement_Attr_GetStringValue 395 | // Get the value of a string attribute in an attribute map by name as 396 | // string. FPDF_StructElement_Attr_GetType() should have returned 397 | // FPDF_OBJECT_STRING or FPDF_OBJECT_NAME for this property. 398 | // Parameters: 399 | // struct_attribute - Handle to the struct element attribute. 400 | // name - The attribute name. 401 | // buffer - A buffer for holding the returned key in 402 | // UTF-16LE. This is only modified if |buflen| is 403 | // longer than the length of the key. Optional, 404 | // pass null to just retrieve the size of the 405 | // buffer needed. 406 | // buflen - The length of the buffer. 407 | // out_buflen - A pointer to variable that will receive the 408 | // minimum buffer size to contain the key. Not 409 | // filled if FALSE is returned. 410 | // Return value: 411 | // Returns TRUE if the name maps to a string value, FALSE otherwise. 412 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 413 | FPDF_StructElement_Attr_GetStringValue(FPDF_STRUCTELEMENT_ATTR struct_attribute, 414 | FPDF_BYTESTRING name, 415 | void* buffer, 416 | unsigned long buflen, 417 | unsigned long* out_buflen); 418 | 419 | // Experimental API. 420 | // Function: FPDF_StructElement_Attr_GetBlobValue 421 | // Get the value of a blob attribute in an attribute map by name as 422 | // string. 423 | // Parameters: 424 | // struct_attribute - Handle to the struct element attribute. 425 | // name - The attribute name. 426 | // buffer - A buffer for holding the returned value. This 427 | // is only modified if |buflen| is at least as 428 | // long as the length of the value. Optional, pass 429 | // null to just retrieve the size of the buffer 430 | // needed. 431 | // buflen - The length of the buffer. 432 | // out_buflen - A pointer to variable that will receive the 433 | // minimum buffer size to contain the key. Not 434 | // filled if FALSE is returned. 435 | // Return value: 436 | // Returns TRUE if the name maps to a string value, FALSE otherwise. 437 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 438 | FPDF_StructElement_Attr_GetBlobValue(FPDF_STRUCTELEMENT_ATTR struct_attribute, 439 | FPDF_BYTESTRING name, 440 | void* buffer, 441 | unsigned long buflen, 442 | unsigned long* out_buflen); 443 | 444 | // Experimental API. 445 | // Function: FPDF_StructElement_GetMarkedContentIdCount 446 | // Get the count of marked content ids for a given element. 447 | // Parameters: 448 | // struct_element - Handle to the struct element. 449 | // Return value: 450 | // The count of marked content ids or -1 if none exists. 451 | FPDF_EXPORT int FPDF_CALLCONV 452 | FPDF_StructElement_GetMarkedContentIdCount(FPDF_STRUCTELEMENT struct_element); 453 | 454 | // Experimental API. 455 | // Function: FPDF_StructElement_GetMarkedContentIdAtIndex 456 | // Get the marked content id at a given index for a given element. 457 | // Parameters: 458 | // struct_element - Handle to the struct element. 459 | // index - The index of the marked content id, 0-based. 460 | // Return value: 461 | // The marked content ID of the element. If no ID exists, returns 462 | // -1. 463 | FPDF_EXPORT int FPDF_CALLCONV 464 | FPDF_StructElement_GetMarkedContentIdAtIndex(FPDF_STRUCTELEMENT struct_element, 465 | int index); 466 | 467 | #ifdef __cplusplus 468 | } // extern "C" 469 | #endif 470 | 471 | #endif // PUBLIC_FPDF_STRUCTTREE_H_ 472 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_sysfontinfo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_SYSFONTINFO_H_ 8 | #define PUBLIC_FPDF_SYSFONTINFO_H_ 9 | 10 | // clang-format off 11 | // NOLINTNEXTLINE(build/include) 12 | #include "fpdfview.h" 13 | 14 | /* Character sets for the font */ 15 | #define FXFONT_ANSI_CHARSET 0 16 | #define FXFONT_DEFAULT_CHARSET 1 17 | #define FXFONT_SYMBOL_CHARSET 2 18 | #define FXFONT_SHIFTJIS_CHARSET 128 19 | #define FXFONT_HANGEUL_CHARSET 129 20 | #define FXFONT_GB2312_CHARSET 134 21 | #define FXFONT_CHINESEBIG5_CHARSET 136 22 | #define FXFONT_GREEK_CHARSET 161 23 | #define FXFONT_VIETNAMESE_CHARSET 163 24 | #define FXFONT_HEBREW_CHARSET 177 25 | #define FXFONT_ARABIC_CHARSET 178 26 | #define FXFONT_CYRILLIC_CHARSET 204 27 | #define FXFONT_THAI_CHARSET 222 28 | #define FXFONT_EASTERNEUROPEAN_CHARSET 238 29 | 30 | /* Font pitch and family flags */ 31 | #define FXFONT_FF_FIXEDPITCH (1 << 0) 32 | #define FXFONT_FF_ROMAN (1 << 4) 33 | #define FXFONT_FF_SCRIPT (4 << 4) 34 | 35 | /* Typical weight values */ 36 | #define FXFONT_FW_NORMAL 400 37 | #define FXFONT_FW_BOLD 700 38 | 39 | // Exported Functions 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* 45 | * Interface: FPDF_SYSFONTINFO 46 | * Interface for getting system font information and font mapping 47 | */ 48 | typedef struct _FPDF_SYSFONTINFO { 49 | /* 50 | * Version number of the interface. Currently must be 1. 51 | */ 52 | int version; 53 | 54 | /* 55 | * Method: Release 56 | * Give implementation a chance to release any data after the 57 | * interface is no longer used. 58 | * Interface Version: 59 | * 1 60 | * Implementation Required: 61 | * No 62 | * Parameters: 63 | * pThis - Pointer to the interface structure itself 64 | * Return Value: 65 | * None 66 | * Comments: 67 | * Called by PDFium during the final cleanup process. 68 | */ 69 | void (*Release)(struct _FPDF_SYSFONTINFO* pThis); 70 | 71 | /* 72 | * Method: EnumFonts 73 | * Enumerate all fonts installed on the system 74 | * Interface Version: 75 | * 1 76 | * Implementation Required: 77 | * No 78 | * Parameters: 79 | * pThis - Pointer to the interface structure itself 80 | * pMapper - An opaque pointer to internal font mapper, used 81 | * when calling FPDF_AddInstalledFont(). 82 | * Return Value: 83 | * None 84 | * Comments: 85 | * Implementations should call FPDF_AddIntalledFont() function for 86 | * each font found. Only TrueType/OpenType and Type1 fonts are accepted 87 | * by PDFium. 88 | */ 89 | void (*EnumFonts)(struct _FPDF_SYSFONTINFO* pThis, void* pMapper); 90 | 91 | /* 92 | * Method: MapFont 93 | * Use the system font mapper to get a font handle from requested 94 | * parameters. 95 | * Interface Version: 96 | * 1 97 | * Implementation Required: 98 | * Required if GetFont method is not implemented. 99 | * Parameters: 100 | * pThis - Pointer to the interface structure itself 101 | * weight - Weight of the requested font. 400 is normal and 102 | * 700 is bold. 103 | * bItalic - Italic option of the requested font, TRUE or 104 | * FALSE. 105 | * charset - Character set identifier for the requested font. 106 | * See above defined constants. 107 | * pitch_family - A combination of flags. See above defined 108 | * constants. 109 | * face - Typeface name. Currently use system local encoding 110 | * only. 111 | * bExact - Obsolete: this parameter is now ignored. 112 | * Return Value: 113 | * An opaque pointer for font handle, or NULL if system mapping is 114 | * not supported. 115 | * Comments: 116 | * If the system supports native font mapper (like Windows), 117 | * implementation can implement this method to get a font handle. 118 | * Otherwise, PDFium will do the mapping and then call GetFont 119 | * method. Only TrueType/OpenType and Type1 fonts are accepted 120 | * by PDFium. 121 | */ 122 | void* (*MapFont)(struct _FPDF_SYSFONTINFO* pThis, 123 | int weight, 124 | FPDF_BOOL bItalic, 125 | int charset, 126 | int pitch_family, 127 | const char* face, 128 | FPDF_BOOL* bExact); 129 | 130 | /* 131 | * Method: GetFont 132 | * Get a handle to a particular font by its internal ID 133 | * Interface Version: 134 | * 1 135 | * Implementation Required: 136 | * Required if MapFont method is not implemented. 137 | * Return Value: 138 | * An opaque pointer for font handle. 139 | * Parameters: 140 | * pThis - Pointer to the interface structure itself 141 | * face - Typeface name in system local encoding. 142 | * Comments: 143 | * If the system mapping not supported, PDFium will do the font 144 | * mapping and use this method to get a font handle. 145 | */ 146 | void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face); 147 | 148 | /* 149 | * Method: GetFontData 150 | * Get font data from a font 151 | * Interface Version: 152 | * 1 153 | * Implementation Required: 154 | * Yes 155 | * Parameters: 156 | * pThis - Pointer to the interface structure itself 157 | * hFont - Font handle returned by MapFont or GetFont method 158 | * table - TrueType/OpenType table identifier (refer to 159 | * TrueType specification), or 0 for the whole file. 160 | * buffer - The buffer receiving the font data. Can be NULL if 161 | * not provided. 162 | * buf_size - Buffer size, can be zero if not provided. 163 | * Return Value: 164 | * Number of bytes needed, if buffer not provided or not large 165 | * enough, or number of bytes written into buffer otherwise. 166 | * Comments: 167 | * Can read either the full font file, or a particular 168 | * TrueType/OpenType table. 169 | */ 170 | unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis, 171 | void* hFont, 172 | unsigned int table, 173 | unsigned char* buffer, 174 | unsigned long buf_size); 175 | 176 | /* 177 | * Method: GetFaceName 178 | * Get face name from a font handle 179 | * Interface Version: 180 | * 1 181 | * Implementation Required: 182 | * No 183 | * Parameters: 184 | * pThis - Pointer to the interface structure itself 185 | * hFont - Font handle returned by MapFont or GetFont method 186 | * buffer - The buffer receiving the face name. Can be NULL if 187 | * not provided 188 | * buf_size - Buffer size, can be zero if not provided 189 | * Return Value: 190 | * Number of bytes needed, if buffer not provided or not large 191 | * enough, or number of bytes written into buffer otherwise. 192 | */ 193 | unsigned long (*GetFaceName)(struct _FPDF_SYSFONTINFO* pThis, 194 | void* hFont, 195 | char* buffer, 196 | unsigned long buf_size); 197 | 198 | /* 199 | * Method: GetFontCharset 200 | * Get character set information for a font handle 201 | * Interface Version: 202 | * 1 203 | * Implementation Required: 204 | * No 205 | * Parameters: 206 | * pThis - Pointer to the interface structure itself 207 | * hFont - Font handle returned by MapFont or GetFont method 208 | * Return Value: 209 | * Character set identifier. See defined constants above. 210 | */ 211 | int (*GetFontCharset)(struct _FPDF_SYSFONTINFO* pThis, void* hFont); 212 | 213 | /* 214 | * Method: DeleteFont 215 | * Delete a font handle 216 | * Interface Version: 217 | * 1 218 | * Implementation Required: 219 | * Yes 220 | * Parameters: 221 | * pThis - Pointer to the interface structure itself 222 | * hFont - Font handle returned by MapFont or GetFont method 223 | * Return Value: 224 | * None 225 | */ 226 | void (*DeleteFont)(struct _FPDF_SYSFONTINFO* pThis, void* hFont); 227 | } FPDF_SYSFONTINFO; 228 | 229 | /* 230 | * Struct: FPDF_CharsetFontMap 231 | * Provides the name of a font to use for a given charset value. 232 | */ 233 | typedef struct FPDF_CharsetFontMap_ { 234 | int charset; // Character Set Enum value, see FXFONT_*_CHARSET above. 235 | const char* fontname; // Name of default font to use with that charset. 236 | } FPDF_CharsetFontMap; 237 | 238 | /* 239 | * Function: FPDF_GetDefaultTTFMap 240 | * Returns a pointer to the default character set to TT Font name map. The 241 | * map is an array of FPDF_CharsetFontMap structs, with its end indicated 242 | * by a { -1, NULL } entry. 243 | * Parameters: 244 | * None. 245 | * Return Value: 246 | * Pointer to the Charset Font Map. 247 | */ 248 | FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap(); 249 | 250 | /* 251 | * Function: FPDF_AddInstalledFont 252 | * Add a system font to the list in PDFium. 253 | * Comments: 254 | * This function is only called during the system font list building 255 | * process. 256 | * Parameters: 257 | * mapper - Opaque pointer to Foxit font mapper 258 | * face - The font face name 259 | * charset - Font character set. See above defined constants. 260 | * Return Value: 261 | * None. 262 | */ 263 | FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void* mapper, 264 | const char* face, 265 | int charset); 266 | 267 | /* 268 | * Function: FPDF_SetSystemFontInfo 269 | * Set the system font info interface into PDFium 270 | * Parameters: 271 | * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure 272 | * Return Value: 273 | * None 274 | * Comments: 275 | * Platform support implementation should implement required methods of 276 | * FFDF_SYSFONTINFO interface, then call this function during PDFium 277 | * initialization process. 278 | * 279 | * Call this with NULL to tell PDFium to stop using a previously set 280 | * |FPDF_SYSFONTINFO|. 281 | */ 282 | FPDF_EXPORT void FPDF_CALLCONV 283 | FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); 284 | 285 | /* 286 | * Function: FPDF_GetDefaultSystemFontInfo 287 | * Get default system font info interface for current platform 288 | * Parameters: 289 | * None 290 | * Return Value: 291 | * Pointer to a FPDF_SYSFONTINFO structure describing the default 292 | * interface, or NULL if the platform doesn't have a default interface. 293 | * Application should call FPDF_FreeDefaultSystemFontInfo to free the 294 | * returned pointer. 295 | * Comments: 296 | * For some platforms, PDFium implements a default version of system 297 | * font info interface. The default implementation can be passed to 298 | * FPDF_SetSystemFontInfo(). 299 | */ 300 | FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo(); 301 | 302 | /* 303 | * Function: FPDF_FreeDefaultSystemFontInfo 304 | * Free a default system font info interface 305 | * Parameters: 306 | * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure 307 | * Return Value: 308 | * None 309 | * Comments: 310 | * This function should be called on the output from 311 | * FPDF_GetDefaultSystemFontInfo() once it is no longer needed. 312 | */ 313 | FPDF_EXPORT void FPDF_CALLCONV 314 | FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); 315 | 316 | #ifdef __cplusplus 317 | } 318 | #endif 319 | 320 | #endif // PUBLIC_FPDF_SYSFONTINFO_H_ 321 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_thumbnail.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PUBLIC_FPDF_THUMBNAIL_H_ 6 | #define PUBLIC_FPDF_THUMBNAIL_H_ 7 | 8 | #include 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | // Experimental API. 18 | // Gets the decoded data from the thumbnail of |page| if it exists. 19 | // This only modifies |buffer| if |buflen| less than or equal to the 20 | // size of the decoded data. Returns the size of the decoded 21 | // data or 0 if thumbnail DNE. Optional, pass null to just retrieve 22 | // the size of the buffer needed. 23 | // 24 | // page - handle to a page. 25 | // buffer - buffer for holding the decoded image data. 26 | // buflen - length of the buffer in bytes. 27 | FPDF_EXPORT unsigned long FPDF_CALLCONV 28 | FPDFPage_GetDecodedThumbnailData(FPDF_PAGE page, 29 | void* buffer, 30 | unsigned long buflen); 31 | 32 | // Experimental API. 33 | // Gets the raw data from the thumbnail of |page| if it exists. 34 | // This only modifies |buffer| if |buflen| is less than or equal to 35 | // the size of the raw data. Returns the size of the raw data or 0 36 | // if thumbnail DNE. Optional, pass null to just retrieve the size 37 | // of the buffer needed. 38 | // 39 | // page - handle to a page. 40 | // buffer - buffer for holding the raw image data. 41 | // buflen - length of the buffer in bytes. 42 | FPDF_EXPORT unsigned long FPDF_CALLCONV 43 | FPDFPage_GetRawThumbnailData(FPDF_PAGE page, 44 | void* buffer, 45 | unsigned long buflen); 46 | 47 | // Experimental API. 48 | // Returns the thumbnail of |page| as a FPDF_BITMAP. Returns a nullptr 49 | // if unable to access the thumbnail's stream. 50 | // 51 | // page - handle to a page. 52 | FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV 53 | FPDFPage_GetThumbnailAsBitmap(FPDF_PAGE page); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif // PUBLIC_FPDF_THUMBNAIL_H_ 60 | -------------------------------------------------------------------------------- /src/main/cpp/include/fpdf_transformpage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The PDFium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 | 7 | #ifndef PUBLIC_FPDF_TRANSFORMPAGE_H_ 8 | #define PUBLIC_FPDF_TRANSFORMPAGE_H_ 9 | 10 | // NOLINTNEXTLINE(build/include) 11 | #include "fpdfview.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | /** 18 | * Set "MediaBox" entry to the page dictionary. 19 | * 20 | * page - Handle to a page. 21 | * left - The left of the rectangle. 22 | * bottom - The bottom of the rectangle. 23 | * right - The right of the rectangle. 24 | * top - The top of the rectangle. 25 | */ 26 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetMediaBox(FPDF_PAGE page, 27 | float left, 28 | float bottom, 29 | float right, 30 | float top); 31 | 32 | /** 33 | * Set "CropBox" entry to the page dictionary. 34 | * 35 | * page - Handle to a page. 36 | * left - The left of the rectangle. 37 | * bottom - The bottom of the rectangle. 38 | * right - The right of the rectangle. 39 | * top - The top of the rectangle. 40 | */ 41 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetCropBox(FPDF_PAGE page, 42 | float left, 43 | float bottom, 44 | float right, 45 | float top); 46 | 47 | /** 48 | * Set "BleedBox" entry to the page dictionary. 49 | * 50 | * page - Handle to a page. 51 | * left - The left of the rectangle. 52 | * bottom - The bottom of the rectangle. 53 | * right - The right of the rectangle. 54 | * top - The top of the rectangle. 55 | */ 56 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetBleedBox(FPDF_PAGE page, 57 | float left, 58 | float bottom, 59 | float right, 60 | float top); 61 | 62 | /** 63 | * Set "TrimBox" entry to the page dictionary. 64 | * 65 | * page - Handle to a page. 66 | * left - The left of the rectangle. 67 | * bottom - The bottom of the rectangle. 68 | * right - The right of the rectangle. 69 | * top - The top of the rectangle. 70 | */ 71 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetTrimBox(FPDF_PAGE page, 72 | float left, 73 | float bottom, 74 | float right, 75 | float top); 76 | 77 | /** 78 | * Set "ArtBox" entry to the page dictionary. 79 | * 80 | * page - Handle to a page. 81 | * left - The left of the rectangle. 82 | * bottom - The bottom of the rectangle. 83 | * right - The right of the rectangle. 84 | * top - The top of the rectangle. 85 | */ 86 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetArtBox(FPDF_PAGE page, 87 | float left, 88 | float bottom, 89 | float right, 90 | float top); 91 | 92 | /** 93 | * Get "MediaBox" entry from the page dictionary. 94 | * 95 | * page - Handle to a page. 96 | * left - Pointer to a float value receiving the left of the rectangle. 97 | * bottom - Pointer to a float value receiving the bottom of the rectangle. 98 | * right - Pointer to a float value receiving the right of the rectangle. 99 | * top - Pointer to a float value receiving the top of the rectangle. 100 | * 101 | * On success, return true and write to the out parameters. Otherwise return 102 | * false and leave the out parameters unmodified. 103 | */ 104 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetMediaBox(FPDF_PAGE page, 105 | float* left, 106 | float* bottom, 107 | float* right, 108 | float* top); 109 | 110 | /** 111 | * Get "CropBox" entry from the page dictionary. 112 | * 113 | * page - Handle to a page. 114 | * left - Pointer to a float value receiving the left of the rectangle. 115 | * bottom - Pointer to a float value receiving the bottom of the rectangle. 116 | * right - Pointer to a float value receiving the right of the rectangle. 117 | * top - Pointer to a float value receiving the top of the rectangle. 118 | * 119 | * On success, return true and write to the out parameters. Otherwise return 120 | * false and leave the out parameters unmodified. 121 | */ 122 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetCropBox(FPDF_PAGE page, 123 | float* left, 124 | float* bottom, 125 | float* right, 126 | float* top); 127 | 128 | /** 129 | * Get "BleedBox" entry from the page dictionary. 130 | * 131 | * page - Handle to a page. 132 | * left - Pointer to a float value receiving the left of the rectangle. 133 | * bottom - Pointer to a float value receiving the bottom of the rectangle. 134 | * right - Pointer to a float value receiving the right of the rectangle. 135 | * top - Pointer to a float value receiving the top of the rectangle. 136 | * 137 | * On success, return true and write to the out parameters. Otherwise return 138 | * false and leave the out parameters unmodified. 139 | */ 140 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetBleedBox(FPDF_PAGE page, 141 | float* left, 142 | float* bottom, 143 | float* right, 144 | float* top); 145 | 146 | /** 147 | * Get "TrimBox" entry from the page dictionary. 148 | * 149 | * page - Handle to a page. 150 | * left - Pointer to a float value receiving the left of the rectangle. 151 | * bottom - Pointer to a float value receiving the bottom of the rectangle. 152 | * right - Pointer to a float value receiving the right of the rectangle. 153 | * top - Pointer to a float value receiving the top of the rectangle. 154 | * 155 | * On success, return true and write to the out parameters. Otherwise return 156 | * false and leave the out parameters unmodified. 157 | */ 158 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetTrimBox(FPDF_PAGE page, 159 | float* left, 160 | float* bottom, 161 | float* right, 162 | float* top); 163 | 164 | /** 165 | * Get "ArtBox" entry from the page dictionary. 166 | * 167 | * page - Handle to a page. 168 | * left - Pointer to a float value receiving the left of the rectangle. 169 | * bottom - Pointer to a float value receiving the bottom of the rectangle. 170 | * right - Pointer to a float value receiving the right of the rectangle. 171 | * top - Pointer to a float value receiving the top of the rectangle. 172 | * 173 | * On success, return true and write to the out parameters. Otherwise return 174 | * false and leave the out parameters unmodified. 175 | */ 176 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetArtBox(FPDF_PAGE page, 177 | float* left, 178 | float* bottom, 179 | float* right, 180 | float* top); 181 | 182 | /** 183 | * Apply transforms to |page|. 184 | * 185 | * If |matrix| is provided it will be applied to transform the page. 186 | * If |clipRect| is provided it will be used to clip the resulting page. 187 | * If neither |matrix| or |clipRect| are provided this method returns |false|. 188 | * Returns |true| if transforms are applied. 189 | * 190 | * This function will transform the whole page, and would take effect to all the 191 | * objects in the page. 192 | * 193 | * page - Page handle. 194 | * matrix - Transform matrix. 195 | * clipRect - Clipping rectangle. 196 | */ 197 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV 198 | FPDFPage_TransFormWithClip(FPDF_PAGE page, 199 | const FS_MATRIX* matrix, 200 | const FS_RECTF* clipRect); 201 | 202 | /** 203 | * Transform (scale, rotate, shear, move) the clip path of page object. 204 | * page_object - Handle to a page object. Returned by 205 | * FPDFPageObj_NewImageObj(). 206 | * 207 | * a - The coefficient "a" of the matrix. 208 | * b - The coefficient "b" of the matrix. 209 | * c - The coefficient "c" of the matrix. 210 | * d - The coefficient "d" of the matrix. 211 | * e - The coefficient "e" of the matrix. 212 | * f - The coefficient "f" of the matrix. 213 | */ 214 | FPDF_EXPORT void FPDF_CALLCONV 215 | FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object, 216 | double a, 217 | double b, 218 | double c, 219 | double d, 220 | double e, 221 | double f); 222 | 223 | // Experimental API. 224 | // Get the clip path of the page object. 225 | // 226 | // page object - Handle to a page object. Returned by e.g. 227 | // FPDFPage_GetObject(). 228 | // 229 | // Returns the handle to the clip path, or NULL on failure. The caller does not 230 | // take ownership of the returned FPDF_CLIPPATH. Instead, it remains valid until 231 | // FPDF_ClosePage() is called for the page containing |page_object|. 232 | FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV 233 | FPDFPageObj_GetClipPath(FPDF_PAGEOBJECT page_object); 234 | 235 | // Experimental API. 236 | // Get number of paths inside |clip_path|. 237 | // 238 | // clip_path - handle to a clip_path. 239 | // 240 | // Returns the number of objects in |clip_path| or -1 on failure. 241 | FPDF_EXPORT int FPDF_CALLCONV FPDFClipPath_CountPaths(FPDF_CLIPPATH clip_path); 242 | 243 | // Experimental API. 244 | // Get number of segments inside one path of |clip_path|. 245 | // 246 | // clip_path - handle to a clip_path. 247 | // path_index - index into the array of paths of the clip path. 248 | // 249 | // Returns the number of segments or -1 on failure. 250 | FPDF_EXPORT int FPDF_CALLCONV 251 | FPDFClipPath_CountPathSegments(FPDF_CLIPPATH clip_path, int path_index); 252 | 253 | // Experimental API. 254 | // Get segment in one specific path of |clip_path| at index. 255 | // 256 | // clip_path - handle to a clip_path. 257 | // path_index - the index of a path. 258 | // segment_index - the index of a segment. 259 | // 260 | // Returns the handle to the segment, or NULL on failure. The caller does not 261 | // take ownership of the returned FPDF_PATHSEGMENT. Instead, it remains valid 262 | // until FPDF_ClosePage() is called for the page containing |clip_path|. 263 | FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV 264 | FPDFClipPath_GetPathSegment(FPDF_CLIPPATH clip_path, 265 | int path_index, 266 | int segment_index); 267 | 268 | /** 269 | * Create a new clip path, with a rectangle inserted. 270 | * 271 | * Caller takes ownership of the returned FPDF_CLIPPATH. It should be freed with 272 | * FPDF_DestroyClipPath(). 273 | * 274 | * left - The left of the clip box. 275 | * bottom - The bottom of the clip box. 276 | * right - The right of the clip box. 277 | * top - The top of the clip box. 278 | */ 279 | FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV FPDF_CreateClipPath(float left, 280 | float bottom, 281 | float right, 282 | float top); 283 | 284 | /** 285 | * Destroy the clip path. 286 | * 287 | * clipPath - A handle to the clip path. It will be invalid after this call. 288 | */ 289 | FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath); 290 | 291 | /** 292 | * Clip the page content, the page content that outside the clipping region 293 | * become invisible. 294 | * 295 | * A clip path will be inserted before the page content stream or content array. 296 | * In this way, the page content will be clipped by this clip path. 297 | * 298 | * page - A page handle. 299 | * clipPath - A handle to the clip path. (Does not take ownership.) 300 | */ 301 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, 302 | FPDF_CLIPPATH clipPath); 303 | 304 | #ifdef __cplusplus 305 | } 306 | #endif 307 | 308 | #endif // PUBLIC_FPDF_TRANSFORMPAGE_H_ 309 | -------------------------------------------------------------------------------- /src/main/cpp/include/utils/Errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_ERRORS_H 18 | #define ANDROID_ERRORS_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | // use this type to return error codes 26 | #ifdef HAVE_MS_C_RUNTIME 27 | typedef int status_t; 28 | #else 29 | typedef int32_t status_t; 30 | #endif 31 | 32 | /* the MS C runtime lacks a few error codes */ 33 | 34 | /* 35 | * Error codes. 36 | * All error codes are negative values. 37 | */ 38 | 39 | // Win32 #defines NO_ERROR as well. It has the same value, so there's no 40 | // real conflict, though it's a bit awkward. 41 | #ifdef _WIN32 42 | # undef NO_ERROR 43 | #endif 44 | 45 | enum { 46 | OK = 0, // Everything's swell. 47 | NO_ERROR = 0, // No errors. 48 | 49 | UNKNOWN_ERROR = (-2147483647-1), // INT32_MIN value 50 | 51 | NO_MEMORY = -ENOMEM, 52 | INVALID_OPERATION = -ENOSYS, 53 | BAD_VALUE = -EINVAL, 54 | BAD_TYPE = (UNKNOWN_ERROR + 1), 55 | NAME_NOT_FOUND = -ENOENT, 56 | PERMISSION_DENIED = -EPERM, 57 | NO_INIT = -ENODEV, 58 | ALREADY_EXISTS = -EEXIST, 59 | DEAD_OBJECT = -EPIPE, 60 | FAILED_TRANSACTION = (UNKNOWN_ERROR + 2), 61 | JPARKS_BROKE_IT = -EPIPE, 62 | #if !defined(HAVE_MS_C_RUNTIME) 63 | BAD_INDEX = -EOVERFLOW, 64 | NOT_ENOUGH_DATA = -ENODATA, 65 | WOULD_BLOCK = -EWOULDBLOCK, 66 | TIMED_OUT = -ETIMEDOUT, 67 | UNKNOWN_TRANSACTION = -EBADMSG, 68 | #else 69 | BAD_INDEX = -E2BIG, 70 | NOT_ENOUGH_DATA = (UNKNOWN_ERROR + 3), 71 | WOULD_BLOCK = (UNKNOWN_ERROR + 4), 72 | TIMED_OUT = (UNKNOWN_ERROR + 5), 73 | UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6), 74 | #endif 75 | FDS_NOT_ALLOWED = (UNKNOWN_ERROR + 7), 76 | }; 77 | 78 | // Restore define; enumeration is in "android" namespace, so the value defined 79 | // there won't work for Win32 code in a different namespace. 80 | #ifdef _WIN32 81 | # define NO_ERROR 0L 82 | #endif 83 | 84 | }; // namespace android 85 | 86 | // --------------------------------------------------------------------------- 87 | 88 | #endif // ANDROID_ERRORS_H 89 | -------------------------------------------------------------------------------- /src/main/cpp/include/utils/Mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_MUTEX_H 18 | #define _LIBS_UTILS_MUTEX_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #if defined(HAVE_PTHREADS) 25 | # include 26 | #endif 27 | 28 | #include "Errors.h" 29 | 30 | // --------------------------------------------------------------------------- 31 | namespace android { 32 | // --------------------------------------------------------------------------- 33 | 34 | class Condition; 35 | 36 | /* 37 | * Simple mutex class. The implementation is system-dependent. 38 | * 39 | * The mutex must be unlocked by the thread that locked it. They are not 40 | * recursive, i.e. the same thread can't lock it multiple times. 41 | */ 42 | class Mutex { 43 | public: 44 | enum { 45 | PRIVATE = 0, 46 | SHARED = 1 47 | }; 48 | 49 | Mutex(); 50 | Mutex(const char* name); 51 | Mutex(int type, const char* name = NULL); 52 | ~Mutex(); 53 | 54 | // lock or unlock the mutex 55 | status_t lock(); 56 | void unlock(); 57 | 58 | // lock if possible; returns 0 on success, error otherwise 59 | status_t tryLock(); 60 | 61 | // Manages the mutex automatically. It'll be locked when Autolock is 62 | // constructed and released when Autolock goes out of scope. 63 | class Autolock { 64 | public: 65 | inline Autolock(Mutex& mutex) : mLock(mutex) { mLock.lock(); } 66 | inline Autolock(Mutex* mutex) : mLock(*mutex) { mLock.lock(); } 67 | inline ~Autolock() { mLock.unlock(); } 68 | private: 69 | Mutex& mLock; 70 | }; 71 | 72 | private: 73 | friend class Condition; 74 | 75 | // A mutex cannot be copied 76 | Mutex(const Mutex&); 77 | Mutex& operator = (const Mutex&); 78 | 79 | #if defined(HAVE_PTHREADS) 80 | pthread_mutex_t mMutex; 81 | #else 82 | void _init(); 83 | void* mState; 84 | #endif 85 | }; 86 | 87 | // --------------------------------------------------------------------------- 88 | 89 | #if defined(HAVE_PTHREADS) 90 | 91 | inline Mutex::Mutex() { 92 | pthread_mutex_init(&mMutex, NULL); 93 | } 94 | inline Mutex::Mutex(__attribute__((unused)) const char* name) { 95 | pthread_mutex_init(&mMutex, NULL); 96 | } 97 | inline Mutex::Mutex(int type, __attribute__((unused)) const char* name) { 98 | if (type == SHARED) { 99 | pthread_mutexattr_t attr; 100 | pthread_mutexattr_init(&attr); 101 | pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); 102 | pthread_mutex_init(&mMutex, &attr); 103 | pthread_mutexattr_destroy(&attr); 104 | } else { 105 | pthread_mutex_init(&mMutex, NULL); 106 | } 107 | } 108 | inline Mutex::~Mutex() { 109 | pthread_mutex_destroy(&mMutex); 110 | } 111 | inline status_t Mutex::lock() { 112 | return -pthread_mutex_lock(&mMutex); 113 | } 114 | inline void Mutex::unlock() { 115 | pthread_mutex_unlock(&mMutex); 116 | } 117 | inline status_t Mutex::tryLock() { 118 | return -pthread_mutex_trylock(&mMutex); 119 | } 120 | 121 | #endif // HAVE_PTHREADS 122 | 123 | // --------------------------------------------------------------------------- 124 | 125 | /* 126 | * Automatic mutex. Declare one of these at the top of a function. 127 | * When the function returns, it will go out of scope, and release the 128 | * mutex. 129 | */ 130 | 131 | typedef Mutex::Autolock AutoMutex; 132 | 133 | // --------------------------------------------------------------------------- 134 | }; // namespace android 135 | // --------------------------------------------------------------------------- 136 | 137 | #endif // _LIBS_UTILS_MUTEX_H 138 | -------------------------------------------------------------------------------- /src/main/cpp/mainJNILib.cpp: -------------------------------------------------------------------------------- 1 | #include "util.hpp" 2 | 3 | extern "C" { 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | } 10 | 11 | #include 12 | #include 13 | #include 14 | #include "include/utils/Mutex.h" 15 | using namespace android; 16 | 17 | #include "include/fpdfview.h" 18 | #include "include/fpdf_doc.h" 19 | #include 20 | #include 21 | #include 22 | 23 | static std::mutex sLibraryLock; 24 | 25 | static int sLibraryReferenceCount = 0; 26 | 27 | static void initLibraryIfNeed(){ 28 | const std::lock_guard lock(sLibraryLock); 29 | if(sLibraryReferenceCount == 0){ 30 | LOGD("Init FPDF library"); 31 | FPDF_InitLibrary(); 32 | } 33 | sLibraryReferenceCount++; 34 | } 35 | 36 | static void destroyLibraryIfNeed(){ 37 | const std::lock_guard lock(sLibraryLock); 38 | sLibraryReferenceCount--; 39 | if(sLibraryReferenceCount == 0){ 40 | LOGD("Destroy FPDF library"); 41 | FPDF_DestroyLibrary(); 42 | } 43 | } 44 | 45 | struct rgb { 46 | uint8_t red; 47 | uint8_t green; 48 | uint8_t blue; 49 | }; 50 | 51 | class DocumentFile { 52 | private: 53 | int fileFd; 54 | 55 | public: 56 | FPDF_DOCUMENT pdfDocument = NULL; 57 | size_t fileSize; 58 | 59 | DocumentFile() { initLibraryIfNeed(); } 60 | ~DocumentFile(); 61 | }; 62 | DocumentFile::~DocumentFile(){ 63 | if(pdfDocument != NULL){ 64 | FPDF_CloseDocument(pdfDocument); 65 | } 66 | 67 | destroyLibraryIfNeed(); 68 | } 69 | 70 | template 71 | inline typename string_type::value_type* WriteInto(string_type* str, size_t length_with_null) { 72 | str->reserve(length_with_null); 73 | str->resize(length_with_null - 1); 74 | return &((*str)[0]); 75 | } 76 | 77 | inline long getFileSize(int fd){ 78 | struct stat file_state; 79 | 80 | if(fstat(fd, &file_state) >= 0){ 81 | return (long)(file_state.st_size); 82 | }else{ 83 | LOGE("Error getting file size"); 84 | return 0; 85 | } 86 | } 87 | 88 | static char* getErrorDescription(const long error) { 89 | char* description = NULL; 90 | switch(error) { 91 | case FPDF_ERR_SUCCESS: 92 | asprintf(&description, "No error."); 93 | break; 94 | case FPDF_ERR_FILE: 95 | asprintf(&description, "File not found or could not be opened."); 96 | break; 97 | case FPDF_ERR_FORMAT: 98 | asprintf(&description, "File not in PDF format or corrupted."); 99 | break; 100 | case FPDF_ERR_PASSWORD: 101 | asprintf(&description, "Incorrect password."); 102 | break; 103 | case FPDF_ERR_SECURITY: 104 | asprintf(&description, "Unsupported security scheme."); 105 | break; 106 | case FPDF_ERR_PAGE: 107 | asprintf(&description, "Page not found or content error."); 108 | break; 109 | default: 110 | asprintf(&description, "Unknown error."); 111 | } 112 | 113 | return description; 114 | } 115 | 116 | int jniThrowException(JNIEnv* env, const char* className, const char* message) { 117 | jclass exClass = env->FindClass(className); 118 | if (exClass == NULL) { 119 | LOGE("Unable to find exception class %s", className); 120 | return -1; 121 | } 122 | 123 | if(env->ThrowNew(exClass, message ) != JNI_OK) { 124 | LOGE("Failed throwing '%s' '%s'", className, message); 125 | return -1; 126 | } 127 | 128 | return 0; 129 | } 130 | 131 | int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt, ...) { 132 | va_list args; 133 | va_start(args, fmt); 134 | char msgBuf[512]; 135 | vsnprintf(msgBuf, sizeof(msgBuf), fmt, args); 136 | return jniThrowException(env, className, msgBuf); 137 | va_end(args); 138 | } 139 | 140 | jobject NewLong(JNIEnv* env, jlong value) { 141 | jclass cls = env->FindClass("java/lang/Long"); 142 | jmethodID methodID = env->GetMethodID(cls, "", "(J)V"); 143 | return env->NewObject(cls, methodID, value); 144 | } 145 | 146 | jobject NewInteger(JNIEnv* env, jint value) { 147 | jclass cls = env->FindClass("java/lang/Integer"); 148 | jmethodID methodID = env->GetMethodID(cls, "", "(I)V"); 149 | return env->NewObject(cls, methodID, value); 150 | } 151 | 152 | uint16_t rgbTo565(rgb *color) { 153 | return ((color->red >> 3) << 11) | ((color->green >> 2) << 5) | (color->blue >> 3); 154 | } 155 | 156 | void rgbBitmapTo565(void *source, int sourceStride, void *dest, AndroidBitmapInfo *info) { 157 | rgb *srcLine; 158 | uint16_t *dstLine; 159 | int y, x; 160 | for (y = 0; y < info->height; y++) { 161 | srcLine = (rgb*) source; 162 | dstLine = (uint16_t*) dest; 163 | for (x = 0; x < info->width; x++) { 164 | dstLine[x] = rgbTo565(&srcLine[x]); 165 | } 166 | source = (char*) source + sourceStride; 167 | dest = (char*) dest + info->stride; 168 | } 169 | } 170 | 171 | extern "C" { //For JNI support 172 | 173 | static int getBlock(void* param, unsigned long position, unsigned char* outBuffer, 174 | unsigned long size) { 175 | const int fd = reinterpret_cast(param); 176 | const int readCount = pread(fd, outBuffer, size, position); 177 | if (readCount < 0) { 178 | LOGE("Cannot read from file descriptor. Error:%d", errno); 179 | return 0; 180 | } 181 | return 1; 182 | } 183 | 184 | JNI_FUNC(jlong, PdfiumCore, nativeOpenDocument)(JNI_ARGS, jint fd, jstring password){ 185 | 186 | size_t fileLength = (size_t)getFileSize(fd); 187 | if(fileLength <= 0) { 188 | jniThrowException(env, "java/io/IOException", 189 | "File is empty"); 190 | return -1; 191 | } 192 | 193 | DocumentFile *docFile = new DocumentFile(); 194 | 195 | FPDF_FILEACCESS loader; 196 | loader.m_FileLen = fileLength; 197 | loader.m_Param = reinterpret_cast(intptr_t(fd)); 198 | loader.m_GetBlock = &getBlock; 199 | 200 | const char *cpassword = NULL; 201 | if(password != NULL) { 202 | cpassword = env->GetStringUTFChars(password, NULL); 203 | } 204 | 205 | FPDF_DOCUMENT document = FPDF_LoadCustomDocument(&loader, cpassword); 206 | 207 | if(cpassword != NULL) { 208 | env->ReleaseStringUTFChars(password, cpassword); 209 | } 210 | 211 | if (!document) { 212 | delete docFile; 213 | 214 | const long errorNum = FPDF_GetLastError(); 215 | if(errorNum == FPDF_ERR_PASSWORD) { 216 | jniThrowException(env, "com/shockwave/pdfium/PdfPasswordException", 217 | "Password required or incorrect password."); 218 | } else { 219 | char* error = getErrorDescription(errorNum); 220 | jniThrowExceptionFmt(env, "java/io/IOException", 221 | "cannot create document: %s", error); 222 | 223 | free(error); 224 | } 225 | 226 | return -1; 227 | } 228 | 229 | docFile->pdfDocument = document; 230 | 231 | return reinterpret_cast(docFile); 232 | } 233 | 234 | JNI_FUNC(jlong, PdfiumCore, nativeOpenMemDocument)(JNI_ARGS, jbyteArray data, jstring password){ 235 | DocumentFile *docFile = new DocumentFile(); 236 | 237 | const char *cpassword = NULL; 238 | if(password != NULL) { 239 | cpassword = env->GetStringUTFChars(password, NULL); 240 | } 241 | 242 | jbyte *cData = env->GetByteArrayElements(data, NULL); 243 | int size = (int) env->GetArrayLength(data); 244 | jbyte *cDataCopy = new jbyte[size]; 245 | memcpy(cDataCopy, cData, size); 246 | FPDF_DOCUMENT document = FPDF_LoadMemDocument( reinterpret_cast(cDataCopy), 247 | size, cpassword); 248 | env->ReleaseByteArrayElements(data, cData, JNI_ABORT); 249 | 250 | if(cpassword != NULL) { 251 | env->ReleaseStringUTFChars(password, cpassword); 252 | } 253 | 254 | if (!document) { 255 | delete docFile; 256 | 257 | const long errorNum = FPDF_GetLastError(); 258 | if(errorNum == FPDF_ERR_PASSWORD) { 259 | jniThrowException(env, "com/shockwave/pdfium/PdfPasswordException", 260 | "Password required or incorrect password."); 261 | } else { 262 | char* error = getErrorDescription(errorNum); 263 | jniThrowExceptionFmt(env, "java/io/IOException", 264 | "cannot create document: %s", error); 265 | 266 | free(error); 267 | } 268 | 269 | return -1; 270 | } 271 | 272 | docFile->pdfDocument = document; 273 | 274 | return reinterpret_cast(docFile); 275 | } 276 | 277 | JNI_FUNC(jint, PdfiumCore, nativeGetPageCount)(JNI_ARGS, jlong documentPtr){ 278 | DocumentFile *doc = reinterpret_cast(documentPtr); 279 | return (jint)FPDF_GetPageCount(doc->pdfDocument); 280 | } 281 | 282 | JNI_FUNC(void, PdfiumCore, nativeCloseDocument)(JNI_ARGS, jlong documentPtr){ 283 | DocumentFile *doc = reinterpret_cast(documentPtr); 284 | delete doc; 285 | } 286 | 287 | static jlong loadPageInternal(JNIEnv *env, DocumentFile *doc, int pageIndex){ 288 | try{ 289 | if(doc == NULL) throw "Get page document null"; 290 | 291 | FPDF_DOCUMENT pdfDoc = doc->pdfDocument; 292 | if(pdfDoc != NULL){ 293 | FPDF_PAGE page = FPDF_LoadPage(pdfDoc, pageIndex); 294 | if (page == NULL) { 295 | throw "Loaded page is null"; 296 | } 297 | return reinterpret_cast(page); 298 | }else{ 299 | throw "Get page pdf document null"; 300 | } 301 | 302 | }catch(const char *msg){ 303 | LOGE("%s", msg); 304 | 305 | jniThrowException(env, "java/lang/IllegalStateException", 306 | "cannot load page"); 307 | 308 | return -1; 309 | } 310 | } 311 | 312 | static void closePageInternal(jlong pagePtr) { FPDF_ClosePage(reinterpret_cast(pagePtr)); } 313 | 314 | JNI_FUNC(jlong, PdfiumCore, nativeLoadPage)(JNI_ARGS, jlong docPtr, jint pageIndex){ 315 | DocumentFile *doc = reinterpret_cast(docPtr); 316 | return loadPageInternal(env, doc, (int)pageIndex); 317 | } 318 | JNI_FUNC(jlongArray, PdfiumCore, nativeLoadPages)(JNI_ARGS, jlong docPtr, jint fromIndex, jint toIndex){ 319 | DocumentFile *doc = reinterpret_cast(docPtr); 320 | 321 | if(toIndex < fromIndex) return NULL; 322 | jlong pages[ toIndex - fromIndex + 1 ]; 323 | 324 | int i; 325 | for(i = 0; i <= (toIndex - fromIndex); i++){ 326 | pages[i] = loadPageInternal(env, doc, (int)(i + fromIndex)); 327 | } 328 | 329 | jlongArray javaPages = env -> NewLongArray( (jsize)(toIndex - fromIndex + 1) ); 330 | env -> SetLongArrayRegion(javaPages, 0, (jsize)(toIndex - fromIndex + 1), (const jlong*)pages); 331 | 332 | return javaPages; 333 | } 334 | 335 | JNI_FUNC(void, PdfiumCore, nativeClosePage)(JNI_ARGS, jlong pagePtr){ closePageInternal(pagePtr); } 336 | JNI_FUNC(void, PdfiumCore, nativeClosePages)(JNI_ARGS, jlongArray pagesPtr){ 337 | int length = (int)(env -> GetArrayLength(pagesPtr)); 338 | jlong *pages = env -> GetLongArrayElements(pagesPtr, NULL); 339 | 340 | int i; 341 | for(i = 0; i < length; i++){ closePageInternal(pages[i]); } 342 | } 343 | 344 | JNI_FUNC(jint, PdfiumCore, nativeGetPageWidthPixel)(JNI_ARGS, jlong pagePtr, jint dpi){ 345 | FPDF_PAGE page = reinterpret_cast(pagePtr); 346 | return (jint)(FPDF_GetPageWidth(page) * dpi / 72); 347 | } 348 | JNI_FUNC(jint, PdfiumCore, nativeGetPageHeightPixel)(JNI_ARGS, jlong pagePtr, jint dpi){ 349 | FPDF_PAGE page = reinterpret_cast(pagePtr); 350 | return (jint)(FPDF_GetPageHeight(page) * dpi / 72); 351 | } 352 | 353 | JNI_FUNC(jint, PdfiumCore, nativeGetPageWidthPoint)(JNI_ARGS, jlong pagePtr){ 354 | FPDF_PAGE page = reinterpret_cast(pagePtr); 355 | return (jint)FPDF_GetPageWidth(page); 356 | } 357 | JNI_FUNC(jint, PdfiumCore, nativeGetPageHeightPoint)(JNI_ARGS, jlong pagePtr){ 358 | FPDF_PAGE page = reinterpret_cast(pagePtr); 359 | return (jint)FPDF_GetPageHeight(page); 360 | } 361 | JNI_FUNC(jobject, PdfiumCore, nativeGetPageSizeByIndex)(JNI_ARGS, jlong docPtr, jint pageIndex, jint dpi){ 362 | DocumentFile *doc = reinterpret_cast(docPtr); 363 | if(doc == NULL) { 364 | LOGE("Document is null"); 365 | 366 | jniThrowException(env, "java/lang/IllegalStateException", 367 | "Document is null"); 368 | return NULL; 369 | } 370 | 371 | double width, height; 372 | int result = FPDF_GetPageSizeByIndex(doc->pdfDocument, pageIndex, &width, &height); 373 | 374 | if (result == 0) { 375 | width = 0; 376 | height = 0; 377 | } 378 | 379 | jint widthInt = (jint) (width * dpi / 72); 380 | jint heightInt = (jint) (height * dpi / 72); 381 | 382 | jclass clazz = env->FindClass("com/shockwave/pdfium/util/Size"); 383 | jmethodID constructorID = env->GetMethodID(clazz, "", "(II)V"); 384 | return env->NewObject(clazz, constructorID, widthInt, heightInt); 385 | } 386 | 387 | static void renderPageInternal( FPDF_PAGE page, 388 | ANativeWindow_Buffer *windowBuffer, 389 | int startX, int startY, 390 | int canvasHorSize, int canvasVerSize, 391 | int drawSizeHor, int drawSizeVer, 392 | bool renderAnnot){ 393 | 394 | FPDF_BITMAP pdfBitmap = FPDFBitmap_CreateEx( canvasHorSize, canvasVerSize, 395 | FPDFBitmap_BGRA, 396 | windowBuffer->bits, (int)(windowBuffer->stride) * 4); 397 | 398 | /*LOGD("Start X: %d", startX); 399 | LOGD("Start Y: %d", startY); 400 | LOGD("Canvas Hor: %d", canvasHorSize); 401 | LOGD("Canvas Ver: %d", canvasVerSize); 402 | LOGD("Draw Hor: %d", drawSizeHor); 403 | LOGD("Draw Ver: %d", drawSizeVer);*/ 404 | 405 | if(drawSizeHor < canvasHorSize || drawSizeVer < canvasVerSize){ 406 | FPDFBitmap_FillRect( pdfBitmap, 0, 0, canvasHorSize, canvasVerSize, 407 | 0x848484FF); //Gray 408 | } 409 | 410 | int baseHorSize = (canvasHorSize < drawSizeHor)? canvasHorSize : drawSizeHor; 411 | int baseVerSize = (canvasVerSize < drawSizeVer)? canvasVerSize : drawSizeVer; 412 | int baseX = (startX < 0)? 0 : startX; 413 | int baseY = (startY < 0)? 0 : startY; 414 | int flags = FPDF_REVERSE_BYTE_ORDER; 415 | 416 | if(renderAnnot) { 417 | flags |= FPDF_ANNOT; 418 | } 419 | 420 | FPDFBitmap_FillRect( pdfBitmap, baseX, baseY, baseHorSize, baseVerSize, 421 | 0xFFFFFFFF); //White 422 | 423 | FPDF_RenderPageBitmap( pdfBitmap, page, 424 | startX, startY, 425 | drawSizeHor, drawSizeVer, 426 | 0, flags ); 427 | } 428 | 429 | JNI_FUNC(void, PdfiumCore, nativeRenderPage)(JNI_ARGS, jlong pagePtr, jobject objSurface, 430 | jint dpi, jint startX, jint startY, 431 | jint drawSizeHor, jint drawSizeVer, 432 | jboolean renderAnnot){ 433 | ANativeWindow *nativeWindow = ANativeWindow_fromSurface(env, objSurface); 434 | if(nativeWindow == NULL){ 435 | LOGE("native window pointer null"); 436 | return; 437 | } 438 | FPDF_PAGE page = reinterpret_cast(pagePtr); 439 | 440 | if(page == NULL || nativeWindow == NULL){ 441 | LOGE("Render page pointers invalid"); 442 | return; 443 | } 444 | 445 | if(ANativeWindow_getFormat(nativeWindow) != WINDOW_FORMAT_RGBA_8888){ 446 | LOGD("Set format to RGBA_8888"); 447 | ANativeWindow_setBuffersGeometry( nativeWindow, 448 | ANativeWindow_getWidth(nativeWindow), 449 | ANativeWindow_getHeight(nativeWindow), 450 | WINDOW_FORMAT_RGBA_8888 ); 451 | } 452 | 453 | ANativeWindow_Buffer buffer; 454 | int ret; 455 | if( (ret = ANativeWindow_lock(nativeWindow, &buffer, NULL)) != 0 ){ 456 | LOGE("Locking native window failed: %s", strerror(ret * -1)); 457 | return; 458 | } 459 | 460 | renderPageInternal(page, &buffer, 461 | (int)startX, (int)startY, 462 | buffer.width, buffer.height, 463 | (int)drawSizeHor, (int)drawSizeVer, 464 | (bool)renderAnnot); 465 | 466 | ANativeWindow_unlockAndPost(nativeWindow); 467 | ANativeWindow_release(nativeWindow); 468 | } 469 | 470 | JNI_FUNC(void, PdfiumCore, nativeRenderPageBitmap)(JNI_ARGS, jlong pagePtr, jobject bitmap, 471 | jint dpi, jint startX, jint startY, 472 | jint drawSizeHor, jint drawSizeVer, 473 | jboolean renderAnnot){ 474 | 475 | FPDF_PAGE page = reinterpret_cast(pagePtr); 476 | 477 | if(page == NULL || bitmap == NULL){ 478 | LOGE("Render page pointers invalid"); 479 | return; 480 | } 481 | 482 | AndroidBitmapInfo info; 483 | int ret; 484 | if((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) { 485 | LOGE("Fetching bitmap info failed: %s", strerror(ret * -1)); 486 | return; 487 | } 488 | 489 | int canvasHorSize = info.width; 490 | int canvasVerSize = info.height; 491 | 492 | if(info.format != ANDROID_BITMAP_FORMAT_RGBA_8888 && info.format != ANDROID_BITMAP_FORMAT_RGB_565){ 493 | LOGE("Bitmap format must be RGBA_8888 or RGB_565"); 494 | return; 495 | } 496 | 497 | void *addr; 498 | if( (ret = AndroidBitmap_lockPixels(env, bitmap, &addr)) != 0 ){ 499 | LOGE("Locking bitmap failed: %s", strerror(ret * -1)); 500 | return; 501 | } 502 | 503 | void *tmp; 504 | int format; 505 | int sourceStride; 506 | if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) { 507 | tmp = malloc(canvasVerSize * canvasHorSize * sizeof(rgb)); 508 | sourceStride = canvasHorSize * sizeof(rgb); 509 | format = FPDFBitmap_BGR; 510 | } else { 511 | tmp = addr; 512 | sourceStride = info.stride; 513 | format = FPDFBitmap_BGRA; 514 | } 515 | 516 | FPDF_BITMAP pdfBitmap = FPDFBitmap_CreateEx( canvasHorSize, canvasVerSize, 517 | format, tmp, sourceStride); 518 | 519 | /*LOGD("Start X: %d", startX); 520 | LOGD("Start Y: %d", startY); 521 | LOGD("Canvas Hor: %d", canvasHorSize); 522 | LOGD("Canvas Ver: %d", canvasVerSize); 523 | LOGD("Draw Hor: %d", drawSizeHor); 524 | LOGD("Draw Ver: %d", drawSizeVer);*/ 525 | 526 | if(drawSizeHor < canvasHorSize || drawSizeVer < canvasVerSize){ 527 | FPDFBitmap_FillRect( pdfBitmap, 0, 0, canvasHorSize, canvasVerSize, 528 | 0x848484FF); //Gray 529 | } 530 | 531 | int baseHorSize = (canvasHorSize < drawSizeHor)? canvasHorSize : (int)drawSizeHor; 532 | int baseVerSize = (canvasVerSize < drawSizeVer)? canvasVerSize : (int)drawSizeVer; 533 | int baseX = (startX < 0)? 0 : (int)startX; 534 | int baseY = (startY < 0)? 0 : (int)startY; 535 | int flags = FPDF_REVERSE_BYTE_ORDER; 536 | 537 | if(renderAnnot) { 538 | flags |= FPDF_ANNOT; 539 | } 540 | 541 | FPDFBitmap_FillRect( pdfBitmap, baseX, baseY, baseHorSize, baseVerSize, 542 | 0xFFFFFFFF); //White 543 | 544 | FPDF_RenderPageBitmap( pdfBitmap, page, 545 | startX, startY, 546 | (int)drawSizeHor, (int)drawSizeVer, 547 | 0, flags ); 548 | 549 | if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) { 550 | rgbBitmapTo565(tmp, sourceStride, addr, &info); 551 | free(tmp); 552 | } 553 | 554 | AndroidBitmap_unlockPixels(env, bitmap); 555 | } 556 | 557 | JNI_FUNC(jstring, PdfiumCore, nativeGetDocumentMetaText)(JNI_ARGS, jlong docPtr, jstring tag) { 558 | const char *ctag = env->GetStringUTFChars(tag, NULL); 559 | if (ctag == NULL) { 560 | return env->NewStringUTF(""); 561 | } 562 | DocumentFile *doc = reinterpret_cast(docPtr); 563 | 564 | size_t bufferLen = FPDF_GetMetaText(doc->pdfDocument, ctag, NULL, 0); 565 | if (bufferLen <= 2) { 566 | return env->NewStringUTF(""); 567 | } 568 | std::wstring text; 569 | FPDF_GetMetaText(doc->pdfDocument, ctag, WriteInto(&text, bufferLen + 1), bufferLen); 570 | env->ReleaseStringUTFChars(tag, ctag); 571 | return env->NewString((jchar*) text.c_str(), bufferLen / 2 - 1); 572 | } 573 | 574 | JNI_FUNC(jobject, PdfiumCore, nativeGetFirstChildBookmark)(JNI_ARGS, jlong docPtr, jobject bookmarkPtr) { 575 | DocumentFile *doc = reinterpret_cast(docPtr); 576 | FPDF_BOOKMARK parent; 577 | if(bookmarkPtr == NULL) { 578 | parent = NULL; 579 | } else { 580 | jclass longClass = env->GetObjectClass(bookmarkPtr); 581 | jmethodID longValueMethod = env->GetMethodID(longClass, "longValue", "()J"); 582 | 583 | jlong ptr = env->CallLongMethod(bookmarkPtr, longValueMethod); 584 | parent = reinterpret_cast(ptr); 585 | } 586 | FPDF_BOOKMARK bookmark = FPDFBookmark_GetFirstChild(doc->pdfDocument, parent); 587 | if (bookmark == NULL) { 588 | return NULL; 589 | } 590 | return NewLong(env, reinterpret_cast(bookmark)); 591 | } 592 | 593 | JNI_FUNC(jobject, PdfiumCore, nativeGetSiblingBookmark)(JNI_ARGS, jlong docPtr, jlong bookmarkPtr) { 594 | DocumentFile *doc = reinterpret_cast(docPtr); 595 | FPDF_BOOKMARK parent = reinterpret_cast(bookmarkPtr); 596 | FPDF_BOOKMARK bookmark = FPDFBookmark_GetNextSibling(doc->pdfDocument, parent); 597 | if (bookmark == NULL) { 598 | return NULL; 599 | } 600 | return NewLong(env, reinterpret_cast(bookmark)); 601 | } 602 | 603 | JNI_FUNC(jstring, PdfiumCore, nativeGetBookmarkTitle)(JNI_ARGS, jlong bookmarkPtr) { 604 | FPDF_BOOKMARK bookmark = reinterpret_cast(bookmarkPtr); 605 | size_t bufferLen = FPDFBookmark_GetTitle(bookmark, NULL, 0); 606 | if (bufferLen <= 2) { 607 | return env->NewStringUTF(""); 608 | } 609 | std::wstring title; 610 | FPDFBookmark_GetTitle(bookmark, WriteInto(&title, bufferLen + 1), bufferLen); 611 | return env->NewString((jchar*) title.c_str(), bufferLen / 2 - 1); 612 | } 613 | 614 | JNI_FUNC(jlong, PdfiumCore, nativeGetBookmarkDestIndex)(JNI_ARGS, jlong docPtr, jlong bookmarkPtr) { 615 | DocumentFile *doc = reinterpret_cast(docPtr); 616 | FPDF_BOOKMARK bookmark = reinterpret_cast(bookmarkPtr); 617 | 618 | FPDF_DEST dest = FPDFBookmark_GetDest(doc->pdfDocument, bookmark); 619 | if (dest == NULL) { 620 | return -1; 621 | } 622 | return FPDFDest_GetDestPageIndex(doc->pdfDocument, dest); 623 | } 624 | 625 | JNI_FUNC(jlongArray, PdfiumCore, nativeGetPageLinks)(JNI_ARGS, jlong pagePtr) { 626 | FPDF_PAGE page = reinterpret_cast(pagePtr); 627 | int pos = 0; 628 | std::vector links; 629 | FPDF_LINK link; 630 | while (FPDFLink_Enumerate(page, &pos, &link)) { 631 | links.push_back(reinterpret_cast(link)); 632 | } 633 | 634 | jlongArray result = env->NewLongArray(links.size()); 635 | env->SetLongArrayRegion(result, 0, links.size(), &links[0]); 636 | return result; 637 | } 638 | 639 | JNI_FUNC(jobject, PdfiumCore, nativeGetDestPageIndex)(JNI_ARGS, jlong docPtr, jlong linkPtr) { 640 | DocumentFile *doc = reinterpret_cast(docPtr); 641 | FPDF_LINK link = reinterpret_cast(linkPtr); 642 | FPDF_DEST dest = FPDFLink_GetDest(doc->pdfDocument, link); 643 | if (dest == NULL) { 644 | return NULL; 645 | } 646 | unsigned long index = FPDFDest_GetDestPageIndex(doc->pdfDocument, dest); 647 | return NewInteger(env, (jint) index); 648 | } 649 | 650 | JNI_FUNC(jstring, PdfiumCore, nativeGetLinkURI)(JNI_ARGS, jlong docPtr, jlong linkPtr){ 651 | DocumentFile *doc = reinterpret_cast(docPtr); 652 | FPDF_LINK link = reinterpret_cast(linkPtr); 653 | FPDF_ACTION action = FPDFLink_GetAction(link); 654 | if (action == NULL) { 655 | return NULL; 656 | } 657 | size_t bufferLen = FPDFAction_GetURIPath(doc->pdfDocument, action, NULL, 0); 658 | if (bufferLen <= 0) { 659 | return env->NewStringUTF(""); 660 | } 661 | std::string uri; 662 | FPDFAction_GetURIPath(doc->pdfDocument, action, WriteInto(&uri, bufferLen), bufferLen); 663 | return env->NewStringUTF(uri.c_str()); 664 | } 665 | 666 | JNI_FUNC(jobject, PdfiumCore, nativeGetLinkRect)(JNI_ARGS, jlong linkPtr) { 667 | FPDF_LINK link = reinterpret_cast(linkPtr); 668 | FS_RECTF fsRectF; 669 | FPDF_BOOL result = FPDFLink_GetAnnotRect(link, &fsRectF); 670 | 671 | if (!result) { 672 | return NULL; 673 | } 674 | 675 | jclass clazz = env->FindClass("android/graphics/RectF"); 676 | jmethodID constructorID = env->GetMethodID(clazz, "", "(FFFF)V"); 677 | return env->NewObject(clazz, constructorID, fsRectF.left, fsRectF.top, fsRectF.right, fsRectF.bottom); 678 | } 679 | 680 | JNI_FUNC(jobject, PdfiumCore, nativePageCoordsToDevice)(JNI_ARGS, jlong pagePtr, jint startX, jint startY, jint sizeX, 681 | jint sizeY, jint rotate, jdouble pageX, jdouble pageY) { 682 | FPDF_PAGE page = reinterpret_cast(pagePtr); 683 | int deviceX, deviceY; 684 | 685 | FPDF_PageToDevice(page, startX, startY, sizeX, sizeY, rotate, pageX, pageY, &deviceX, &deviceY); 686 | 687 | jclass clazz = env->FindClass("android/graphics/Point"); 688 | jmethodID constructorID = env->GetMethodID(clazz, "", "(II)V"); 689 | return env->NewObject(clazz, constructorID, deviceX, deviceY); 690 | } 691 | 692 | }//extern C 693 | -------------------------------------------------------------------------------- /src/main/cpp/util.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_HPP_ 2 | #define _UTIL_HPP_ 3 | 4 | #include 5 | extern "C" { 6 | #include 7 | } 8 | 9 | #include 10 | 11 | #define JNI_FUNC(retType, bindClass, name) JNIEXPORT retType JNICALL Java_com_shockwave_pdfium_##bindClass##_##name 12 | #define JNI_ARGS JNIEnv *env, jobject thiz 13 | 14 | #define LOG_TAG "jniPdfium" 15 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 16 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 17 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 18 | 19 | #endif -------------------------------------------------------------------------------- /src/main/java/com/shockwave/pdfium/PdfDocument.java: -------------------------------------------------------------------------------- 1 | package com.shockwave.pdfium; 2 | 3 | import android.graphics.RectF; 4 | import android.os.ParcelFileDescriptor; 5 | import androidx.collection.ArrayMap; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class PdfDocument { 12 | 13 | public static class Meta { 14 | String title; 15 | String author; 16 | String subject; 17 | String keywords; 18 | String creator; 19 | String producer; 20 | String creationDate; 21 | String modDate; 22 | 23 | public String getTitle() { 24 | return title; 25 | } 26 | 27 | public String getAuthor() { 28 | return author; 29 | } 30 | 31 | public String getSubject() { 32 | return subject; 33 | } 34 | 35 | public String getKeywords() { 36 | return keywords; 37 | } 38 | 39 | public String getCreator() { 40 | return creator; 41 | } 42 | 43 | public String getProducer() { 44 | return producer; 45 | } 46 | 47 | public String getCreationDate() { 48 | return creationDate; 49 | } 50 | 51 | public String getModDate() { 52 | return modDate; 53 | } 54 | } 55 | 56 | public static class Bookmark { 57 | private List children = new ArrayList<>(); 58 | String title; 59 | long pageIdx; 60 | long mNativePtr; 61 | 62 | public List getChildren() { 63 | return children; 64 | } 65 | 66 | public boolean hasChildren() { 67 | return !children.isEmpty(); 68 | } 69 | 70 | public String getTitle() { 71 | return title; 72 | } 73 | 74 | public long getPageIdx() { 75 | return pageIdx; 76 | } 77 | } 78 | 79 | public static class Link { 80 | private RectF bounds; 81 | private Integer destPageIdx; 82 | private String uri; 83 | 84 | public Link(RectF bounds, Integer destPageIdx, String uri) { 85 | this.bounds = bounds; 86 | this.destPageIdx = destPageIdx; 87 | this.uri = uri; 88 | } 89 | 90 | public Integer getDestPageIdx() { 91 | return destPageIdx; 92 | } 93 | 94 | public String getUri() { 95 | return uri; 96 | } 97 | 98 | public RectF getBounds() { 99 | return bounds; 100 | } 101 | } 102 | 103 | /*package*/ PdfDocument() { 104 | } 105 | 106 | /*package*/ long mNativeDocPtr; 107 | /*package*/ ParcelFileDescriptor parcelFileDescriptor; 108 | 109 | /*package*/ final Map mNativePagesPtr = new ArrayMap<>(); 110 | 111 | public boolean hasPage(int index) { 112 | return mNativePagesPtr.containsKey(index); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/shockwave/pdfium/PdfPasswordException.java: -------------------------------------------------------------------------------- 1 | package com.shockwave.pdfium; 2 | 3 | import java.io.IOException; 4 | 5 | public class PdfPasswordException extends IOException { 6 | public PdfPasswordException() { 7 | super(); 8 | } 9 | 10 | public PdfPasswordException(String detailMessage) { 11 | super(detailMessage); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/shockwave/pdfium/PdfiumCore.java: -------------------------------------------------------------------------------- 1 | package com.shockwave.pdfium; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Point; 6 | import android.graphics.RectF; 7 | import android.os.ParcelFileDescriptor; 8 | import android.util.Log; 9 | import android.view.Surface; 10 | 11 | import com.shockwave.pdfium.util.Size; 12 | 13 | import java.io.FileDescriptor; 14 | import java.io.IOException; 15 | import java.lang.reflect.Field; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class PdfiumCore { 20 | private static final String TAG = PdfiumCore.class.getName(); 21 | private static final Class FD_CLASS = FileDescriptor.class; 22 | private static final String FD_FIELD_NAME = "descriptor"; 23 | 24 | static { 25 | try { 26 | System.loadLibrary("pdfiumandroid"); 27 | } catch (UnsatisfiedLinkError e) { 28 | Log.e(TAG, "Native libraries failed to load - " + e); 29 | } 30 | } 31 | 32 | private native long nativeOpenDocument(int fd, String password); 33 | 34 | private native long nativeOpenMemDocument(byte[] data, String password); 35 | 36 | private native void nativeCloseDocument(long docPtr); 37 | 38 | private native int nativeGetPageCount(long docPtr); 39 | 40 | private native long nativeLoadPage(long docPtr, int pageIndex); 41 | 42 | private native long[] nativeLoadPages(long docPtr, int fromIndex, int toIndex); 43 | 44 | private native void nativeClosePage(long pagePtr); 45 | 46 | private native void nativeClosePages(long[] pagesPtr); 47 | 48 | private native int nativeGetPageWidthPixel(long pagePtr, int dpi); 49 | 50 | private native int nativeGetPageHeightPixel(long pagePtr, int dpi); 51 | 52 | private native int nativeGetPageWidthPoint(long pagePtr); 53 | 54 | private native int nativeGetPageHeightPoint(long pagePtr); 55 | 56 | //private native long nativeGetNativeWindow(Surface surface); 57 | //private native void nativeRenderPage(long pagePtr, long nativeWindowPtr); 58 | private native void nativeRenderPage(long pagePtr, Surface surface, int dpi, 59 | int startX, int startY, 60 | int drawSizeHor, int drawSizeVer, 61 | boolean renderAnnot); 62 | 63 | private native void nativeRenderPageBitmap(long pagePtr, Bitmap bitmap, int dpi, 64 | int startX, int startY, 65 | int drawSizeHor, int drawSizeVer, 66 | boolean renderAnnot); 67 | 68 | private native String nativeGetDocumentMetaText(long docPtr, String tag); 69 | 70 | private native Long nativeGetFirstChildBookmark(long docPtr, Long bookmarkPtr); 71 | 72 | private native Long nativeGetSiblingBookmark(long docPtr, long bookmarkPtr); 73 | 74 | private native String nativeGetBookmarkTitle(long bookmarkPtr); 75 | 76 | private native long nativeGetBookmarkDestIndex(long docPtr, long bookmarkPtr); 77 | 78 | private native Size nativeGetPageSizeByIndex(long docPtr, int pageIndex, int dpi); 79 | 80 | private native long[] nativeGetPageLinks(long pagePtr); 81 | 82 | private native Integer nativeGetDestPageIndex(long docPtr, long linkPtr); 83 | 84 | private native String nativeGetLinkURI(long docPtr, long linkPtr); 85 | 86 | private native RectF nativeGetLinkRect(long linkPtr); 87 | 88 | private native Point nativePageCoordsToDevice(long pagePtr, int startX, int startY, int sizeX, 89 | int sizeY, int rotate, double pageX, double pageY); 90 | 91 | 92 | /* synchronize native methods */ 93 | private static final Object lock = new Object(); 94 | private static Field mFdField = null; 95 | private int mCurrentDpi; 96 | 97 | public static int getNumFd(ParcelFileDescriptor fdObj) { 98 | try { 99 | if (mFdField == null) { 100 | mFdField = FD_CLASS.getDeclaredField(FD_FIELD_NAME); 101 | mFdField.setAccessible(true); 102 | } 103 | 104 | return mFdField.getInt(fdObj.getFileDescriptor()); 105 | } catch (NoSuchFieldException e) { 106 | e.printStackTrace(); 107 | return -1; 108 | } catch (IllegalAccessException e) { 109 | e.printStackTrace(); 110 | return -1; 111 | } 112 | } 113 | 114 | 115 | /** Context needed to get screen density */ 116 | public PdfiumCore(Context ctx) { 117 | mCurrentDpi = ctx.getResources().getDisplayMetrics().densityDpi; 118 | Log.d(TAG, "Starting PdfiumAndroid " + BuildConfig.VERSION_NAME); 119 | } 120 | 121 | /** Create new document from file */ 122 | public PdfDocument newDocument(ParcelFileDescriptor fd) throws IOException { 123 | return newDocument(fd, null); 124 | } 125 | 126 | /** Create new document from file with password */ 127 | public PdfDocument newDocument(ParcelFileDescriptor fd, String password) throws IOException { 128 | PdfDocument document = new PdfDocument(); 129 | document.parcelFileDescriptor = fd; 130 | synchronized (lock) { 131 | document.mNativeDocPtr = nativeOpenDocument(getNumFd(fd), password); 132 | } 133 | 134 | return document; 135 | } 136 | 137 | /** Create new document from bytearray */ 138 | public PdfDocument newDocument(byte[] data) throws IOException { 139 | return newDocument(data, null); 140 | } 141 | 142 | /** Create new document from bytearray with password */ 143 | public PdfDocument newDocument(byte[] data, String password) throws IOException { 144 | PdfDocument document = new PdfDocument(); 145 | synchronized (lock) { 146 | document.mNativeDocPtr = nativeOpenMemDocument(data, password); 147 | } 148 | return document; 149 | } 150 | 151 | /** Get total numer of pages in document */ 152 | public int getPageCount(PdfDocument doc) { 153 | synchronized (lock) { 154 | return nativeGetPageCount(doc.mNativeDocPtr); 155 | } 156 | } 157 | 158 | /** Open page and store native pointer in {@link PdfDocument} */ 159 | public long openPage(PdfDocument doc, int pageIndex) { 160 | long pagePtr; 161 | synchronized (lock) { 162 | pagePtr = nativeLoadPage(doc.mNativeDocPtr, pageIndex); 163 | doc.mNativePagesPtr.put(pageIndex, pagePtr); 164 | return pagePtr; 165 | } 166 | 167 | } 168 | 169 | /** Open range of pages and store native pointers in {@link PdfDocument} */ 170 | public long[] openPage(PdfDocument doc, int fromIndex, int toIndex) { 171 | long[] pagesPtr; 172 | synchronized (lock) { 173 | pagesPtr = nativeLoadPages(doc.mNativeDocPtr, fromIndex, toIndex); 174 | int pageIndex = fromIndex; 175 | for (long page : pagesPtr) { 176 | if (pageIndex > toIndex) break; 177 | doc.mNativePagesPtr.put(pageIndex, page); 178 | pageIndex++; 179 | } 180 | 181 | return pagesPtr; 182 | } 183 | } 184 | 185 | /** 186 | * Get page width in pixels.
187 | * This method requires page to be opened. 188 | */ 189 | public int getPageWidth(PdfDocument doc, int index) { 190 | synchronized (lock) { 191 | Long pagePtr; 192 | if ((pagePtr = doc.mNativePagesPtr.get(index)) != null) { 193 | return nativeGetPageWidthPixel(pagePtr, mCurrentDpi); 194 | } 195 | return 0; 196 | } 197 | } 198 | 199 | /** 200 | * Get page height in pixels.
201 | * This method requires page to be opened. 202 | */ 203 | public int getPageHeight(PdfDocument doc, int index) { 204 | synchronized (lock) { 205 | Long pagePtr; 206 | if ((pagePtr = doc.mNativePagesPtr.get(index)) != null) { 207 | return nativeGetPageHeightPixel(pagePtr, mCurrentDpi); 208 | } 209 | return 0; 210 | } 211 | } 212 | 213 | /** 214 | * Get page width in PostScript points (1/72th of an inch).
215 | * This method requires page to be opened. 216 | */ 217 | public int getPageWidthPoint(PdfDocument doc, int index) { 218 | synchronized (lock) { 219 | Long pagePtr; 220 | if ((pagePtr = doc.mNativePagesPtr.get(index)) != null) { 221 | return nativeGetPageWidthPoint(pagePtr); 222 | } 223 | return 0; 224 | } 225 | } 226 | 227 | /** 228 | * Get page height in PostScript points (1/72th of an inch).
229 | * This method requires page to be opened. 230 | */ 231 | public int getPageHeightPoint(PdfDocument doc, int index) { 232 | synchronized (lock) { 233 | Long pagePtr; 234 | if ((pagePtr = doc.mNativePagesPtr.get(index)) != null) { 235 | return nativeGetPageHeightPoint(pagePtr); 236 | } 237 | return 0; 238 | } 239 | } 240 | 241 | /** 242 | * Get size of page in pixels.
243 | * This method does not require given page to be opened. 244 | */ 245 | public Size getPageSize(PdfDocument doc, int index) { 246 | synchronized (lock) { 247 | return nativeGetPageSizeByIndex(doc.mNativeDocPtr, index, mCurrentDpi); 248 | } 249 | } 250 | 251 | /** 252 | * Render page fragment on {@link Surface}.
253 | * Page must be opened before rendering. 254 | */ 255 | public void renderPage(PdfDocument doc, Surface surface, int pageIndex, 256 | int startX, int startY, int drawSizeX, int drawSizeY) { 257 | renderPage(doc, surface, pageIndex, startX, startY, drawSizeX, drawSizeY, false); 258 | } 259 | 260 | /** 261 | * Render page fragment on {@link Surface}. This method allows to render annotations.
262 | * Page must be opened before rendering. 263 | */ 264 | public void renderPage(PdfDocument doc, Surface surface, int pageIndex, 265 | int startX, int startY, int drawSizeX, int drawSizeY, 266 | boolean renderAnnot) { 267 | synchronized (lock) { 268 | try { 269 | //nativeRenderPage(doc.mNativePagesPtr.get(pageIndex), surface, mCurrentDpi); 270 | nativeRenderPage(doc.mNativePagesPtr.get(pageIndex), surface, mCurrentDpi, 271 | startX, startY, drawSizeX, drawSizeY, renderAnnot); 272 | } catch (NullPointerException e) { 273 | Log.e(TAG, "mContext may be null"); 274 | e.printStackTrace(); 275 | } catch (Exception e) { 276 | Log.e(TAG, "Exception throw from native"); 277 | e.printStackTrace(); 278 | } 279 | } 280 | } 281 | 282 | /** 283 | * Render page fragment on {@link Bitmap}.
284 | * Page must be opened before rendering. 285 | *

286 | * Supported bitmap configurations: 287 | *

    288 | *
  • ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError 289 | *
  • RGB_565 - little worse quality, twice less memory usage 290 | *
291 | */ 292 | public void renderPageBitmap(PdfDocument doc, Bitmap bitmap, int pageIndex, 293 | int startX, int startY, int drawSizeX, int drawSizeY) { 294 | renderPageBitmap(doc, bitmap, pageIndex, startX, startY, drawSizeX, drawSizeY, false); 295 | } 296 | 297 | /** 298 | * Render page fragment on {@link Bitmap}. This method allows to render annotations.
299 | * Page must be opened before rendering. 300 | *

301 | * For more info see {@link PdfiumCore#renderPageBitmap(PdfDocument, Bitmap, int, int, int, int, int)} 302 | */ 303 | public void renderPageBitmap(PdfDocument doc, Bitmap bitmap, int pageIndex, 304 | int startX, int startY, int drawSizeX, int drawSizeY, 305 | boolean renderAnnot) { 306 | synchronized (lock) { 307 | try { 308 | nativeRenderPageBitmap(doc.mNativePagesPtr.get(pageIndex), bitmap, mCurrentDpi, 309 | startX, startY, drawSizeX, drawSizeY, renderAnnot); 310 | } catch (NullPointerException e) { 311 | Log.e(TAG, "mContext may be null"); 312 | e.printStackTrace(); 313 | } catch (Exception e) { 314 | Log.e(TAG, "Exception throw from native"); 315 | e.printStackTrace(); 316 | } 317 | } 318 | } 319 | 320 | /** Release native resources and opened file */ 321 | public void closeDocument(PdfDocument doc) { 322 | synchronized (lock) { 323 | for (Integer index : doc.mNativePagesPtr.keySet()) { 324 | nativeClosePage(doc.mNativePagesPtr.get(index)); 325 | } 326 | doc.mNativePagesPtr.clear(); 327 | 328 | nativeCloseDocument(doc.mNativeDocPtr); 329 | 330 | if (doc.parcelFileDescriptor != null) { //if document was loaded from file 331 | try { 332 | doc.parcelFileDescriptor.close(); 333 | } catch (IOException e) { 334 | /* ignore */ 335 | } 336 | doc.parcelFileDescriptor = null; 337 | } 338 | } 339 | } 340 | 341 | /** Get metadata for given document */ 342 | public PdfDocument.Meta getDocumentMeta(PdfDocument doc) { 343 | synchronized (lock) { 344 | PdfDocument.Meta meta = new PdfDocument.Meta(); 345 | meta.title = nativeGetDocumentMetaText(doc.mNativeDocPtr, "Title"); 346 | meta.author = nativeGetDocumentMetaText(doc.mNativeDocPtr, "Author"); 347 | meta.subject = nativeGetDocumentMetaText(doc.mNativeDocPtr, "Subject"); 348 | meta.keywords = nativeGetDocumentMetaText(doc.mNativeDocPtr, "Keywords"); 349 | meta.creator = nativeGetDocumentMetaText(doc.mNativeDocPtr, "Creator"); 350 | meta.producer = nativeGetDocumentMetaText(doc.mNativeDocPtr, "Producer"); 351 | meta.creationDate = nativeGetDocumentMetaText(doc.mNativeDocPtr, "CreationDate"); 352 | meta.modDate = nativeGetDocumentMetaText(doc.mNativeDocPtr, "ModDate"); 353 | 354 | return meta; 355 | } 356 | } 357 | 358 | /** Get table of contents (bookmarks) for given document */ 359 | public List getTableOfContents(PdfDocument doc) { 360 | synchronized (lock) { 361 | List topLevel = new ArrayList<>(); 362 | Long first = nativeGetFirstChildBookmark(doc.mNativeDocPtr, null); 363 | if (first != null) { 364 | recursiveGetBookmark(topLevel, doc, first); 365 | } 366 | return topLevel; 367 | } 368 | } 369 | 370 | private void recursiveGetBookmark(List tree, PdfDocument doc, long bookmarkPtr) { 371 | PdfDocument.Bookmark bookmark = new PdfDocument.Bookmark(); 372 | bookmark.mNativePtr = bookmarkPtr; 373 | bookmark.title = nativeGetBookmarkTitle(bookmarkPtr); 374 | bookmark.pageIdx = nativeGetBookmarkDestIndex(doc.mNativeDocPtr, bookmarkPtr); 375 | tree.add(bookmark); 376 | 377 | Long child = nativeGetFirstChildBookmark(doc.mNativeDocPtr, bookmarkPtr); 378 | if (child != null) { 379 | recursiveGetBookmark(bookmark.getChildren(), doc, child); 380 | } 381 | 382 | Long sibling = nativeGetSiblingBookmark(doc.mNativeDocPtr, bookmarkPtr); 383 | if (sibling != null) { 384 | recursiveGetBookmark(tree, doc, sibling); 385 | } 386 | } 387 | 388 | /** Get all links from given page */ 389 | public List getPageLinks(PdfDocument doc, int pageIndex) { 390 | synchronized (lock) { 391 | List links = new ArrayList<>(); 392 | Long nativePagePtr = doc.mNativePagesPtr.get(pageIndex); 393 | if (nativePagePtr == null) { 394 | return links; 395 | } 396 | long[] linkPtrs = nativeGetPageLinks(nativePagePtr); 397 | for (long linkPtr : linkPtrs) { 398 | Integer index = nativeGetDestPageIndex(doc.mNativeDocPtr, linkPtr); 399 | String uri = nativeGetLinkURI(doc.mNativeDocPtr, linkPtr); 400 | 401 | RectF rect = nativeGetLinkRect(linkPtr); 402 | if (rect != null && (index != null || uri != null)) { 403 | links.add(new PdfDocument.Link(rect, index, uri)); 404 | } 405 | 406 | } 407 | return links; 408 | } 409 | } 410 | 411 | /** 412 | * Map page coordinates to device screen coordinates 413 | * 414 | * @param doc pdf document 415 | * @param pageIndex index of page 416 | * @param startX left pixel position of the display area in device coordinates 417 | * @param startY top pixel position of the display area in device coordinates 418 | * @param sizeX horizontal size (in pixels) for displaying the page 419 | * @param sizeY vertical size (in pixels) for displaying the page 420 | * @param rotate page orientation: 0 (normal), 1 (rotated 90 degrees clockwise), 421 | * 2 (rotated 180 degrees), 3 (rotated 90 degrees counter-clockwise) 422 | * @param pageX X value in page coordinates 423 | * @param pageY Y value in page coordinate 424 | * @return mapped coordinates 425 | */ 426 | public Point mapPageCoordsToDevice(PdfDocument doc, int pageIndex, int startX, int startY, int sizeX, 427 | int sizeY, int rotate, double pageX, double pageY) { 428 | long pagePtr = doc.mNativePagesPtr.get(pageIndex); 429 | return nativePageCoordsToDevice(pagePtr, startX, startY, sizeX, sizeY, rotate, pageX, pageY); 430 | } 431 | 432 | /** 433 | * @return mapped coordinates 434 | * @see PdfiumCore#mapPageCoordsToDevice(PdfDocument, int, int, int, int, int, int, double, double) 435 | */ 436 | public RectF mapRectToDevice(PdfDocument doc, int pageIndex, int startX, int startY, int sizeX, 437 | int sizeY, int rotate, RectF coords) { 438 | 439 | Point leftTop = mapPageCoordsToDevice(doc, pageIndex, startX, startY, sizeX, sizeY, rotate, 440 | coords.left, coords.top); 441 | Point rightBottom = mapPageCoordsToDevice(doc, pageIndex, startX, startY, sizeX, sizeY, rotate, 442 | coords.right, coords.bottom); 443 | return new RectF(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y); 444 | } 445 | } 446 | -------------------------------------------------------------------------------- /src/main/java/com/shockwave/pdfium/util/Size.java: -------------------------------------------------------------------------------- 1 | package com.shockwave.pdfium.util; 2 | 3 | public class Size { 4 | private final int width; 5 | private final int height; 6 | 7 | public Size(int width, int height) { 8 | this.width = width; 9 | this.height = height; 10 | } 11 | 12 | public int getWidth() { 13 | return width; 14 | } 15 | 16 | public int getHeight() { 17 | return height; 18 | } 19 | 20 | @Override 21 | public boolean equals(final Object obj) { 22 | if (obj == null) { 23 | return false; 24 | } 25 | if (this == obj) { 26 | return true; 27 | } 28 | if (obj instanceof Size) { 29 | Size other = (Size) obj; 30 | return width == other.width && height == other.height; 31 | } 32 | return false; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return width + "x" + height; 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | // assuming most sizes are <2^16, doing a rotate will give us perfect hashing 43 | return height ^ ((width << (Integer.SIZE / 2)) | (width >>> (Integer.SIZE / 2))); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/shockwave/pdfium/util/SizeF.java: -------------------------------------------------------------------------------- 1 | package com.shockwave.pdfium.util; 2 | 3 | public class SizeF { 4 | private final float width; 5 | private final float height; 6 | 7 | public SizeF(float width, float height) { 8 | this.width = width; 9 | this.height = height; 10 | } 11 | 12 | public float getWidth() { 13 | return width; 14 | } 15 | 16 | public float getHeight() { 17 | return height; 18 | } 19 | 20 | @Override 21 | public boolean equals(final Object obj) { 22 | if (obj == null) { 23 | return false; 24 | } 25 | if (this == obj) { 26 | return true; 27 | } 28 | if (obj instanceof SizeF) { 29 | final SizeF other = (SizeF) obj; 30 | return width == other.width && height == other.height; 31 | } 32 | return false; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return width + "x" + height; 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | return Float.floatToIntBits(width) ^ Float.floatToIntBits(height); 43 | } 44 | 45 | public Size toSize() { 46 | return new Size((int) width, (int) height); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/jniLibs/arm64-v8a/libpdfium.cr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lion1988dev/PdfiumAndroid/5b0980bd396b801d4bc2a79c4833298a811b63e1/src/main/jniLibs/arm64-v8a/libpdfium.cr.so -------------------------------------------------------------------------------- /src/main/jniLibs/armeabi-v7a/libpdfium.cr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lion1988dev/PdfiumAndroid/5b0980bd396b801d4bc2a79c4833298a811b63e1/src/main/jniLibs/armeabi-v7a/libpdfium.cr.so -------------------------------------------------------------------------------- /src/main/jniLibs/x86/libpdfium.cr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lion1988dev/PdfiumAndroid/5b0980bd396b801d4bc2a79c4833298a811b63e1/src/main/jniLibs/x86/libpdfium.cr.so -------------------------------------------------------------------------------- /src/main/jniLibs/x86_64/libpdfium.cr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lion1988dev/PdfiumAndroid/5b0980bd396b801d4bc2a79c4833298a811b63e1/src/main/jniLibs/x86_64/libpdfium.cr.so --------------------------------------------------------------------------------