Skip to content

Commit

Permalink
Release 2.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PSPDFKit committed Jun 7, 2024
1 parent 34697d8 commit 8b4d9ef
Show file tree
Hide file tree
Showing 53 changed files with 1,195 additions and 5,682 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## Newest Release

### 2.11.0 - 07 Jun 2024

- Adds the ability to clear the document cache. (J#HYB-347)
- Adds support for opening PDF documents from a remote URL. (J#HYB-354)
- Updates `setAnnotationFlags` and `getAnnotationFlags` APIs to support using annotation `name` as an identifier. (J#HYB-372)
- Fixes an issue where calling `exitCurrentlyActiveMode` while not in annotation editing mode generates an exception on iOS. (J#HYB-373)
- Fixes an issue where the annotation `uuid` isn't included in `onAnnotationTapped` callbacks. (J#HYB-374)
- Fixes an issue where Instant configuration wasn't applied when using the `presentInstant` API on iOS. (J#HYB-375)

## Previous Releases

### 2.10.0 - 06 May 2024

- Adds the ability to define annotation behavior using flags. (J#HYB-283)
Expand All @@ -9,8 +20,6 @@
- Fixes an issue where selecting a measurement annotation without the Measurement Tools license causes a crash. (J#HYB-318)
- Fixes an issue where the `removeAnnotation` API sometimes failed to remove an annotation on iOS. (J#HYB-43)

## Previous Releases

### 2.9.1 - 12 Apr 2024

- Adds the ability to import and export annotations from XFDF files. (J#HYB-293)
Expand Down
Binary file modified License-Evaluation.pdf
Binary file not shown.
57 changes: 57 additions & 0 deletions android/src/main/java/com/pspdfkit/react/PDFDocumentModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.pspdfkit.react

import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.module.annotations.ReactModule
import com.pspdfkit.document.PdfDocument

@ReactModule(name = PDFDocumentModule.NAME)
class PDFDocumentModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {

private var documents = mutableMapOf<Int, PdfDocument>()

override fun getName(): String {
return NAME
}

private fun getDocument(reference: Int): PdfDocument? {
return this.documents[reference]
}

fun setDocument(document: PdfDocument, reference: Int) {
this.documents[reference] = document
}

@ReactMethod fun getDocumentId(reference: Int, promise: Promise) {
try {
// Using uid here until Android exposes the documentId property.
promise.resolve(this.getDocument(reference)?.uid)
} catch (e: Throwable) {
promise.reject("getDocumentId error", e)
}
}

@ReactMethod fun invalidateCacheForPage(reference: Int, pageIndex: Int, promise: Promise) {
try {
this.getDocument(reference)?.invalidateCacheForPage(pageIndex)
promise.resolve(true)
} catch (e: Throwable) {
promise.reject("invalidateCacheForPage error", e)
}
}

@ReactMethod fun invalidateCache(reference: Int, promise: Promise) {
try {
this.getDocument(reference)?.invalidateCache()
promise.resolve(true)
} catch (e: Throwable) {
promise.reject("invalidateCache error", e)
}
}

companion object {
const val NAME = "PDFDocumentManager"
}
}
5 changes: 2 additions & 3 deletions android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ public String getName() {

@ReactMethod
public void present(@NonNull String document, @NonNull ReadableMap configuration, @Nullable Promise promise) {
File documentFile = new File(document);
if(PSPDFKitUtils.isValidPdf(documentFile)) {
if(PSPDFKitUtils.isValidPdf(document)) {
lastPresentPromise = promise;
presentPdf(document, configuration, promise);
} else if(PSPDFKitUtils.isValidImage(documentFile)) {
} else if(PSPDFKitUtils.isValidImage(document)) {
lastPresentPromise = promise;
presentImage(document, configuration, promise);
}else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
modules.add(new PSPDFKitModule(reactContext));
modules.add(new TestingModule(reactContext));
modules.add(new RNProcessor(reactContext));
modules.add(new PDFDocumentModule(reactContext));
return modules;
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
List<ViewManager> viewManagers = new ArrayList<>();
viewManagers.add(new ReactPdfViewManager());
viewManagers.add(new ReactPdfViewManager(reactContext));
return viewManagers;
}
}
14 changes: 11 additions & 3 deletions android/src/main/java/com/pspdfkit/react/ReactPdfViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
Expand Down Expand Up @@ -78,6 +79,12 @@ public class ReactPdfViewManager extends ViewGroupManager<PdfView> {

private final CompositeDisposable annotationDisposables = new CompositeDisposable();

private final ReactApplicationContext reactApplicationContext;

public ReactPdfViewManager(ReactApplicationContext reactApplicationContext) {
this.reactApplicationContext = reactApplicationContext;
}

@NonNull
@Override
public String getName() {
Expand Down Expand Up @@ -152,13 +159,14 @@ public void setConfiguration(PdfView view, @NonNull ReadableMap configuration) {
view.setConfiguration(configurationBuild);
}
view.setDocumentPassword(configuration.getString("documentPassword"));
view.setRemoteDocumentConfiguration(configuration.getMap("remoteDocumentConfiguration"));
// Although MeasurementValueConfigurations is specified as part of Configuration, it is configured separately on the Android SDK
if (configuration.getArray("measurementValueConfigurations") != null) {
view.setMeasurementValueConfigurations(configuration.getArray("measurementValueConfigurations"));
}
}
}

@ReactProp(name = "annotationPresets")
@ReactProp(name = "annotationPresets")
public void setAnnotationPresets(PdfView view, @NonNull ReadableMap annotationPresets) {
Map<AnnotationType, AnnotationConfiguration> annotationsConfiguration = AnnotationConfigurationAdaptor.convertAnnotationConfigurations(
view.getContext(), annotationPresets
Expand All @@ -168,7 +176,7 @@ public void setAnnotationPresets(PdfView view, @NonNull ReadableMap annotationPr

@ReactProp(name = "document")
public void setDocument(PdfView view, @NonNull String document) {
view.setDocument(document);
view.setDocument(document, this.reactApplicationContext);
}

@ReactProp(name = "pageIndex")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CustomAnnotationContextualMenuItemTappedEvent: Event<CustomAnnotationConte
this.buttonId = buttonId
}

override fun getEventName(): String? {
override fun getEventName(): String {
return EVENT_NAME
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CustomToolbarButtonTappedEvent: Event<CustomToolbarButtonTappedEvent> {
this.buttonId = buttonId
}

override fun getEventName(): String? {
override fun getEventName(): String {
return EVENT_NAME
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {
if (rawInstantJson != null && !rawInstantJson.equals("null")) {
JSONObject instantJson = new JSONObject(rawInstantJson);
Map<String, Object> map = JsonUtilities.jsonObjectToMap(instantJson);
map.put("uuid", annotation.getUuid());
WritableMap eventData = Arguments.makeNativeMap(map);
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), eventData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public PdfViewDataReturnedEvent(@IdRes int viewId, int requestId, @NonNull List<
continue;
}
JSONObject instantJson = new JSONObject(annotation.toInstantJson());
annotationsSerialized.add(JsonUtilities.jsonObjectToMap(instantJson));
Map<String, Object> annotationMap = JsonUtilities.jsonObjectToMap(instantJson);
annotationMap.put("uuid", annotation.getUuid());
annotationsSerialized.add(annotationMap);
}

Map<String, Object> annotations = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class PSPDFKitUtils {
)

@JvmStatic
public fun isValidImage(file: File): Boolean {
public fun isValidImage(path: String): Boolean {
val file = File(path)
for (extension in SUPPORTED_IMAGE_TYPES) {
if (file.name.lowercase(Locale.getDefault()).endsWith(extension)) {
return true
Expand All @@ -27,8 +28,9 @@ class PSPDFKitUtils {
}

@JvmStatic
public fun isValidPdf(file: File): Boolean {
return file.name.lowercase(Locale.getDefault()).endsWith(".pdf")
public fun isValidPdf(path: String): Boolean {
val file = File(path)
return file.name.lowercase(Locale.getDefault()).endsWith(".pdf")
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.pspdfkit.react.helper

import android.content.Context
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import com.facebook.react.bridge.ReactApplicationContext
import com.pspdfkit.document.download.DownloadJob
import com.pspdfkit.document.download.DownloadProgressFragment
import com.pspdfkit.document.download.DownloadRequest
import com.pspdfkit.document.download.source.DownloadSource
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.MalformedURLException
import java.net.URL
import java.net.URLConnection

class RemoteDocumentDownloader(private val remoteURL: String,
private var destinationFileURL: String?,
private val overwriteExisting: Boolean,
private val context: Context,
private val fragmentManager: FragmentManager) {

fun startDownload(callback: (File?) -> Unit) {
val source: WebDownloadSource = try {
// Try to parse the URL pointing to the PDF document.
WebDownloadSource(URL(remoteURL))
} catch (e: MalformedURLException) {
// Error while trying to parse the PDF Download URL
return
}

if (overwriteExisting && destinationFileURL != null) {
val delete = File(destinationFileURL)
if (delete.exists()) {
delete.delete()
}
}

val request = DownloadRequest.Builder(context)
.source(source)
.outputFile(if (destinationFileURL == null)
File(context.getDir("documents", Context.MODE_PRIVATE), "temp.pdf") else
File(destinationFileURL))
.overwriteExisting(overwriteExisting)
.useTemporaryOutputFile(false)
.build()

val job = DownloadJob.startDownload(request)
job.setProgressListener(object : DownloadJob.ProgressListenerAdapter() {
override fun onComplete(output: File) {
callback(output)
}

override fun onError(exception: Throwable) {
callback(null)
}
})
val fragment = DownloadProgressFragment()
fragment.show(fragmentManager, "download-fragment")
fragment.job = job
}
}

class WebDownloadSource constructor(private val documentURL: URL) : DownloadSource {
/**
* The open method needs to return an [InputStream] that will provide the complete document.
*/
@Throws(IOException::class)
override fun open(): InputStream {
val connection = documentURL.openConnection() as HttpURLConnection
connection.connect()
return connection.inputStream
}

/**
* If the length is available it can be returned here. This is optional, and can improve the reported download progress, since it will then contain
* a percentage of download.
*/
override fun getLength(): Long {
var length = DownloadSource.UNKNOWN_DOWNLOAD_SIZE

// We try to estimate the download size using the content length header.
var urlConnection: URLConnection? = null
try {
urlConnection = documentURL.openConnection()
val contentLength = urlConnection.contentLength
if (contentLength != -1) {
length = contentLength.toLong()
}
} catch (e: IOException) {
// Error while trying to parse the PDF Download URL
} finally {
(urlConnection as? HttpURLConnection)?.disconnect()
}
return length
}

override fun toString(): String {
return "WebDownloadSource{documentURL=$documentURL}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private int getIdFromName(@NonNull String name) {
case "markup":
return com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_group_markup;
case "writing":
return com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_item_writing;
return com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_group_writing;
case "highlight":
return com.pspdfkit.R.id.pspdf__annotation_creation_toolbar_item_highlight;
case "squiggly":
Expand Down
Loading

0 comments on commit 8b4d9ef

Please sign in to comment.