Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PDF Viewer Scanner White
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
PDF Viewer Scanner White
Commits
4592181e
Commit
4592181e
authored
Nov 21, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
ef7a5af2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
PdfBoxUtils.kt
...base/pdfviewerscannerwhite/ui/document/pdf/PdfBoxUtils.kt
+11
-4
No files found.
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfBoxUtils.kt
View file @
4592181e
...
...
@@ -29,7 +29,9 @@ object PdfBoxUtils {
fun
getNumberOfPages
(
filePath
:
String
,
password
:
String
?
=
null
,
uri
:
String
?
=
null
):
Int
{
val
document
=
loadPDDocument
(
path
=
filePath
,
password
,
uri
)
return
document
.
numberOfPages
val
number
=
document
.
numberOfPages
document
.
close
()
return
number
}
...
...
@@ -43,10 +45,9 @@ object PdfBoxUtils {
):
Drawable
{
val
document
=
loadPDDocument
(
filePath
,
password
,
uri
)
val
renderer
=
PDFRenderer
(
document
)
val
bitmap
:
Bitmap
=
renderer
.
renderImage
(
pageIndex
,
scale
,
ImageType
.
RGB
,
RenderDestination
.
EXPORT
)
val
drawable
=
BitmapDrawable
(
context
.
resources
,
bitmap
)
document
.
close
()
return
drawable
}
...
...
@@ -143,8 +144,9 @@ object PdfBoxUtils {
password
:
String
,
uri
:
String
?
=
null
):
Boolean
{
var
pdfDocument
:
PDDocument
?
=
null
try
{
val
pdfDocument
=
loadPDDocument
(
filePath
,
password
,
uri
)
pdfDocument
=
loadPDDocument
(
filePath
,
password
,
uri
)
// 尝试使用提供的密码加载PDF文件
pdfDocument
.
use
{
document
->
// 如果没有抛出异常,说明密码正确
...
...
@@ -156,10 +158,15 @@ object PdfBoxUtils {
}
catch
(
e
:
IOException
)
{
// 其他I/O异常处理
println
(
"An I/O error occurred: "
+
e
.
message
)
}
finally
{
pdfDocument
?.
close
()
}
return
false
}
/**
* 注意一下PDDocument用完都要关闭一下
*/
private
fun
loadPDDocument
(
path
:
String
,
password
:
String
?,
uri
:
String
?
=
null
):
PDDocument
{
return
if
(
uri
==
null
)
{
if
(
password
==
null
)
{
...
...
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