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
c30c7593
Commit
c30c7593
authored
Sep 20, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
ec932d27
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
575 additions
and
110 deletions
+575
-110
build.gradle.kts
app/build.gradle.kts
+12
-7
PdfActivity.kt
...base/pdfviewerscannerwhite/ui/document/pdf/PdfActivity.kt
+354
-6
PdfLoadingActivity.kt
...fviewerscannerwhite/ui/document/pdf/PdfLoadingActivity.kt
+40
-16
PdfPagerAdapter.kt
.../pdfviewerscannerwhite/ui/document/pdf/PdfPagerAdapter.kt
+0
-1
PdfPresenter.kt
...ase/pdfviewerscannerwhite/ui/document/pdf/PdfPresenter.kt
+50
-12
libmupdf_java.so
app/src/main/jniLibs/arm64-v8a/libmupdf_java.so
+0
-0
libmupdf_java.so
app/src/main/jniLibs/armeabi-v7a/libmupdf_java.so
+0
-0
libmupdf_java.so
app/src/main/jniLibs/mips/libmupdf_java.so
+0
-0
libmupdf_java.so
app/src/main/jniLibs/x86/libmupdf_java.so
+0
-0
libmupdf_java.so
app/src/main/jniLibs/x86_64/libmupdf_java.so
+0
-0
activity_pdf.xml
app/src/main/res/layout/activity_pdf.xml
+43
-5
activity_pdf_loading.xml
app/src/main/res/layout/activity_pdf_loading.xml
+0
-1
build.gradle
pdflibrary/build.gradle
+14
-3
MuPDFCore.java
...ibrary/src/main/java/com/artifex/mupdfdemo/MuPDFCore.java
+17
-9
ReaderView.java
...brary/src/main/java/com/artifex/mupdfdemo/ReaderView.java
+26
-15
SavePdf.java
pdflibrary/src/main/java/com/artifex/mupdfdemo/SavePdf.java
+19
-35
libmupdf_java.so
pdflibrary/src/main/jniLibs/arm64-v8a/libmupdf_java.so
+0
-0
libmupdf_java.so
pdflibrary/src/main/jniLibs/armeabi-v7a/libmupdf_java.so
+0
-0
libmupdf_java.so
pdflibrary/src/main/jniLibs/mips/libmupdf_java.so
+0
-0
libmupdf_java.so
pdflibrary/src/main/jniLibs/x86/libmupdf_java.so
+0
-0
libmupdf_java.so
pdflibrary/src/main/jniLibs/x86_64/libmupdf_java.so
+0
-0
No files found.
app/build.gradle.kts
View file @
c30c7593
...
...
@@ -15,6 +15,16 @@ android {
versionName
=
"1.0"
testInstrumentationRunner
=
"androidx.test.runner.AndroidJUnitRunner"
// ndk {
// abiFilters.add("arm64-v8a")
// // 取消注释以下行以添加更多 ABI 支持
// abiFilters.add("armeabi-v7a")
// }
// sourceSets {
// getByName("main") {
// jniLibs.srcDirs("src/main/jniLibs")
// }
// }
}
buildTypes
{
...
...
@@ -34,13 +44,8 @@ android {
viewBinding
=
true
buildConfig
=
true
}
sourceSets
{
getByName
(
"main"
)
{
assets
{
srcDirs
(
"src\\main\\assets"
,
"src\\main\\assets"
)
}
}
}
}
dependencies
{
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfActivity.kt
View file @
c30c7593
This diff is collapsed.
Click to expand it.
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfLoadingActivity.kt
View file @
c30c7593
...
...
@@ -2,21 +2,21 @@ package com.base.pdfviewerscannerwhite.ui.document.pdf
import
android.content.Intent
import
androidx.lifecycle.lifecycleScope
import
com.artifex.mupdfdemo.MuPDFCore
import
com.base.pdfviewerscannerwhite.databinding.ActivityPdfLoadingBinding
import
com.base.pdfviewerscannerwhite.helper.BaseActivity
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
java.io.File
import
kotlin.random.Random
class
PdfLoadingActivity
:
BaseActivity
<
ActivityPdfLoadingBinding
>()
{
private
val
TAG
=
"PdfLoadingActivity"
private
var
doWhat
=
""
private
var
srcPath
:
String
=
""
private
var
new
Name
:
String
=
""
private
var
new
Path
:
String
=
""
private
var
splitIndex
:
List
<
Int
>
=
listOf
()
private
lateinit
var
pdfPresenter
:
PdfPresenter
...
...
@@ -24,16 +24,36 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
ActivityPdfLoadingBinding
.
inflate
(
layoutInflater
)
}
var
isFinishBoolean
:
Boolean
=
false
var
newPdfFile
:
File
?
=
null
private
var
isFinishBoolean
:
Boolean
=
false
private
var
progressFinishAction
:
(()
->
Unit
)?
=
null
override
fun
initView
()
{
pdfPresenter
=
PdfPresenter
(
this
)
initSpPa
()
pdfPresenter
.
splitPdf
(
File
(
srcPath
),
newName
,
splitIndex
,
finishAction
=
{
newPdfFile
=
it
when
(
doWhat
)
{
DO_SPLIT_PDF
->
{
progressFinishAction
=
{
finish
()
}
pdfPresenter
.
splitPdf
(
srcPath
,
newPath
,
splitIndex
,
finishAction
=
{
isFinishBoolean
=
true
})
}
DO_SAVE_PDF
->
{
muPDFCore
?.
save
()
muPDFCore
=
null
progressFinishAction
=
{
finish
()
}
lifecycleScope
.
launch
{
delay
(
Random
.
nextLong
(
1500
,
2500
))
isFinishBoolean
=
true
}
}
}
startProgress
()
}
...
...
@@ -49,18 +69,22 @@ class PdfLoadingActivity : BaseActivity<ActivityPdfLoadingBinding>() {
}
delay
(
500
)
}
if
(
newPdfFile
==
null
)
{
toast
(
"split pdf failed!"
)
finish
()
return
@launch
}
progressFinishAction
?.
invoke
()
}
private
fun
initSpPa
()
{
doWhat
=
intent
?.
extras
?.
getString
(
"doWhat"
,
""
)
?:
""
srcPath
=
intent
?.
extras
?.
getString
(
"srcPath"
,
""
)
?:
""
new
Name
=
intent
?.
extras
?.
getString
(
"newName
"
,
""
)
?:
""
new
Path
=
intent
?.
extras
?.
getString
(
"newPath
"
,
""
)
?:
""
splitIndex
=
intent
.
extras
?.
getString
(
"splitIndex"
)
?.
split
(
","
)
?.
map
{
it
.
toInt
()
}
?:
listOf
()
}
companion
object
{
var
muPDFCore
:
MuPDFCore
?
=
null
const
val
DO_SPLIT_PDF
=
"do_split_pdf"
const
val
DO_SAVE_PDF
=
"do_save_pdf"
}
}
\ No newline at end of file
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfPagerAdapter.kt
View file @
c30c7593
...
...
@@ -88,7 +88,6 @@ class PdfPagerAdapter(val pdfPath: String, val itemLayout: Int = R.layout.item_p
runCatching
{
val
drawable
=
PdfBoxUtils
.
getPdfDrawablePage
(
context
,
pdfPath
,
item
.
pageIndex
,
scale
)
item
.
pageDrawable
=
drawable
// 任务代码
itemView
.
post
{
item
.
pageDrawable
?.
let
{
iv
.
setImageDrawable
(
it
)
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfPresenter.kt
View file @
c30c7593
package
com.base.pdfviewerscannerwhite.ui.document.pdf
import
android.content.Context
import
android.os.Handler
import
android.util.Log
import
com.artifex.mupdfdemo.MuPDFCore
import
com.artifex.mupdfdemo.OutlineActivityData
import
com.base.pdfviewerscannerwhite.bean.PdfPageBean
...
...
@@ -15,14 +13,12 @@ class PdfPresenter(
val
context
:
Context
,
val
pdfView
:
PdfView
?
=
null
)
{
var
handler
:
Handler
?
=
null
private
val
TAG
=
"PdfPresenter"
fun
openFile
(
path
:
String
):
MuPDFCore
?
{
va
l
muPDFCore
:
MuPDFCore
?
=
null
va
r
muPDFCore
:
MuPDFCore
?
=
null
try
{
MuPDFCore
(
context
,
path
)
muPDFCore
=
MuPDFCore
(
context
,
path
)
// 新建:删除旧的目录数据
OutlineActivityData
.
set
(
null
)
}
catch
(
e
:
java
.
lang
.
Exception
)
{
...
...
@@ -44,13 +40,13 @@ class PdfPresenter(
}
fun
splitPdf
(
file
:
File
,
newName
:
String
,
splitIndex
:
List
<
Int
>,
srcPath
:
String
,
newPath
:
String
,
splitIndex
:
List
<
Int
>,
finishAction
:
(
newFile
:
File
?)
->
Unit
)
=
Thread
{
val
newFile
=
File
(
file
.
parentFile
,
newName
)
try
{
// 加载现有 PDF 文档
val
sourceDocument
=
PDDocument
.
load
(
file
)
val
sourceDocument
=
PDDocument
.
load
(
File
(
srcPath
)
)
// 创建新的 PDF 文档
val
newDocument
=
PDDocument
()
...
...
@@ -61,7 +57,7 @@ class PdfPresenter(
newDocument
.
addPage
(
page
)
}
// 保存新的 PDF 文档
newDocument
.
save
(
new
File
)
newDocument
.
save
(
new
Path
)
newDocument
.
close
()
sourceDocument
.
close
()
}
catch
(
e
:
Exception
)
{
...
...
@@ -69,6 +65,48 @@ class PdfPresenter(
finishAction
.
invoke
(
null
)
return
@Thread
}
finishAction
.
invoke
(
newFile
)
finishAction
.
invoke
(
File
(
newPath
)
)
}.
start
()
fun
createNewPath
(
path
:
String
):
String
{
val
file
=
File
(
path
)
var
newName
=
file
.
name
.
split
(
"."
)[
0
]
//aaaa_1.pdf
if
(
isUnderscoreNumberSuffix
(
newName
))
{
val
nameSplit
=
newName
.
split
(
"_"
)
val
number
=
nameSplit
[
1
].
toInt
()
+
1
newName
=
"${nameSplit[0]}_$number"
}
else
{
newName
=
"${newName}_1"
}
val
newFile
=
File
(
file
.
parentFile
,
"$newName.pdf"
)
if
(!
newFile
.
exists
())
{
newFile
.
createNewFile
()
}
return
newFile
.
absolutePath
}
private
fun
isUnderscoreNumberSuffix
(
input
:
String
):
Boolean
{
val
pattern
=
"_\\d+$"
.
toRegex
()
return
pattern
.
matches
(
input
)
}
fun
savePdf
(
context
:
Context
,
muPDFCore
:
MuPDFCore
?,
srcPath
:
String
,
newPath
:
String
)
{
//保存的逻辑,
// 1.原本的文件拷贝一份
// 2。然后保存修改到原本的文件,重名命名该文件为新文件
// 3.拷贝的文件在恢复原位置
val
tempFile
=
File
(
context
.
filesDir
,
"temp.pdf"
)
if
(!
tempFile
.
exists
())
{
tempFile
.
createNewFile
()
}
File
(
srcPath
).
compareTo
(
tempFile
)
muPDFCore
?.
save
()
val
newFile
=
File
(
newPath
)
}
}
\ No newline at end of file
app/src/main/jniLibs/arm64-v8a/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
app/src/main/jniLibs/armeabi-v7a/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
app/src/main/jniLibs/mips/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
app/src/main/jniLibs/x86/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
app/src/main/jniLibs/x86_64/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
app/src/main/res/layout/activity_pdf.xml
View file @
c30c7593
...
...
@@ -7,10 +7,11 @@
android:layout_height=
"match_parent"
tools:context=
".ui.document.pdf.PdfActivity"
>
<!-- <com.artifex.mupdfdemo.MuPDFReaderView-->
<!-- android:id="@+id/mupdf_reader_view"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent" />-->
<com.artifex.mupdfdemo.MuPDFReaderView
android:id=
"@+id/mupdf_reader_view"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
<ViewAnimator
android:id=
"@+id/v_animator_top"
...
...
@@ -134,7 +135,7 @@
android:textSize=
"16sp"
android:visibility=
"gone"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraint
Start_toStartOf=
"@+id/iv_xuanzhuan
"
app:layout_constraint
End_toEndOf=
"@+id/iv_more
"
app:layout_constraintTop_toTopOf=
"parent"
tools:ignore=
"HardcodedText"
/>
...
...
@@ -142,10 +143,27 @@
</ViewAnimator>
<TextView
android:id=
"@+id/tv_pageCount"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"28dp"
android:layout_marginTop=
"28dp"
android:background=
"@drawable/bg_54585b_5"
android:includeFontPadding=
"false"
android:paddingHorizontal=
"2dp"
android:paddingVertical=
"2dp"
android:textColor=
"@color/white"
android:textSize=
"12sp"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/v_animator_top"
tools:text=
"1/3"
/>
<ViewAnimator
android:id=
"@+id/v_animator_bottom"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_alignParentBottom=
"true"
android:background=
"@color/white"
app:layout_constraintBottom_toBottomOf=
"parent"
>
...
...
@@ -160,14 +178,17 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@color/white"
android:paddingVertical=
"8dp"
android:visibility=
"gone"
app:layout_constraintBottom_toTopOf=
"@id/v_animator_bottom"
>
<LinearLayout
android:id=
"@+id/ll_highlight"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:background=
"?android:attr/selectableItemBackground"
android:orientation=
"vertical"
app:layout_constraintEnd_toStartOf=
"@id/ll_glide_line"
app:layout_constraintStart_toStartOf=
"parent"
...
...
@@ -194,8 +215,10 @@
<LinearLayout
android:id=
"@+id/ll_glide_line"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:background=
"?android:attr/selectableItemBackground"
android:orientation=
"vertical"
app:layout_constraintEnd_toStartOf=
"@id/ll_strikethrough"
app:layout_constraintStart_toEndOf=
"@id/ll_highlight"
...
...
@@ -222,8 +245,10 @@
<LinearLayout
android:id=
"@+id/ll_strikethrough"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:background=
"?android:attr/selectableItemBackground"
android:orientation=
"vertical"
app:layout_constraintEnd_toStartOf=
"@id/ll_painting_brush"
app:layout_constraintStart_toEndOf=
"@id/ll_glide_line"
...
...
@@ -252,6 +277,7 @@
android:id=
"@+id/ll_painting_brush"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:background=
"?android:attr/selectableItemBackground"
android:orientation=
"vertical"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@id/ll_strikethrough"
...
...
@@ -294,4 +320,16 @@
</ViewAnimator>
<ImageView
android:id=
"@+id/iv_bianji"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"15dp"
android:layout_marginBottom=
"108dp"
android:src=
"@mipmap/bianji"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
tools:ignore=
"ContentDescription"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/activity_pdf_loading.xml
View file @
c30c7593
...
...
@@ -40,7 +40,6 @@
android:layout_marginHorizontal=
"56dp"
android:layout_marginTop=
"19dp"
android:max=
"100"
android:progress=
"50"
android:progressDrawable=
"@drawable/progress_bg"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
...
...
pdflibrary/build.gradle
View file @
c30c7593
...
...
@@ -4,11 +4,23 @@ plugins {
id
'org.jetbrains.kotlin.android'
}
android
{
compileSdkVersion
28
namespace
"com.lonelypluto.pdfviewerlibrary"
compileSdk
34
defaultConfig
{
minSdkVersion
17
minSdk
24
targetSdk
34
ndk
{
abiFilters
"arm64-v8a"
// "armeabi-v7a"
}
sourceSets
{
main
{
jniLibs
.
srcDirs
=
[
'src/main/jniLibs'
]
}
}
}
buildTypes
{
...
...
@@ -25,6 +37,5 @@ android {
dependencies
{
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
// implementation 'com.android.support:appcompat-v7:28.0.0'
implementation
(
libs
.
androidx
.
appcompat
)
}
\ No newline at end of file
pdflibrary/src/main/java/com/artifex/mupdfdemo/MuPDFCore.java
View file @
c30c7593
...
...
@@ -4,7 +4,9 @@ import android.content.Context;
import
android.graphics.Bitmap
;
import
android.graphics.PointF
;
import
android.graphics.RectF
;
import
java.util.ArrayList
;
import
com.lonelypluto.pdfviewerlibrary.R
;
public
class
MuPDFCore
{
...
...
@@ -12,10 +14,12 @@ public class MuPDFCore {
private
static
boolean
gs_so_available
=
false
;
static
{
try
{
System
.
out
.
println
(
"Loading dll"
);
System
.
loadLibrary
(
"mupdf_java"
);
System
.
out
.
println
(
"Loaded dll"
);
if
(
gprfSupportedInternal
())
{
Boolean
flag
=
gprfSupportedInternal
();
if
(
flag
)
{
try
{
System
.
loadLibrary
(
"gs"
);
gs_so_available
=
true
;
...
...
@@ -23,6 +27,10 @@ public class MuPDFCore {
gs_so_available
=
false
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/* Readable members */
...
...
pdflibrary/src/main/java/com/artifex/mupdfdemo/ReaderView.java
View file @
c30c7593
...
...
@@ -14,9 +14,7 @@ import android.view.View;
import
android.widget.Adapter
;
import
android.widget.AdapterView
;
import
android.widget.Scroller
;
import
com.lonelypluto.pdfviewerlibrary.R
;
import
java.util.LinkedList
;
import
java.util.NoSuchElementException
;
...
...
@@ -108,6 +106,7 @@ public class ReaderView
}
public
void
setDisplayedViewIndex
(
int
i
)
{
if
(
mAdapter
!=
null
)
{
if
(
0
<=
i
&&
i
<
mAdapter
.
getCount
())
{
onMoveOffChild
(
mCurrent
);
mCurrent
=
i
;
...
...
@@ -116,6 +115,7 @@ public class ReaderView
requestLayout
();
}
}
}
/**
* 设置横向或竖向滑动
...
...
@@ -590,7 +590,9 @@ public class ReaderView
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
);
try
{
if
(
mAdapter
!=
null
)
{
onLayout2
(
changed
,
left
,
top
,
right
,
bottom
);
}
}
catch
(
OutOfMemoryError
e
)
{
System
.
out
.
println
(
"Out of memory during layout"
);
...
...
@@ -625,6 +627,7 @@ public class ReaderView
return
;
View
cv
=
mChildViews
.
get
(
mCurrent
);
Point
cvOffset
;
if
(!
mResetLayout
)
{
...
...
@@ -828,11 +831,13 @@ public class ReaderView
private
View
getOrCreateChild
(
int
i
)
{
View
v
=
mChildViews
.
get
(
i
);
if
(
v
==
null
)
{
if
(
mAdapter
!=
null
)
{
v
=
mAdapter
.
getView
(
i
,
getCached
(),
this
);
addAndMeasureChild
(
i
,
v
);
onChildSetup
(
i
,
v
);
onScaleChild
(
v
,
mScale
);
}
}
return
v
;
}
...
...
@@ -922,8 +927,14 @@ public class ReaderView
}
private
Point
subScreenSizeOffset
(
View
v
)
{
return
new
Point
(
Math
.
max
((
getWidth
()
-
v
.
getMeasuredWidth
())
/
2
,
0
),
Math
.
max
((
getHeight
()
-
v
.
getMeasuredHeight
())
/
2
,
0
));
int
mw
=
0
;
int
mh
=
0
;
if
(
v
!=
null
)
{
mw
=
v
.
getMeasuredWidth
();
mh
=
v
.
getMeasuredHeight
();
}
return
new
Point
(
Math
.
max
((
getWidth
()
-
mw
)
/
2
,
0
),
Math
.
max
((
getHeight
()
-
mh
)
/
2
,
0
));
}
private
static
int
directionOfTravel
(
float
vx
,
float
vy
)
{
...
...
pdflibrary/src/main/java/com/artifex/mupdfdemo/SavePdf.java
View file @
c30c7593
...
...
@@ -23,6 +23,7 @@ import java.net.MalformedURLException;
public
class
SavePdf
{
private
float
defaultScale
=
0.90756303f
;
public
void
setWidthScale
(
float
widthScale
)
{
this
.
widthScale
=
widthScale
;
}
...
...
@@ -45,6 +46,7 @@ public class SavePdf {
/**
* 设置放大比例
*
* @param scale
*/
public
void
setScale
(
float
scale
)
{
...
...
@@ -53,6 +55,7 @@ public class SavePdf {
/**
* 设置宽高
*
* @param
*/
public
void
setWH
(
float
width
,
float
height
)
{
...
...
@@ -98,43 +101,24 @@ public class SavePdf {
public
void
addText
()
{
try
{
PdfReader
reader
=
new
PdfReader
(
inPath
,
"PDF"
.
getBytes
());
///打开要写入的PDF
Log
.
e
(
"addText"
,
"1"
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
outPath
);
//设置涂鸦后的PDF
Log
.
e
(
"addText"
,
"2"
);
PdfStamper
stamp
;
stamp
=
new
PdfStamper
(
reader
,
outputStream
);
Log
.
e
(
"addText"
,
"3 "
+
pageNum
);
PdfContentByte
over
=
stamp
.
getOverContent
(
pageNum
);
//////用于设置在第几页打印签名
Log
.
e
(
"addText"
,
"4"
);
if
(
bitmap
!=
null
)
{
byte
[]
bytes
=
Bitmap2Bytes
(
bitmap
);
Image
img
=
Image
.
getInstance
(
bytes
);
//将要放到PDF的图片传过来,要设置为byte[]类型
com
.
lowagie
.
text
.
Rectangle
rectangle
=
reader
.
getPageSize
(
pageNum
);
img
.
setAlignment
(
Image
.
MIDDLE
);
// 图像在文档中的对齐方式
//这里是重点!!!!!设置Image图片大小,需要根据屏幕的分辨率,签名时PDF的放大比例来计算;还有就是当PDF开始显示的时候,他已经做了一次缩放,可以用 rectangle.getWidth() / (bitmap.getWidth() / 2)求得那个放大比
// img.scaleAbsolute(363 * 1.0f * density / 2 / scale * rectangle.getWidth() / (bitmap.getWidth() / 2), 557 * 1.0f * density / 2 / scale * rectangle.getWidth() / (bitmap.getWidth() / 2));
// img.scaleAbsolute(594 * 1.0f * density / 2 / scale * rectangle.getWidth() / (bitmap.getWidth() / 2), 557 * 1.0f * density / 2 / scale * rectangle.getWidth() / (bitmap.getWidth() / 2));
// img.scaleAbsolute(602 * 1.0f * density / 2 / scale * rectangle.getWidth() / (bitmap.getWidth() / 2), 870 * 1.0f * density / 2 / scale * rectangle.getWidth() / (bitmap.getWidth() / 2));
//这里设置image相对PDF左下角的偏移量,我的做法是得到放大后位置相对于整个PDF的百分比再乘PDF的大小得到他的相对偏移位置
// img.setAbsolutePosition(rectangle.getWidth() * widthScale, rectangle.getHeight() * heightScale);// 偏右上
Log
.
e
(
"zyw"
,
"position = "
+
rectangle
.
getWidth
()
*
widthScale
+
" "
+
rectangle
.
getHeight
()
*
heightScale
);
Log
.
e
(
"zyw"
,
"density = "
+
density
);
Log
.
e
(
"zyw"
,
"img.getWidth() = "
+
img
.
getWidth
()
+
" img.getHeight() = "
+
img
.
getHeight
());
Log
.
e
(
"zyw"
,
"scale = "
+
scale
);
Log
.
e
(
"zyw"
,
"widthScale = "
+
widthScale
+
" heightScale = "
+
heightScale
);
Log
.
e
(
"zyw"
,
"bitmap.w = "
+
bitmap
.
getWidth
()
+
" bitmap.h = "
+
bitmap
.
getHeight
());
Log
.
e
(
"zyw"
,
"rectangle.getLeft = "
+
rectangle
.
getLeft
()
+
" rectangle.getBottom() = "
+
rectangle
.
getBottom
());
Log
.
e
(
"zyw"
,
"rectangle.getWidth = "
+
rectangle
.
getWidth
()
+
" rectangle.getHeight = "
+
rectangle
.
getHeight
());
Log
.
e
(
"zyw"
,
"比例1 = "
+
((
float
)
rectangle
.
getWidth
()/
img
.
getWidth
())*
100
);
Log
.
e
(
"zyw"
,
"比例2 = "
+
rectangle
.
getWidth
()
*
widthScale
*
100
);
Log
.
e
(
"zyw"
,
"坐标AbsolutePosition = "
+
width
*
(
rectangle
.
getWidth
()
*
widthScale
)
+
" "
+
(
1964
-
height
-
img
.
getHeight
())
*
(
rectangle
.
getWidth
()
*
widthScale
));
Log
.
e
(
"zyw"
,
"差值 = "
+
rectangle
.
getHeight
()
*
(
heightScale
-
widthScale
));
// img.scalePercent(((float)594/1080)*100);
Log
.
e
(
"zyw"
,
"缩放比例 = "
+
scale
/
defaultScale
);
img
.
scalePercent
(
rectangle
.
getWidth
()
*
widthScale
*
100
);
// img.setAbsolutePosition(rectangle.getLeft(), rectangle.getBottom() - 120);
img
.
setAbsolutePosition
(
width
*
(
rectangle
.
getWidth
()
*
widthScale
)
*
(
scale
),
rectangle
.
getHeight
()
-
((
height
)
*
(
rectangle
.
getWidth
()
*
widthScale
)
*
(
scale
/
defaultScale
))
+
img
.
getHeight
()/
2
*
widthScale
*
100
);
// img.setAbsolutePosition(rectangle.getLeft() + percent/2, rectangle.getBottom() - percent/2);// 偏左下
img
.
scalePercent
(
rectangle
.
getWidth
()
*
widthScale
*
100
);
img
.
setAbsolutePosition
(
width
*
(
rectangle
.
getWidth
()
*
widthScale
)
*
(
scale
),
rectangle
.
getHeight
()
-
((
height
)
*
(
rectangle
.
getWidth
()
*
widthScale
)
*
(
scale
/
defaultScale
))
+
img
.
getHeight
()
/
2
*
widthScale
*
100
);
over
.
addImage
(
img
);
}
Log
.
e
(
"addText"
,
"5"
);
stamp
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
...
...
pdflibrary/src/main/jniLibs/arm64-v8a/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
pdflibrary/src/main/jniLibs/armeabi-v7a/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
pdflibrary/src/main/jniLibs/mips/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
pdflibrary/src/main/jniLibs/x86/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
pdflibrary/src/main/jniLibs/x86_64/libmupdf_java.so
0 → 100644
View file @
c30c7593
File added
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