Skip to content

Commit 8ef5cb0

Browse files
author
PSPDFKit
committed
Release 3.4.0
1 parent 940ca0f commit 8ef5cb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2179
-181
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Newest Release
22

3+
### 3.4.0 - 26 Oct 2022
4+
5+
- Adds generating PDF from images, templates and HTML. (#36736)
6+
- Updates for PSPDFKit 8.4.1 Android. (#37192)
7+
- Updates for PSPDFKit 12.0 for iOS. (#37192)
8+
- Fixes keyboard cutting off search results when inline search is disabled. (#35418)
9+
- Fixes an issue where the `PspdfkitView` widget is not rendered in Flutter versions 3.3.0 and above on Android. (#37044)
10+
## Previous Releases
11+
312
### 3.3.0 - 19 Jul 2022
413

514
- Moved package files from `lib/src` to `lib` to remove import warnings and renamed `main.dart` to `pspdfkit.dart`. (#34058)
@@ -11,8 +20,6 @@
1120
- Fixes an issue where tapping on form fields yields unexpected behavior in the Catalog basic example. (#33853)
1221
- Fixes the configuration option `userInterfaceViewMode: 'alwaysHidden'` not hiding the widget’s top bar on iOS. (#31095)
1322

14-
## Previous Releases
15-
1623
### 3.2.2 - 16 Mar 2022
1724

1825
- Improves the example project by using the `PlatformUtils` class to check for supported platforms (#33212)

android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ apply plugin: 'kotlin-android'
3737

3838
android {
3939
compileSdkVersion androidCompileSdkVersion
40-
buildToolsVersion androidBuildToolsVersion
4140

4241
compileOptions {
4342
sourceCompatibility 1.8

android/config.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (pspdfkitMavenUrl == null || pspdfkitMavenUrl == '') {
3838

3939
ext.pspdfkitVersion = localProperties.getProperty('pspdfkit.version')
4040
if (pspdfkitVersion == null || pspdfkitVersion == '') {
41-
ext.pspdfkitVersion = '8.2.1'
41+
ext.pspdfkitVersion = '8.4.1'
4242
}
4343

4444
ext.pspdfkitMavenModuleName = 'pspdfkit'
@@ -53,7 +53,6 @@ def pubspecYaml = new Yaml().load(pubspecFile.newInputStream())
5353
ext.pspdfkitFlutterVersion = pubspecYaml.version
5454

5555
ext.androidCompileSdkVersion = 31
56-
ext.androidBuildToolsVersion = '30.0.3'
5756
ext.androidMinSdkVersion = 21
5857
ext.androidTargetSdkVersion = 30
5958
ext.androidGradlePluginVersion = '7.1.1'

android/src/main/java/com/pspdfkit/flutter/pspdfkit/PSPDFKitView.kt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pspdfkit.flutter.pspdfkit
22

33
import android.content.Context
4+
import android.content.MutableContextWrapper
45
import android.net.Uri
56
import android.view.View
67
import androidx.fragment.app.FragmentActivity
@@ -17,6 +18,10 @@ import com.pspdfkit.forms.EditableButtonFormElement
1718
import com.pspdfkit.forms.SignatureFormElement
1819
import com.pspdfkit.forms.TextFormElement
1920
import com.pspdfkit.ui.PdfUiFragment
21+
import com.pspdfkit.document.processor.PdfProcessor
22+
import com.pspdfkit.document.processor.PdfProcessorTask
23+
import com.pspdfkit.document.processor.NewPage
24+
import com.pspdfkit.document.processor.PagePattern
2025
import com.pspdfkit.ui.PdfUiFragmentBuilder
2126
import io.flutter.plugin.common.BinaryMessenger
2227
import io.flutter.plugin.common.MethodCall
@@ -29,9 +34,20 @@ import io.reactivex.android.schedulers.AndroidSchedulers
2934
import io.reactivex.schedulers.Schedulers
3035
import org.json.JSONObject
3136
import java.io.ByteArrayOutputStream
37+
import java.io.File
38+
import android.app.Activity
39+
import android.content.Intent
40+
import android.graphics.BitmapFactory
41+
import android.graphics.RectF
42+
import android.os.Bundle
43+
import com.pspdfkit.configuration.activity.PdfActivityConfiguration
44+
import com.pspdfkit.document.processor.PageImage
45+
import com.pspdfkit.ui.PdfActivity
46+
import com.pspdfkit.utils.Size
47+
import java.io.FileInputStream
3248

3349
internal class PSPDFKitView(
34-
context: Context,
50+
val context: Context,
3551
id: Int,
3652
messenger: BinaryMessenger,
3753
documentPath: String? = null,
@@ -69,14 +85,14 @@ internal class PSPDFKitView(
6985
fragmentContainerView?.let {
7086
it.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
7187
override fun onViewAttachedToWindow(view: View?) {
72-
(context as FragmentActivity).supportFragmentManager.commit {
88+
getFragmentActivity(context).supportFragmentManager.commit {
7389
add(it.id, pdfUiFragment)
7490
setReorderingAllowed(true)
7591
}
7692
}
7793

7894
override fun onViewDetachedFromWindow(view: View?) {
79-
(context as FragmentActivity).supportFragmentManager.commit {
95+
getFragmentActivity(context).supportFragmentManager.commit {
8096
remove(pdfUiFragment)
8197
setReorderingAllowed(true)
8298
}
@@ -368,6 +384,21 @@ internal class PSPDFKitView(
368384
}
369385
}
370386

387+
// Get Fragment Activity from context
388+
private fun getFragmentActivity(context: Context): FragmentActivity {
389+
return when (context) {
390+
is FragmentActivity -> {
391+
context
392+
}
393+
is MutableContextWrapper -> {
394+
getFragmentActivity(context.baseContext)
395+
}
396+
else -> {
397+
throw IllegalStateException("Context is not a FragmentActivity")
398+
}
399+
}
400+
}
401+
371402
companion object {
372403
private const val LOG_TAG = "PSPDFKitPlugin"
373404
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright © 2018-2022 PSPDFKit GmbH. All rights reserved.
3+
*
4+
* THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
5+
* AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
6+
* UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
7+
* This notice may not be removed from this file.
8+
*/
9+
10+
package com.pspdfkit.flutter.pspdfkit
11+
12+
import android.annotation.SuppressLint
13+
import android.content.Context
14+
import android.net.Uri
15+
import com.pspdfkit.document.html.HtmlToPdfConverter
16+
import io.flutter.plugin.common.MethodChannel
17+
import io.reactivex.android.schedulers.AndroidSchedulers
18+
import io.reactivex.schedulers.Schedulers
19+
import java.io.File
20+
21+
object PspdfkitHTMLConverter {
22+
23+
@JvmStatic
24+
@SuppressLint("CheckResult")
25+
fun generateFromHtmlString(
26+
context: Context,
27+
html: String,
28+
outputFilePath: String,
29+
options: Map<String, Any>?,
30+
results: MethodChannel.Result
31+
) {
32+
val outputFile = File(outputFilePath)// Output file for the converted PDF.
33+
34+
val converter = if (options?.contains("baseUrl") == true) HtmlToPdfConverter.fromHTMLString(
35+
context,
36+
html,
37+
options["baseUrl"] as String
38+
) else HtmlToPdfConverter.fromHTMLString(context, html)
39+
40+
if (options?.contains("enableJavaScript") == true)
41+
converter.setJavaScriptEnabled(options["enableJavaScript"] as Boolean)
42+
43+
if (options?.contains("documentTitle") == true)
44+
converter.title(options["documentTitle"] as String)
45+
46+
converter
47+
// Perform the conversion.
48+
.convertToPdfAsync(outputFile)
49+
.subscribeOn(Schedulers.io())
50+
// Publish results on the main thread so we can update the UI.
51+
.observeOn(AndroidSchedulers.mainThread())
52+
.subscribe(
53+
{ results.success(outputFile.absolutePath) },
54+
{ results.error("HTML_TO_PDF_ERROR", it.message, null) })
55+
}
56+
57+
@JvmStatic
58+
@SuppressLint("CheckResult")
59+
fun generateFromHtmlUri(
60+
context: Context,
61+
htmlUriString: String,
62+
outputFilePath: String,
63+
options: Map<String, Any>?,
64+
results: MethodChannel.Result
65+
) {
66+
val outputFile = File(outputFilePath)// Output file for the converted PDF.
67+
val convertor = HtmlToPdfConverter.fromUri(context, Uri.parse(htmlUriString))
68+
69+
// Configure javascript enabled
70+
if (options?.contains("enableJavaScript") == true)
71+
convertor.setJavaScriptEnabled(options["enableJavaScript"] as Boolean)
72+
73+
// Configure title for the created document.
74+
if (options?.contains("documentTitle") == true) convertor.title(options["documentTitle"] as String)
75+
76+
convertor
77+
// Perform the conversion.
78+
.convertToPdfAsync(outputFile)
79+
// Subscribe to the conversion result.
80+
.subscribe({
81+
// Return the converted document.
82+
results.success(outputFilePath)
83+
}, {
84+
// Handle the error.
85+
results.error("Error converting HTML to PDF", it.message, null)
86+
})
87+
}
88+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.pspdfkit.flutter.pspdfkit
2+
3+
import android.util.Log
4+
import com.pspdfkit.document.processor.PdfProcessor
5+
import com.pspdfkit.document.processor.PdfProcessorTask
6+
import com.pspdfkit.flutter.pspdfkit.pdfgeneration.PdfPageAdaptor
7+
import io.flutter.plugin.common.MethodChannel
8+
import io.reactivex.android.schedulers.AndroidSchedulers
9+
import io.reactivex.disposables.Disposable
10+
import io.reactivex.schedulers.Schedulers
11+
import java.io.File
12+
13+
class PspdfkitPdfGenerator(private val pageAdaptor: PdfPageAdaptor) {
14+
15+
var disposable: Disposable? = null
16+
17+
/**
18+
* Creates a new [PdfProcessorTask] that can be used to process a PDF document.
19+
*/
20+
fun generatePdf(
21+
pages: List<HashMap<String, Any>>,
22+
outputFilePath: String,
23+
result: MethodChannel.Result
24+
) {
25+
26+
val documentPages = pageAdaptor.parsePages(pages)
27+
val task = PdfProcessorTask.empty()
28+
29+
documentPages.forEachIndexed { index, newPage ->
30+
task.addNewPage(newPage, index)
31+
}
32+
33+
val outputFile = File(outputFilePath);
34+
disposable = PdfProcessor
35+
.processDocumentAsync(task, outputFile)
36+
.subscribeOn(Schedulers.io())
37+
// Publish results on the main thread so we can update the UI.
38+
.observeOn(AndroidSchedulers.mainThread())
39+
.subscribe({
40+
//Log progress
41+
Log.d(
42+
"PDF Generation",
43+
"generatePdf: Processing page ${it.pagesProcessed + 1} of ${it.totalPages}"
44+
)
45+
}, {
46+
// Handle the error.
47+
result.error("Error generating PDF", it.message, null)
48+
}, {
49+
result.success(outputFilePath)
50+
})
51+
}
52+
53+
fun dispose() {
54+
disposable?.dispose()
55+
instance = null
56+
}
57+
58+
companion object {
59+
60+
private var instance: PspdfkitPdfGenerator? = null
61+
62+
fun getInstance(pageAdaptor: PdfPageAdaptor): PspdfkitPdfGenerator {
63+
if (instance == null) {
64+
instance = PspdfkitPdfGenerator(pageAdaptor)
65+
}
66+
return instance!!
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)