Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
Super PDF Reader
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
wanglei
Super PDF Reader
Commits
3ad487b9
Commit
3ad487b9
authored
Jun 26, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...提交部分功能...
parent
2b6ab242
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
146 additions
and
12 deletions
+146
-12
PdfBrowserActivity.kt
...va/com/base/superpdfreader/activity/PdfBrowserActivity.kt
+37
-8
PdfHelp.kt
...rc/main/java/com/base/superpdfreader/helps/pdf/PdfHelp.kt
+14
-3
DialogViews.kt
...src/main/java/com/base/superpdfreader/view/DialogViews.kt
+37
-0
activity_pdf_browser.xml
app/src/main/res/layout/activity_pdf_browser.xml
+1
-1
dialog_pdf_save.xml
app/src/main/res/layout/dialog_pdf_save.xml
+2
-0
item_enter_pdf_password.xml
app/src/main/res/layout/item_enter_pdf_password.xml
+55
-0
lock_pdf.png
app/src/main/res/mipmap-xxhdpi/lock_pdf.png
+0
-0
No files found.
app/src/main/java/com/base/superpdfreader/activity/PdfBrowserActivity.kt
View file @
3ad487b9
...
@@ -6,15 +6,17 @@ import android.animation.ValueAnimator
...
@@ -6,15 +6,17 @@ import android.animation.ValueAnimator
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
import
android.graphics.Color
import
android.graphics.Color
import
android.view.View
import
android.view.View
import
android.widget.Toast
import
androidx.activity.addCallback
import
androidx.activity.addCallback
import
androidx.core.animation.addListener
import
androidx.core.animation.addListener
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.base.superpdfreader.bean.PdfParameterBean
import
com.base.superpdfreader.databinding.ActivityPdfBrowserBinding
import
com.base.superpdfreader.databinding.ActivityPdfBrowserBinding
import
com.base.superpdfreader.helps.BaseActivity
import
com.base.superpdfreader.helps.BaseActivity
import
com.base.superpdfreader.helps.LogEx
import
com.base.superpdfreader.helps.LogEx
import
com.base.superpdfreader.utils.BarUtils
import
com.base.superpdfreader.utils.BarUtils
import
com.base.superpdfreader.view.DialogViews.showEnterDdfPassword
import
com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
import
com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
import
com.tom_roush.pdfbox.pdmodel.PDDocument
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.delay
...
@@ -40,17 +42,44 @@ class PdfBrowserActivity : BaseActivity<ActivityPdfBrowserBinding>() {
...
@@ -40,17 +42,44 @@ class PdfBrowserActivity : BaseActivity<ActivityPdfBrowserBinding>() {
val
path
=
intent
.
extras
?.
getString
(
"Path"
)
?:
""
val
path
=
intent
.
extras
?.
getString
(
"Path"
)
?:
""
val
file
=
File
(
path
)
val
file
=
File
(
path
)
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
binding
.
pdfview
.
fromFile
(
file
)
.
defaultPage
(
pageNumber
)
try
{
.
enableAnnotationRendering
(
true
)
PDDocument
.
load
(
file
)
.
scrollHandle
(
object
:
DefaultScrollHandle
(
this
)
{})
loadPdfView
(
file
)
.
spacing
(
10
)
}
catch
(
e
:
Exception
)
{
.
onPageError
{
page
,
t
->
}
.
load
()
dialog
=
showEnterDdfPassword
(
cancel
=
{
finishToMain
()
},
ok
=
{
password
->
var
pdDocument
:
PDDocument
?
=
null
runCatching
{
pdDocument
=
PDDocument
.
load
(
file
,
password
)
}
if
(
pdDocument
!=
null
)
{
dialog
?.
dismiss
()
loadPdfView
(
file
,
password
)
}
else
{
Toast
.
makeText
(
this
,
"Wrong password"
,
Toast
.
LENGTH_SHORT
).
show
()
}
})
}
}
}
}
}
private
fun
loadPdfView
(
file
:
File
,
password
:
String
=
""
)
{
binding
.
pdfview
.
fromFile
(
file
)
.
defaultPage
(
pageNumber
)
.
enableAnnotationRendering
(
true
)
.
scrollHandle
(
object
:
DefaultScrollHandle
(
this
)
{})
.
spacing
(
10
)
.
onPageError
{
page
,
t
->
LogEx
.
logDebug
(
TAG
,
"error $t"
)
}.
password
(
password
).
load
()
}
override
fun
initListener
()
{
override
fun
initListener
()
{
binding
.
pdfview
.
setOnClickListener
{
binding
.
pdfview
.
setOnClickListener
{
toggleTools
()
toggleTools
()
...
...
app/src/main/java/com/base/superpdfreader/helps/pdf/PdfHelp.kt
View file @
3ad487b9
...
@@ -12,6 +12,8 @@ import com.tom_roush.pdfbox.pdmodel.PDDocument
...
@@ -12,6 +12,8 @@ import com.tom_roush.pdfbox.pdmodel.PDDocument
import
com.tom_roush.pdfbox.pdmodel.PDPage
import
com.tom_roush.pdfbox.pdmodel.PDPage
import
com.tom_roush.pdfbox.pdmodel.PDPageContentStream
import
com.tom_roush.pdfbox.pdmodel.PDPageContentStream
import
com.tom_roush.pdfbox.pdmodel.common.PDRectangle
import
com.tom_roush.pdfbox.pdmodel.common.PDRectangle
import
com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission
import
com.tom_roush.pdfbox.pdmodel.encryption.StandardProtectionPolicy
import
com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject
import
com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject
import
java.io.BufferedInputStream
import
java.io.BufferedInputStream
import
java.io.ByteArrayOutputStream
import
java.io.ByteArrayOutputStream
...
@@ -28,11 +30,10 @@ object PdfHelp {
...
@@ -28,11 +30,10 @@ object PdfHelp {
LogEx
.
logDebug
(
TAG
,
"pageSize=${arrayPageSize[pdfParameterBean.pageSize]}"
)
LogEx
.
logDebug
(
TAG
,
"pageSize=${arrayPageSize[pdfParameterBean.pageSize]}"
)
LogEx
.
logDebug
(
TAG
,
"margin=${arrayMargin[pdfParameterBean.margin]}"
)
LogEx
.
logDebug
(
TAG
,
"margin=${arrayMargin[pdfParameterBean.margin]}"
)
LogEx
.
logDebug
(
TAG
,
"compression=${arrayCompression[pdfParameterBean.compression]}"
)
LogEx
.
logDebug
(
TAG
,
"compression=${arrayCompression[pdfParameterBean.compression]}"
)
LogEx
.
logDebug
(
TAG
,
"password=${pdfParameterBean.password}"
)
try
{
try
{
PDDocument
().
use
{
document
->
PDDocument
().
use
{
document
->
pdfParameterBean
.
pathArray
.
forEach
{
imagePath
->
pdfParameterBean
.
pathArray
.
forEach
{
imagePath
->
// val pdImage = PDImageXObject.createFromFileByExtension(File(imagePath), document)
// val pdImage = PDImageXObject.createFromFileByExtension(File(imagePath), document)
...
@@ -111,7 +112,9 @@ object PdfHelp {
...
@@ -111,7 +112,9 @@ object PdfHelp {
}
}
}
}
}
}
pdfParameterBean
.
password
?.
let
{
pwd
->
protectPdf
(
pwd
,
document
)
}
document
.
save
(
pdfPath
)
// 保存 PDF
document
.
save
(
pdfPath
)
// 保存 PDF
}
}
}
catch
(
e
:
IOException
)
{
}
catch
(
e
:
IOException
)
{
...
@@ -120,6 +123,14 @@ object PdfHelp {
...
@@ -120,6 +123,14 @@ object PdfHelp {
}
}
fun
protectPdf
(
password
:
String
,
document
:
PDDocument
)
{
val
accessPermission
=
AccessPermission
()
val
spp
=
StandardProtectionPolicy
(
password
,
password
,
accessPermission
)
spp
.
setEncryptionKeyLength
(
128
)
spp
.
permissions
=
accessPermission
document
.
protect
(
spp
)
}
fun
compressImage
(
path
:
String
,
compress
:
Int
):
ByteArray
{
fun
compressImage
(
path
:
String
,
compress
:
Int
):
ByteArray
{
val
bitmap
=
openImage2Bitmap
(
path
)
val
bitmap
=
openImage2Bitmap
(
path
)
val
out
=
ByteArrayOutputStream
()
val
out
=
ByteArrayOutputStream
()
...
...
app/src/main/java/com/base/superpdfreader/view/DialogViews.kt
View file @
3ad487b9
...
@@ -13,6 +13,8 @@ import com.base.superpdfreader.R
...
@@ -13,6 +13,8 @@ import com.base.superpdfreader.R
import
com.base.superpdfreader.databinding.DialogPermissonOpenBinding
import
com.base.superpdfreader.databinding.DialogPermissonOpenBinding
import
com.base.superpdfreader.databinding.ItemDeleteTipBinding
import
com.base.superpdfreader.databinding.ItemDeleteTipBinding
import
com.base.superpdfreader.databinding.ItemEditBinding
import
com.base.superpdfreader.databinding.ItemEditBinding
import
com.base.superpdfreader.databinding.ItemEnterPdfPasswordBinding
import
com.base.superpdfreader.view.DialogViews.showDeleteConfirm
import
com.base.superpdfreader.view.DialogViews.showRenameDialog
import
com.base.superpdfreader.view.DialogViews.showRenameDialog
object
DialogViews
{
object
DialogViews
{
...
@@ -110,4 +112,39 @@ object DialogViews {
...
@@ -110,4 +112,39 @@ object DialogViews {
nButton
.
textSize
=
16f
nButton
.
textSize
=
16f
nButton
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
color_pdf
))
nButton
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
color_pdf
))
}
}
fun
Context
.
showEnterDdfPassword
(
cancel
:
()
->
Unit
,
ok
:
(
password
:
String
)
->
Unit
):
AlertDialog
?
{
val
view
=
LayoutInflater
.
from
(
this
).
inflate
(
R
.
layout
.
item_enter_pdf_password
,
null
,
false
)
val
binding
=
ItemEnterPdfPasswordBinding
.
bind
(
view
)
val
dialog
=
AlertDialog
.
Builder
(
this
)
.
setView
(
view
)
.
setPositiveButton
(
"OK"
)
{
dialog
,
which
->
val
pwd
=
binding
.
editPassword
.
text
.
toString
()
if
(
pwd
.
isEmpty
())
{
Toast
.
makeText
(
this
,
"Password cannot be empty"
,
Toast
.
LENGTH_SHORT
).
show
()
return
@setPositiveButton
}
ok
.
invoke
(
pwd
)
}.
setNegativeButton
(
"CANCEL"
)
{
dialog
,
which
->
dialog
.
dismiss
()
cancel
.
invoke
()
}.
create
()
dialog
.
setCanceledOnTouchOutside
(
false
)
dialog
.
show
()
val
pButton
=
dialog
.
getButton
(
AlertDialog
.
BUTTON_POSITIVE
)
val
nButton
=
dialog
.
getButton
(
AlertDialog
.
BUTTON_NEGATIVE
)
pButton
.
textSize
=
16f
pButton
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
color_pdf
))
nButton
.
textSize
=
16f
nButton
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
color_pdf
))
return
dialog
}
}
}
app/src/main/res/layout/activity_pdf_browser.xml
View file @
3ad487b9
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
android:id=
"@+id/pdfview"
android:id=
"@+id/pdfview"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
android:layout_height=
"0dp"
android:background=
"#
FACCC6
"
android:background=
"#
E0E0E0
"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/v_top"
/>
app:layout_constraintTop_toBottomOf=
"@id/v_top"
/>
...
...
app/src/main/res/layout/dialog_pdf_save.xml
View file @
3ad487b9
...
@@ -275,6 +275,8 @@
...
@@ -275,6 +275,8 @@
android:layout_marginHorizontal=
"15dp"
android:layout_marginHorizontal=
"15dp"
android:background=
"@null"
android:background=
"@null"
android:hint=
"Password"
android:hint=
"Password"
android:inputType=
"textVisiblePassword"
android:singleLine=
"true"
tools:ignore=
"Autofill,HardcodedText,TextFields"
/>
tools:ignore=
"Autofill,HardcodedText,TextFields"
/>
</com.noober.background.view.BLFrameLayout>
</com.noober.background.view.BLFrameLayout>
...
...
app/src/main/res/layout/item_enter_pdf_password.xml
0 → 100644
View file @
3ad487b9
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"30dp"
android:layout_marginTop=
"15dp"
tools:ignore=
"UseCompoundDrawables"
>
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_vertical"
android:src=
"@mipmap/lock_pdf"
tools:ignore=
"ContentDescription"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_vertical"
android:layout_marginStart=
"16dp"
android:text=
"Protected PDF"
android:textColor=
"@color/black"
android:textSize=
"20sp"
tools:ignore=
"HardcodedText"
/>
</LinearLayout>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"30dp"
android:layout_marginTop=
"10dp"
android:text=
"Enter password"
android:textSize=
"16sp"
tools:ignore=
"HardcodedText"
/>
<EditText
android:textSize=
"16sp"
android:id=
"@+id/edit_password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginHorizontal=
"30dp"
android:layout_marginTop=
"8dp"
android:layout_marginBottom=
"16dp"
android:inputType=
"textVisiblePassword"
android:theme=
"@style/MyMyEditText"
tools:ignore=
"Autofill,LabelFor,TextFields"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/mipmap-xxhdpi/lock_pdf.png
0 → 100644
View file @
3ad487b9
1.38 KB
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