Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
scanqrwhite2copy1
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
scanqrwhite2copy1
Commits
c7d9242b
Commit
c7d9242b
authored
Feb 12, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
595ebc8f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
ExportPdfActivity.kt
...va/com/base/scanqrclear/ui/exportpdf/ExportPdfActivity.kt
+6
-6
ExportPdf.kt
app/src/main/java/com/base/scanqrclear/utils/ExportPdf.kt
+6
-4
No files found.
app/src/main/java/com/base/scanqrclear/ui/exportpdf/ExportPdfActivity.kt
View file @
c7d9242b
...
@@ -95,7 +95,7 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
...
@@ -95,7 +95,7 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
binding
.
tvQr
.
text
=
content
binding
.
tvQr
.
text
=
content
qrStringArray
=
content
.
split
(
"\n"
).
toTypedArray
()
qrStringArray
=
content
.
split
(
"\n"
).
toTypedArray
()
generateQRCode
()
generateQRCode
(
0.4f
,
3.0f
)
}
}
KEY_PRODUCT
->
{
KEY_PRODUCT
->
{
...
@@ -116,12 +116,12 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
...
@@ -116,12 +116,12 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
}
}
fun
generateQRCode
()
{
fun
generateQRCode
(
scale
:
Float
=
0.5f
,
imageYRate
:
Float
=
2f
)
{
Thread
{
Thread
{
val
bitmap
=
generateQRCode
(
qrString
,
735
,
735
,
5
)
val
bitmap
=
generateQRCode
(
qrString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
}
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
}
bitmap
?.
let
{
generatePdfFile
(
it
,
0.5f
,
30f
)
}
bitmap
?.
let
{
generatePdfFile
(
it
,
scale
,
imageYRate
)
}
}.
start
()
}.
start
()
}
}
...
@@ -130,11 +130,11 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
...
@@ -130,11 +130,11 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
val
bitmap
=
QRCodeUtils
.
generateEAN13Barcode
(
qrString
,
648
,
255
)
val
bitmap
=
QRCodeUtils
.
generateEAN13Barcode
(
qrString
,
648
,
255
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
}
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
}
bitmap
?.
let
{
generatePdfFile
(
it
,
0.5f
,
50
f
)
}
bitmap
?.
let
{
generatePdfFile
(
it
,
0.5f
,
2
f
)
}
}.
start
()
}.
start
()
}
}
fun
generatePdfFile
(
bitmap
:
Bitmap
,
scale
:
Float
=
0.5f
,
margin
:
Float
=
50f
)
{
fun
generatePdfFile
(
bitmap
:
Bitmap
,
scale
:
Float
,
imageYRate
:
Float
)
{
val
tempPdf
=
File
(
this
.
cacheDir
,
"${pdfQrName}_${System.currentTimeMillis()}.pdf"
)
val
tempPdf
=
File
(
this
.
cacheDir
,
"${pdfQrName}_${System.currentTimeMillis()}.pdf"
)
this
.
cacheDir
.
mkdirs
()
this
.
cacheDir
.
mkdirs
()
tempPdf
.
createNewFile
()
tempPdf
.
createNewFile
()
...
@@ -146,7 +146,7 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
...
@@ -146,7 +146,7 @@ class ExportPdfActivity : BaseActivity<ActivityExportPdfBinding>(ActivityExportP
true
true
)
)
val
flag
=
generatePdfWithTextAndImage
(
tempPdf
,
scaledBitmap
,
qrType
,
qrStringArray
,
margin
)
val
flag
=
generatePdfWithTextAndImage
(
tempPdf
,
scaledBitmap
,
qrType
,
qrStringArray
,
imageYRate
)
if
(
flag
)
{
if
(
flag
)
{
LogEx
.
logDebug
(
TAG
,
"${tempPdf.absoluteFile}"
)
LogEx
.
logDebug
(
TAG
,
"${tempPdf.absoluteFile}"
)
pdfTempFile
=
tempPdf
pdfTempFile
=
tempPdf
...
...
app/src/main/java/com/base/scanqrclear/utils/ExportPdf.kt
View file @
c7d9242b
...
@@ -15,7 +15,7 @@ object ExportPdf {
...
@@ -15,7 +15,7 @@ object ExportPdf {
bitmap
:
Bitmap
,
bitmap
:
Bitmap
,
qrType
:
String
,
qrType
:
String
,
qrStrings
:
Array
<
String
>,
qrStrings
:
Array
<
String
>,
marginVertical
:
Float
=
50f
imageYRate
:
Float
//图片水平位置比例,2水平居中,小于2偏下,大于2偏上
):
Boolean
{
):
Boolean
{
// A4纸张大小(单位:点,1英寸=72点)
// A4纸张大小(单位:点,1英寸=72点)
val
pageWidth
=
595
val
pageWidth
=
595
...
@@ -31,7 +31,7 @@ object ExportPdf {
...
@@ -31,7 +31,7 @@ object ExportPdf {
// 计算图片的绘制位置(水平和垂直居中)
// 计算图片的绘制位置(水平和垂直居中)
val
imageX
=
(
pageWidth
-
imageWidth
)
/
2f
val
imageX
=
(
pageWidth
-
imageWidth
)
/
2f
val
imageY
=
(
pageHeight
-
imageHeight
)
/
2f
val
imageY
=
(
pageHeight
-
imageHeight
)
/
imageYRate
// 绘制图片
// 绘制图片
canvas
.
drawBitmap
(
bitmap
,
imageX
,
imageY
,
null
)
canvas
.
drawBitmap
(
bitmap
,
imageX
,
imageY
,
null
)
...
@@ -43,13 +43,15 @@ object ExportPdf {
...
@@ -43,13 +43,15 @@ object ExportPdf {
paint
.
textSize
=
25f
// 设置文本大小
paint
.
textSize
=
25f
// 设置文本大小
paint
.
textAlign
=
Paint
.
Align
.
CENTER
// 文本居中对齐
paint
.
textAlign
=
Paint
.
Align
.
CENTER
// 文本居中对齐
//文本距离图片间隔
val
textVerticalMargin
=
30f
// 计算顶部文本的绘制位置
// 计算顶部文本的绘制位置
val
textTopY
=
imageY
-
marginVertical
-
paint
.
descent
()
// 图片上方50点
val
textTopY
=
imageY
-
textVerticalMargin
-
paint
.
descent
()
// 图片上方50点
canvas
.
drawText
(
qrType
,
pageWidth
/
2f
,
textTopY
,
paint
)
canvas
.
drawText
(
qrType
,
pageWidth
/
2f
,
textTopY
,
paint
)
// 计算底部文本的绘制位置
// 计算底部文本的绘制位置
var
currentY
=
imageY
+
imageHeight
+
marginVertical
// 图片下方起始位置
var
currentY
=
imageY
+
imageHeight
+
textVerticalMargin
// 图片下方起始位置
val
lineHeight
=
paint
.
textSize
+
10f
// 行高(文本大小 + 间距)
val
lineHeight
=
paint
.
textSize
+
10f
// 行高(文本大小 + 间距)
// 遍历字符串数组,逐行绘制
// 遍历字符串数组,逐行绘制
...
...
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