Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PDF Viewer Scanner White ago
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kuxulei
PDF Viewer Scanner White ago
Commits
9f95e179
Commit
9f95e179
authored
Sep 30, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
118a1bd6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
24 deletions
+44
-24
PdfBoxUtils.kt
...base/pdfviewerscannerwhite/ui/document/pdf/PdfBoxUtils.kt
+8
-3
PdfPresenter.kt
...ase/pdfviewerscannerwhite/ui/document/pdf/PdfPresenter.kt
+36
-21
No files found.
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfBoxUtils.kt
View file @
9f95e179
...
@@ -6,6 +6,7 @@ import android.graphics.drawable.BitmapDrawable
...
@@ -6,6 +6,7 @@ import android.graphics.drawable.BitmapDrawable
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
android.net.Uri
import
android.net.Uri
import
com.base.pdfviewerscannerwhite.helper.MyApplication.Companion.context
import
com.base.pdfviewerscannerwhite.helper.MyApplication.Companion.context
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.base.pdfviewerscannerwhite.utils.UriUtils.readFileToByteArray
import
com.base.pdfviewerscannerwhite.utils.UriUtils.readFileToByteArray
import
com.tom_roush.pdfbox.pdmodel.PDDocument
import
com.tom_roush.pdfbox.pdmodel.PDDocument
import
com.tom_roush.pdfbox.pdmodel.PDPage
import
com.tom_roush.pdfbox.pdmodel.PDPage
...
@@ -25,7 +26,6 @@ object PdfBoxUtils {
...
@@ -25,7 +26,6 @@ object PdfBoxUtils {
private
val
TAG
=
"PdfUtils"
private
val
TAG
=
"PdfUtils"
fun
getNumberOfPages
(
filePath
:
String
,
password
:
String
?
=
null
,
uri
:
String
?
=
null
):
Int
{
fun
getNumberOfPages
(
filePath
:
String
,
password
:
String
?
=
null
,
uri
:
String
?
=
null
):
Int
{
val
document
=
val
document
=
loadPDDocument
(
path
=
filePath
,
password
,
uri
)
loadPDDocument
(
path
=
filePath
,
password
,
uri
)
...
@@ -90,7 +90,8 @@ object PdfBoxUtils {
...
@@ -90,7 +90,8 @@ object PdfBoxUtils {
sourceFilePath
:
String
,
sourceFilePath
:
String
,
userPassword
:
String
,
userPassword
:
String
,
ownerPassword
:
String
ownerPassword
:
String
)
{
):
Boolean
{
try
{
try
{
PDDocument
.
load
(
File
(
sourceFilePath
)).
use
{
document
->
PDDocument
.
load
(
File
(
sourceFilePath
)).
use
{
document
->
val
ap
=
AccessPermission
()
val
ap
=
AccessPermission
()
...
@@ -102,10 +103,14 @@ object PdfBoxUtils {
...
@@ -102,10 +103,14 @@ object PdfBoxUtils {
val
spp
=
StandardProtectionPolicy
(
userPassword
,
ownerPassword
,
ap
)
val
spp
=
StandardProtectionPolicy
(
userPassword
,
ownerPassword
,
ap
)
document
.
protect
(
spp
)
document
.
protect
(
spp
)
document
.
save
(
File
(
sourceFilePath
))
document
.
save
(
File
(
sourceFilePath
))
LogEx
.
logDebug
(
TAG
,
"setPassword finish"
)
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
LogEx
.
logDebug
(
TAG
,
"setPassword Exception ${e.printStackTrace()}"
)
e
.
printStackTrace
()
return
false
}
}
return
true
}
}
fun
clearPassword
(
filePath
:
String
,
password
:
String
)
{
fun
clearPassword
(
filePath
:
String
,
password
:
String
)
{
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfPresenter.kt
View file @
9f95e179
...
@@ -13,8 +13,6 @@ import com.base.pdfviewerscannerwhite.utils.LogEx
...
@@ -13,8 +13,6 @@ import com.base.pdfviewerscannerwhite.utils.LogEx
import
com.base.pdfviewerscannerwhite.utils.UriUtils.readFileToByteArray
import
com.base.pdfviewerscannerwhite.utils.UriUtils.readFileToByteArray
import
com.tom_roush.pdfbox.multipdf.PDFMergerUtility
import
com.tom_roush.pdfbox.multipdf.PDFMergerUtility
import
com.tom_roush.pdfbox.pdmodel.PDDocument
import
com.tom_roush.pdfbox.pdmodel.PDDocument
import
java.io.ByteArrayInputStream
import
java.io.ByteArrayOutputStream
import
java.io.File
import
java.io.File
...
@@ -142,30 +140,46 @@ class PdfPresenter(
...
@@ -142,30 +140,46 @@ class PdfPresenter(
val
mergerUtility
=
PDFMergerUtility
()
val
mergerUtility
=
PDFMergerUtility
()
mergerUtility
.
destinationFileName
=
mergePath
mergerUtility
.
destinationFileName
=
mergePath
//解密
PdfMergeActivity
.
mergePdfList
.
filter
{
it
.
state
==
1
}.
forEach
{
PdfBoxUtils
.
clearPassword
(
it
.
path
,
it
.
password
)
}
LogEx
.
logDebug
(
TAG
,
"mergePdf ${mergePdfList.size}"
)
LogEx
.
logDebug
(
TAG
,
"mergePdf ${mergePdfList.size}"
)
PdfMergeActivity
.
mergePdfList
.
forEach
{
documentBean
->
PdfMergeActivity
.
mergePdfList
.
forEach
{
documentBean
->
LogEx
.
logDebug
(
TAG
,
"mergePdf item= ${documentBean.path} ${documentBean.state}"
)
LogEx
.
logDebug
(
TAG
,
"mergePdf item= ${documentBean.path} ${documentBean.state}"
)
if
(
documentBean
.
state
==
0
)
{
//带密码 mergerUtility.addSource(inputStream) 不行
mergerUtility
.
addSource
(
File
(
documentBean
.
path
))
mergerUtility
.
addSource
(
File
(
documentBean
.
path
))
}
else
{
LogEx
.
logDebug
(
TAG
,
"mergePdf password=${documentBean.password}"
)
// if (documentBean.state == 0) {
try
{
// mergerUtility.addSource(File(documentBean.path))
val
pdfDocument
=
PDDocument
.
load
(
File
(
documentBean
.
path
),
documentBean
.
password
)
// } else {
LogEx
.
logDebug
(
TAG
,
"mergePdf pdfDocument ${pdfDocument.numberOfPages}"
)
// LogEx.logDebug(TAG, "mergePdf password=${documentBean.password}")
val
byteArrayOutputStream
=
ByteArrayOutputStream
(
1024
*
2
)
// try {
pdfDocument
.
save
(
byteArrayOutputStream
)
// val pdfDocument = PDDocument.load(File(documentBean.path), documentBean.password)
LogEx
.
logDebug
(
TAG
,
"mergePdf byteArrayOutputStream ${byteArrayOutputStream.size()}"
)
// LogEx.logDebug(TAG, "mergePdf pdfDocument ${pdfDocument.numberOfPages}")
pdfDocument
.
close
()
// val byteArrayOutputStream = ByteArrayOutputStream()
val
inputStream
=
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
())
// pdfDocument.save(byteArrayOutputStream)
LogEx
.
logDebug
(
TAG
,
"mergePdf inputStream"
)
// LogEx.logDebug(TAG, "mergePdf byteArrayOutputStream ${byteArrayOutputStream.size()}")
mergerUtility
.
addSource
(
inputStream
)
// pdfDocument.close()
}
catch
(
e
:
Exception
)
{
// val inputStream = ByteArrayInputStream(byteArrayOutputStream.toByteArray())
LogEx
.
logDebug
(
TAG
,
"mergePdf Exception ${e.printStackTrace()}"
)
// LogEx.logDebug(TAG, "mergePdf inputStream")
}
// mergerUtility.addSource(inputStream)
LogEx
.
logDebug
(
TAG
,
"mergePdf inputStream"
)
// } catch (e: Exception) {
}
// LogEx.logDebug(TAG, "mergePdf Exception ${e.printStackTrace()}")
// }
// LogEx.logDebug(TAG, "mergePdf inputStream")
// }
}
}
mergerUtility
.
mergeDocuments
(
null
)
mergerUtility
.
mergeDocuments
(
null
)
//重新加密
PdfMergeActivity
.
mergePdfList
.
filter
{
it
.
state
==
1
}.
forEach
{
val
flag
=
PdfBoxUtils
.
setPassword
(
it
.
path
,
it
.
password
,
it
.
password
)
LogEx
.
logDebug
(
TAG
,
"重新加密 flag=$flag ${it.path} ${it.password}"
)
}
mergePdfList
.
clear
()
mergePdfList
.
clear
()
LogEx
.
logDebug
(
TAG
,
"mergePdf finish"
)
LogEx
.
logDebug
(
TAG
,
"mergePdf finish"
)
isSuccess
=
true
isSuccess
=
true
...
@@ -173,6 +187,7 @@ class PdfPresenter(
...
@@ -173,6 +187,7 @@ class PdfPresenter(
}
}
finishAction
.
invoke
(
isSuccess
)
finishAction
.
invoke
(
isSuccess
)
}.
start
()
}.
start
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment