Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MultipleSourceSecurity
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周宗顺
MultipleSourceSecurity
Commits
f9f6fa73
Commit
f9f6fa73
authored
Nov 18, 2025
by
孙杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目pdf
parent
bb02446d
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1250 additions
and
0 deletions
+1250
-0
pom.xml
PddServer/pom.xml
+67
-0
BarCodeUtils.java
.../main/java/org/ta/pddserver/PDFTemplate/BarCodeUtils.java
+186
-0
FileUtils.java
...src/main/java/org/ta/pddserver/PDFTemplate/FileUtils.java
+229
-0
PdfUtil.java
...r/src/main/java/org/ta/pddserver/PDFTemplate/PdfUtil.java
+273
-0
QRCodeUtils.java
...c/main/java/org/ta/pddserver/PDFTemplate/QRCodeUtils.java
+259
-0
ZipUtil.java
...r/src/main/java/org/ta/pddserver/PDFTemplate/ZipUtil.java
+41
-0
Uploader.java
PddServer/src/main/java/org/ta/pddserver/cos/Uploader.java
+162
-0
PrintOrderInfoTO.java
...main/java/org/ta/pddserver/model/to/PrintOrderInfoTO.java
+27
-0
TimeTool.java
PddServer/src/main/java/org/ta/pddserver/utils/TimeTool.java
+6
-0
FormSale-sample.pdf
PddServer/src/main/resources/pdfs/FormSale-sample.pdf
+0
-0
lotte_T.png
lotte_T.png
+0
-0
lotte_logo.png
lotte_logo.png
+0
-0
No files found.
PddServer/pom.xml
View file @
f9f6fa73
...
@@ -85,6 +85,73 @@
...
@@ -85,6 +85,73 @@
<artifactId>
spring-boot-starter-amqp
</artifactId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
</dependency>
<!--pdf -->
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
<dependency>
<groupId>
com.itextpdf
</groupId>
<artifactId>
itextpdf
</artifactId>
<version>
5.5.13
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf/itext-asian -->
<dependency>
<groupId>
com.itextpdf
</groupId>
<artifactId>
itext-asian
</artifactId>
<version>
5.2.0
</version>
</dependency>
<!--条形码 -->
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
<version>
3.3.3
</version>
</dependency>
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
javase
</artifactId>
<version>
3.3.3
</version>
</dependency>
<dependency>
<groupId>
com.itextpdf
</groupId>
<artifactId>
itextpdf
</artifactId>
<version>
5.5.13
</version>
</dependency>
<dependency>
<groupId>
com.itextpdf
</groupId>
<artifactId>
itext-asian
</artifactId>
<version>
5.2.0
</version>
</dependency>
<!-- 谷歌二维码 -->
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
<version>
3.1.0
</version>
</dependency>
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
javase
</artifactId>
<version>
3.1.0
</version>
</dependency>
<!-- 阿里云上传 -->
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<version>
2.8.3
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.7
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
...
...
PddServer/src/main/java/org/ta/pddserver/PDFTemplate/BarCodeUtils.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
PDFTemplate
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.WriterException
;
import
com.google.zxing.client.j2se.MatrixToImageWriter
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.oned.Code128Writer
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
/**
*
*/
public
class
BarCodeUtils
{
/** 条形码宽度 */
private
static
final
int
WIDTH
=
500
;
/** 条形码高度 */
private
static
final
int
HEIGHT
=
70
;
/** 加文字 条形码 */
private
static
final
int
WORDHEIGHT
=
95
;
/**
* 设置 条形码参数
*/
private
static
Map
<
EncodeHintType
,
Object
>
hints
=
new
HashMap
<
EncodeHintType
,
Object
>()
{
private
static
final
long
serialVersionUID
=
1L
;
{
// 设置编码方式
put
(
EncodeHintType
.
CHARACTER_SET
,
"utf-8"
);
}
};
/**
* 把带logo的二维码下面加上文字
* @author fxbin
* @param image 条形码图片
* @param words 文字
* @return 返回BufferedImage
*/
public
static
BufferedImage
insertWords
(
BufferedImage
image
,
String
words
){
// 新的图片,把带logo的二维码下面加上文字
if
(
StringUtils
.
isNotEmpty
(
words
))
{
BufferedImage
outImage
=
new
BufferedImage
(
WIDTH
,
WORDHEIGHT
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics2D
g2d
=
outImage
.
createGraphics
();
// 抗锯齿
setGraphics2D
(
g2d
);
// 设置白色
setColorWhite
(
g2d
);
// 画条形码到新的面板
g2d
.
drawImage
(
image
,
0
,
0
,
image
.
getWidth
(),
image
.
getHeight
(),
null
);
// 画文字到新的面板
Color
color
=
new
Color
(
0
,
0
,
0
);
g2d
.
setColor
(
color
);
// 字体、字型、字号
g2d
.
setFont
(
new
Font
(
"微软雅黑"
,
Font
.
PLAIN
,
18
));
//文字长度
int
strWidth
=
g2d
.
getFontMetrics
().
stringWidth
(
words
);
//总长度减去文字长度的一半 (居中显示)
int
wordStartX
=(
WIDTH
-
strWidth
)
/
2
;
//height + (outImage.getHeight() - height) / 2 + 12
int
wordStartY
=
HEIGHT
+
20
;
// 画文字
g2d
.
drawString
(
words
,
wordStartX
,
wordStartY
);
g2d
.
dispose
();
outImage
.
flush
();
return
outImage
;
}
return
null
;
}
/**
* 生成 图片缓冲
* @author fxbin
* @param vaNumber VA 码
* @return 返回BufferedImage
*/
public
static
BufferedImage
getBarCode
(
String
vaNumber
){
try
{
Code128Writer
writer
=
new
Code128Writer
();
// 编码内容, 编码类型, 宽度, 高度, 设置参数
BitMatrix
bitMatrix
=
writer
.
encode
(
vaNumber
,
BarcodeFormat
.
CODE_128
,
WIDTH
,
HEIGHT
,
hints
);
return
MatrixToImageWriter
.
toBufferedImage
(
bitMatrix
);
}
catch
(
WriterException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 生成 图片缓冲图片大小自己输入
* @author fxbin
* @param vaNumber VA 码
* @return 返回BufferedImage
*/
public
static
BufferedImage
getBarCode
(
String
vaNumber
,
int
width
,
int
height
){
try
{
Code128Writer
writer
=
new
Code128Writer
();
// 编码内容, 编码类型, 宽度, 高度, 设置参数
BitMatrix
bitMatrix
=
writer
.
encode
(
vaNumber
,
BarcodeFormat
.
CODE_128
,
width
,
height
,
hints
);
return
MatrixToImageWriter
.
toBufferedImage
(
bitMatrix
);
}
catch
(
WriterException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 把带logo的二维码下面加上文字大小自己输入
* @author fxbin
* @param image 条形码图片
* @param words 文字
* @return 返回BufferedImage
*/
public
static
BufferedImage
insertWords
(
BufferedImage
image
,
String
words
,
int
width
,
int
wordheight
,
int
height
){
// 新的图片,把带logo的二维码下面加上文字
if
(
StringUtils
.
isNotEmpty
(
words
))
{
BufferedImage
outImage
=
new
BufferedImage
(
width
,
wordheight
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics2D
g2d
=
outImage
.
createGraphics
();
// 抗锯齿
setGraphics2D
(
g2d
);
// 设置白色
setColorWhite
(
g2d
);
// 画条形码到新的面板
g2d
.
drawImage
(
image
,
0
,
0
,
image
.
getWidth
(),
image
.
getHeight
(),
null
);
// 画文字到新的面板
Color
color
=
new
Color
(
0
,
0
,
0
);
g2d
.
setColor
(
color
);
// 字体、字型、字号
g2d
.
setFont
(
new
Font
(
"微软雅黑"
,
Font
.
PLAIN
,
18
));
//文字长度
int
strWidth
=
g2d
.
getFontMetrics
().
stringWidth
(
words
);
//总长度减去文字长度的一半 (居中显示)
int
wordStartX
=(
width
-
strWidth
)
/
2
;
//height + (outImage.getHeight() - height) / 2 + 12
int
wordStartY
=
height
+
20
;
// 画文字
g2d
.
drawString
(
words
,
wordStartX
,
wordStartY
);
g2d
.
dispose
();
outImage
.
flush
();
return
outImage
;
}
return
null
;
}
/**
* 设置 Graphics2D 属性 (抗锯齿)
* @param g2d Graphics2D提供对几何形状、坐标转换、颜色管理和文本布局更为复杂的控制
*/
private
static
void
setGraphics2D
(
Graphics2D
g2d
){
g2d
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
g2d
.
setRenderingHint
(
RenderingHints
.
KEY_STROKE_CONTROL
,
RenderingHints
.
VALUE_STROKE_DEFAULT
);
Stroke
s
=
new
BasicStroke
(
1
,
BasicStroke
.
CAP_ROUND
,
BasicStroke
.
JOIN_MITER
);
g2d
.
setStroke
(
s
);
}
/**
* 设置背景为白色
* @param g2d Graphics2D提供对几何形状、坐标转换、颜色管理和文本布局更为复杂的控制
*/
private
static
void
setColorWhite
(
Graphics2D
g2d
){
g2d
.
setColor
(
Color
.
WHITE
);
//填充整个屏幕
g2d
.
fillRect
(
0
,
0
,
600
,
600
);
//设置笔刷
g2d
.
setColor
(
Color
.
BLACK
);
}
}
PddServer/src/main/java/org/ta/pddserver/PDFTemplate/FileUtils.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
PDFTemplate
;
import
java.io.*
;
/**
* 文件操作代码
*
* @author cn.outofmemory
* @date 2013-1-7
*/
public
class
FileUtils
{
/**
* 将文本文件中的内容读入到buffer中
* @param buffer buffer
* @param filePath 文件路径
* @throws IOException 异常
* @author cn.outofmemory
* @date 2013-1-7
*/
public
static
void
readToBuffer
(
StringBuffer
buffer
,
String
filePath
)
throws
IOException
{
InputStream
is
=
new
FileInputStream
(
filePath
);
String
line
;
// 用来保存每行读取的内容
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
line
=
reader
.
readLine
();
// 读取第一行
while
(
line
!=
null
)
{
// 如果 line 为空说明读完了
buffer
.
append
(
line
);
// 将读到的内容添加到 buffer 中
buffer
.
append
(
"\n"
);
// 添加换行符
line
=
reader
.
readLine
();
// 读取下一行
}
reader
.
close
();
is
.
close
();
}
/**
* 读取文本文件内容
* @param filePath 文件所在路径
* @return 文本内容
* @throws IOException 异常
* @author cn.outofmemory
* @date 2013-1-7
*/
public
static
String
readFile
(
String
filePath
){
try
{
StringBuffer
sb
=
new
StringBuffer
();
FileUtils
.
readToBuffer
(
sb
,
filePath
);
return
sb
.
toString
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
public
static
long
getFileSize
(
String
filename
)
{
File
file
=
new
File
(
filename
);
if
(!
file
.
exists
()
||
!
file
.
isFile
())
{
System
.
out
.
println
(
"文件不存在"
);
return
-
1
;
}
return
file
.
length
();
}
public
static
long
getFileSize
(
File
file
)
{
if
(!
file
.
exists
()
||
!
file
.
isFile
())
{
System
.
out
.
println
(
"文件不存在"
);
return
-
1
;
}
return
file
.
length
();
}
/*
public static String genChecksum(String file, CheckSumAlgoType checkSumAlgoType) {
*/
/**
* 使用org.apache.commons.codec.digest.DigestUtils
*//*
String checksum = null;
try {
switch (checkSumAlgoType) {
case MD5:
checksum = DigestUtils.md5Hex(new FileInputStream(file));
break;
case SHA_1:
checksum = DigestUtils.sha1Hex(new FileInputStream(file));
break;
case SHA_256:
checksum = DigestUtils.sha256Hex(new FileInputStream(file));
break;
case SHA_512:
checksum = DigestUtils.sha512Hex(new FileInputStream(file));
break;
default:
checksum = DigestUtils.md5Hex(new FileInputStream(file));
}
} catch (Exception e) {
e.printStackTrace();
}
return checksum;
}
public static String genChecksum(File file, CheckSumAlgoType checkSumAlgoType) {
*/
/**
* 使用org.apache.commons.codec.digest.DigestUtils
*//*
String checksum = null;
try {
switch (checkSumAlgoType) {
case MD5:
checksum = DigestUtils.md5Hex(new FileInputStream(file));
break;
case SHA_1:
checksum = DigestUtils.sha1Hex(new FileInputStream(file));
break;
case SHA_256:
checksum = DigestUtils.sha256Hex(new FileInputStream(file));
break;
case SHA_512:
checksum = DigestUtils.sha512Hex(new FileInputStream(file));
break;
default:
checksum = DigestUtils.md5Hex(new FileInputStream(file));
}
} catch (Exception e) {
e.printStackTrace();
}
return checksum;
}
*/
public
static
void
copy
(
String
source
,
String
dest
,
int
bufferSize
)
{
InputStream
in
=
null
;
OutputStream
out
=
null
;
try
{
in
=
new
FileInputStream
(
source
);
out
=
new
FileOutputStream
(
dest
);
byte
[]
buffer
=
new
byte
[
bufferSize
];
int
len
;
while
((
len
=
in
.
read
(
buffer
))
>
0
)
{
out
.
write
(
buffer
,
0
,
len
);
}
in
.
close
();
out
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
boolean
checkDir
(
String
dirName
)
{
try
{
File
dir
=
new
File
(
dirName
);
if
(
dir
.
exists
())
{
System
.
out
.
println
(
"创建目录"
+
dirName
+
"失败,目标目录已经存在"
);
}
else
{
if
(!
dirName
.
endsWith
(
File
.
separator
))
{
dirName
=
dirName
+
File
.
separator
;
}
if
(
dir
.
mkdirs
())
{
System
.
out
.
println
(
"创建目录"
+
dirName
+
"成功!"
);
}
else
{
System
.
out
.
println
(
"创建目录"
+
dirName
+
"失败!"
);
return
false
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
return
true
;
}
//删除文件夹
//param folderPath 文件夹完整绝对路径
public
static
void
delFolder
(
String
folderPath
)
{
try
{
delAllFile
(
folderPath
);
//删除完里面所有内容
String
filePath
=
folderPath
;
filePath
=
filePath
.
toString
();
File
myFilePath
=
new
File
(
filePath
);
myFilePath
.
delete
();
//删除空文件夹
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
//删除指定文件夹下所有文件
//param path 文件夹完整绝对路径
public
static
boolean
delAllFile
(
String
path
)
{
boolean
flag
=
false
;
File
file
=
new
File
(
path
);
if
(!
file
.
exists
())
{
return
flag
;
}
if
(!
file
.
isDirectory
())
{
return
flag
;
}
String
[]
tempList
=
file
.
list
();
File
temp
=
null
;
for
(
int
i
=
0
;
i
<
tempList
.
length
;
i
++)
{
if
(
path
.
endsWith
(
File
.
separator
))
{
temp
=
new
File
(
path
+
tempList
[
i
]);
}
else
{
temp
=
new
File
(
path
+
File
.
separator
+
tempList
[
i
]);
}
if
(
temp
.
isFile
())
{
temp
.
delete
();
}
if
(
temp
.
isDirectory
())
{
delAllFile
(
path
+
"/"
+
tempList
[
i
]);
//先删除文件夹里面的文件
delFolder
(
path
+
"/"
+
tempList
[
i
]);
//再删除空文件夹
flag
=
true
;
}
}
return
flag
;
}
}
\ No newline at end of file
PddServer/src/main/java/org/ta/pddserver/PDFTemplate/PdfUtil.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
PDFTemplate
;
import
com.itextpdf.text.Image
;
import
com.itextpdf.text.Rectangle
;
import
com.itextpdf.text.pdf.*
;
import
jakarta.servlet.ServletOutputStream
;
import
jakarta.servlet.http.HttpServletResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
org.ta.pddserver.cos.Uploader
;
import
org.ta.pddserver.model.to.PrintOrderInfoTO
;
import
org.ta.pddserver.utils.TimeTool
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
ta
.
pddserver
.
PDFTemplate
.
BarCodeUtils
.
getBarCode
;
import
static
org
.
ta
.
pddserver
.
PDFTemplate
.
BarCodeUtils
.
insertWords
;
@Slf4j
public
class
PdfUtil
{
private
static
final
String
SALE_SAMPLE_PDF
=
"./pdfs/FormSale-sample.pdf"
;
private
static
final
String
LOTTE_LOGO
=
"lotte_logo.png"
;
private
static
final
String
LOTTE_T
=
"lotte_T.png"
;
public
String
printSaleInfo
(
PrintOrderInfoTO
formData
,
HttpServletResponse
response
)
throws
Exception
{
String
returnString
=
""
;
try
{
//文件路径
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
//要插入的数据
data
.
put
(
"pageNo"
,
"1/1"
);
data
.
put
(
"feeTag"
,
"배송비고:"
);
data
.
put
(
"goodNameTag"
,
"상품명:"
);
data
.
put
(
"goodName"
,
"E-commerce consuming goods"
);
data
.
put
(
"printTime"
,
new
TimeTool
().
getNowDateString
());
data
.
put
(
"recipient"
,
"받는분: "
+
formData
.
getRecipient
());
data
.
put
(
"detailedAddress"
,
"상품명: "
+
formData
.
getDetailedAddress
());
data
.
put
(
"expressTag"
,
formData
.
getExpressTag
());
data
.
put
(
"expressUid"
,
formData
.
getExpressUid
());
data
.
put
(
"addressUpperLeft"
,
formData
.
getAddressUpperLeft
());
data
.
put
(
"addressUpperRight"
,
formData
.
getAddressUpperRight
());
data
.
put
(
"addressBottomLeft"
,
formData
.
getAddressBottomLeft
());
data
.
put
(
"addressBottomRight"
,
formData
.
getAddressBottomRight
());
data
.
put
(
"expressUidDown"
,
formData
.
getExpressUid
());
data
.
put
(
"orderCore"
,
formData
.
getOrderCore
());
//生成图片
log
.
info
(
"formData.getExpressUid() = "
+
formData
.
getExpressUid
());
//BufferedImage image = insertWords(getBarCode(formData.getExpressUid(), 600, 100), formData.getExpressUid(), 600, 140, 100);
BufferedImage
image
=
getBarCode
(
formData
.
getExpressUid
(),
600
,
100
);
//初始化itext
// 设置编码 todo 此处处理编码问题
// 之前的BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 创建韩文字体
// BaseFont baseFont = BaseFont.createFont("Gothic.ttf",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// BaseFont baseFont = BaseFont.createFont("C:/Windows/Fonts/Malgun Gothic.ttc", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont
baseFont
=
BaseFont
.
createFont
(
"C:/Windows/Fonts/Malgun Gothic.ttf"
,
"UniKSC-UCS2-H"
,
BaseFont
.
NOT_EMBEDDED
);
PdfReader
pdfReader
=
new
PdfReader
(
SALE_SAMPLE_PDF
);
//获取地址
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
PdfStamper
pdfStamper
=
new
PdfStamper
(
pdfReader
,
output
);
AcroFields
form
=
pdfStamper
.
getAcroFields
();
form
.
addSubstitutionFont
(
baseFont
);
//写入数据
for
(
String
key
:
data
.
keySet
())
{
String
value
=
data
.
get
(
key
).
toString
();
//key对应模板数据域的名称
form
.
setField
(
key
,
new
String
(
value
.
getBytes
(
"UTF-8"
),
"UTF-8"
));
}
//添加图片
int
pageNo
=
form
.
getFieldPositions
(
"expressCodeUp"
).
get
(
0
).
page
;
Rectangle
signRect
=
form
.
getFieldPositions
(
"expressCodeUp"
).
get
(
0
).
position
;
float
x
=
signRect
.
getLeft
();
float
y
=
signRect
.
getBottom
();
ByteArrayOutputStream
stream
=
new
ByteArrayOutputStream
();
if
(!
ImageIO
.
write
(
image
,
"jpeg"
,
stream
))
{
return
returnString
;
}
byte
[]
imageBytes
=
stream
.
toByteArray
();
Image
imagePath
=
Image
.
getInstance
(
imageBytes
);
PdfContentByte
under
=
pdfStamper
.
getOverContent
(
pageNo
);
// 设置图片大小
imagePath
.
scaleToFit
(
signRect
.
getWidth
(),
signRect
.
getHeight
());
//设置图片位置
imagePath
.
setAbsolutePosition
(
x
,
y
);
under
.
addImage
(
imagePath
);
//添加图片
int
pageNoMiddle
=
form
.
getFieldPositions
(
"expressCodeMiddle"
).
get
(
0
).
page
;
Rectangle
signRectMiddle
=
form
.
getFieldPositions
(
"expressCodeMiddle"
).
get
(
0
).
position
;
float
xMiddle
=
signRectMiddle
.
getLeft
();
float
yMiddle
=
signRectMiddle
.
getBottom
();
ByteArrayOutputStream
streamMiddle
=
new
ByteArrayOutputStream
();
if
(!
ImageIO
.
write
(
image
,
"jpeg"
,
streamMiddle
))
{
return
returnString
;
}
byte
[]
imageBytesMiddle
=
streamMiddle
.
toByteArray
();
Image
imagePathMiddle
=
Image
.
getInstance
(
imageBytesMiddle
);
PdfContentByte
undeMiddle
=
pdfStamper
.
getOverContent
(
pageNoMiddle
);
// 设置图片大小
imagePathMiddle
.
scaleToFit
(
signRectMiddle
.
getWidth
(),
signRectMiddle
.
getHeight
());
//设置图片位置
imagePathMiddle
.
setAbsolutePosition
(
xMiddle
,
yMiddle
);
undeMiddle
.
addImage
(
imagePathMiddle
);
//添加图片
int
pageNoDown
=
form
.
getFieldPositions
(
"expressCodeDown"
).
get
(
0
).
page
;
Rectangle
signRectDown
=
form
.
getFieldPositions
(
"expressCodeDown"
).
get
(
0
).
position
;
float
xDown
=
signRectDown
.
getLeft
();
float
yDown
=
signRectDown
.
getBottom
();
ByteArrayOutputStream
streamDown
=
new
ByteArrayOutputStream
();
if
(!
ImageIO
.
write
(
image
,
"jpeg"
,
streamDown
))
{
return
returnString
;
}
byte
[]
imageBytesDown
=
streamDown
.
toByteArray
();
Image
imagePathDown
=
Image
.
getInstance
(
imageBytesDown
);
PdfContentByte
undeDown
=
pdfStamper
.
getOverContent
(
pageNoDown
);
// 设置图片大小
imagePathDown
.
scaleToFit
(
signRectDown
.
getWidth
(),
signRectDown
.
getHeight
());
//设置图片位置
imagePathDown
.
setAbsolutePosition
(
xDown
,
yDown
);
undeDown
.
addImage
(
imagePathDown
);
//生成图片
log
.
info
(
"formData.getLandingUid() = "
+
formData
.
getLandingUid
());
// BufferedImage imageLanding = insertWords(getBarCode(formData.getLandingUid(), 600, 100), formData.getLandingUid(), 600, 140, 100);
BufferedImage
imageLanding
=
getBarCode
(
formData
.
getLandingUid
(),
610
,
220
);
//初始化itext
// 设置编码
//BaseFont baseFontLanding = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
PdfReader
pdfReaderLanding
=
new
PdfReader
(
SALE_SAMPLE_PDF
);
//获取地址
ByteArrayOutputStream
outputLanding
=
new
ByteArrayOutputStream
();
PdfStamper
pdfStamperLanding
=
new
PdfStamper
(
pdfReaderLanding
,
outputLanding
);
AcroFields
formLanding
=
pdfStamperLanding
.
getAcroFields
();
formLanding
.
addSubstitutionFont
(
baseFont
);
//写入数据
for
(
String
key
:
data
.
keySet
())
{
String
value
=
data
.
get
(
key
).
toString
();
//key对应模板数据域的名称
formLanding
.
setField
(
key
,
new
String
(
value
.
getBytes
(
"UTF-8"
),
"UTF-8"
));
}
//添加图片
int
pageNoLandingCode
=
formLanding
.
getFieldPositions
(
"landingCode"
).
get
(
0
).
page
;
Rectangle
signRectLandingCode
=
formLanding
.
getFieldPositions
(
"landingCode"
).
get
(
0
).
position
;
float
xLandingCode
=
signRectLandingCode
.
getLeft
();
float
yLandingCode
=
signRectLandingCode
.
getBottom
();
ByteArrayOutputStream
streamLandingCode
=
new
ByteArrayOutputStream
();
if
(!
ImageIO
.
write
(
imageLanding
,
"jpeg"
,
streamLandingCode
))
{
return
returnString
;
}
byte
[]
imageBytesLandingCode
=
streamLandingCode
.
toByteArray
();
Image
imagePathLandingCode
=
Image
.
getInstance
(
imageBytesLandingCode
);
PdfContentByte
underLandingCode
=
pdfStamper
.
getOverContent
(
pageNoLandingCode
);
// 设置图片大小
imagePathLandingCode
.
scaleToFit
(
signRectLandingCode
.
getWidth
(),
signRectLandingCode
.
getHeight
());
//设置图片位置
imagePathLandingCode
.
setAbsolutePosition
(
xLandingCode
,
yLandingCode
);
underLandingCode
.
addImage
(
imagePathLandingCode
);
//添加图片
int
pageNoLogo
=
form
.
getFieldPositions
(
"expressLogo"
).
get
(
0
).
page
;
Rectangle
signRectLogo
=
form
.
getFieldPositions
(
"expressLogo"
).
get
(
0
).
position
;
float
xLogo
=
signRectLogo
.
getLeft
();
float
yLogo
=
signRectLogo
.
getBottom
();
Image
imagePathLogo
=
Image
.
getInstance
(
LOTTE_LOGO
);
//获取地址
PdfContentByte
underLogo
=
pdfStamper
.
getOverContent
(
pageNoLogo
);
// 设置图片大小
imagePathLogo
.
scaleToFit
(
signRectLogo
.
getWidth
(),
signRectLogo
.
getHeight
());
// image.scaleAbsolute(signRect.getWidth(), signRect.getHeight());
//设置图片位置
imagePathLogo
.
setAbsolutePosition
(
xLogo
,
yLogo
);
underLogo
.
addImage
(
imagePathLogo
);
//添加图片
int
pageNoHere
=
form
.
getFieldPositions
(
"pasteHere"
).
get
(
0
).
page
;
Rectangle
signRectHere
=
form
.
getFieldPositions
(
"pasteHere"
).
get
(
0
).
position
;
float
xHere
=
signRectHere
.
getLeft
();
float
yHere
=
signRectHere
.
getBottom
();
Image
imagePathHere
=
Image
.
getInstance
(
LOTTE_T
);
//获取地址
PdfContentByte
underHere
=
pdfStamper
.
getOverContent
(
pageNoHere
);
// 设置图片大小
imagePathHere
.
scaleToFit
(
signRectHere
.
getWidth
(),
signRectHere
.
getHeight
());
// image.scaleAbsolute(signRect.getWidth(), signRect.getHeight());
//设置图片位置
imagePathHere
.
setAbsolutePosition
(
xHere
,
yHere
);
underHere
.
addImage
(
imagePathHere
);
//设置不可编辑
pdfStamper
.
setFormFlattening
(
true
);
pdfStamper
.
close
();
// returnString= Uploader.uploadOssStream(output,System.currentTimeMillis()+"-"+ formData.getOrderCore()+ ".pdf");
this
.
writeSinglePdf
(
"Order"
,
output
,
System
.
currentTimeMillis
()+
"-"
+
formData
.
getOrderCore
(),
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
return
returnString
;
}
}
private
boolean
writeSinglePdf
(
String
name
,
ByteArrayOutputStream
stream
,
String
code
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"APPLICATION/OCTET-STREAM"
);
response
.
setHeader
(
"fileName"
,
name
+
"-"
+
code
+
".pdf"
);
ServletOutputStream
stream1
=
response
.
getOutputStream
();
try
{
byte
[]
buf
=
new
byte
[
1024
];
byte
[]
data
=
stream
.
toByteArray
();
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
data
);
int
len
;
while
((
len
=
in
.
read
(
buf
))
!=
-
1
)
{
stream1
.
write
(
buf
,
0
,
len
);
}
in
.
close
();
response
.
flushBuffer
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
stream1
.
close
();
}
return
false
;
}
/* public static void main1(String[] args) throws Exception {
HttpServletResponse response = null;
PrintOrderInfoTO formData = new PrintOrderInfoTO();
formData.setExpressTag("운송장번호");
formData.setExpressUid("317758904816");
formData.setLandingUid("123456789012");
formData.setAddressUpperLeft("B-26-평64");
formData.setAddressUpperRight("부평(대)");
formData.setAddressBottomLeft("X 부평구 부평5동");
formData.setAddressBottomRight("평64-이구용");
formData.setRecipient("받는분: REN SUPING 010-3619-****21353");
formData.setDetailedAddress("인천광역시 부평구 부평동 126-9 유진마젤란주상복합 오피스텔1205");
formData.setOrderCore("PP25111223915187411540070");
printSaleInfo(formData,response);
}*/
}
PddServer/src/main/java/org/ta/pddserver/PDFTemplate/QRCodeUtils.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
PDFTemplate
;
import
com.google.zxing.*
;
import
com.google.zxing.client.j2se.BufferedImageLuminanceSource
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.common.HybridBinarizer
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.geom.RoundRectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.OutputStream
;
import
java.util.Hashtable
;
import
java.util.Random
;
public
class
QRCodeUtils
{
private
static
final
String
CHARSET
=
"utf-8"
;
private
static
final
String
FORMAT
=
"JPG"
;
// 二维码尺寸
private
static
final
int
QRCODE_SIZE
=
3000
;
// LOGO宽度
private
static
final
int
LOGO_WIDTH
=
600
;
// LOGO高度
private
static
final
int
LOGO_HEIGHT
=
600
;
static
BufferedImage
createImage
(
String
content
,
String
logoPath
,
boolean
needCompress
)
throws
Exception
{
Hashtable
<
EncodeHintType
,
Object
>
hints
=
new
Hashtable
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
ErrorCorrectionLevel
.
H
);
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
CHARSET
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
1
);
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
QRCODE_SIZE
,
QRCODE_SIZE
,
hints
);
int
width
=
bitMatrix
.
getWidth
();
int
height
=
bitMatrix
.
getHeight
();
BufferedImage
image
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
for
(
int
x
=
0
;
x
<
width
;
x
++)
{
for
(
int
y
=
0
;
y
<
height
;
y
++)
{
image
.
setRGB
(
x
,
y
,
bitMatrix
.
get
(
x
,
y
)
?
0xFF000000
:
0xFFFFFFFF
);
}
}
if
(
logoPath
==
null
||
""
.
equals
(
logoPath
))
{
return
image
;
}
// 插入图片
QRCodeUtils
.
insertImage
(
image
,
logoPath
,
needCompress
);
return
image
;
}
/**
* 插入LOGO
*
* @param source 二维码图片
* @param logoPath LOGO图片地址
* @param needCompress 是否压缩
* @throws Exception
*/
private
static
void
insertImage
(
BufferedImage
source
,
String
logoPath
,
boolean
needCompress
)
throws
Exception
{
File
file
=
new
File
(
logoPath
);
if
(!
file
.
exists
())
{
throw
new
Exception
(
"logo file not found."
);
}
Image
src
=
ImageIO
.
read
(
new
File
(
logoPath
));
int
width
=
src
.
getWidth
(
null
);
int
height
=
src
.
getHeight
(
null
);
if
(
needCompress
)
{
// 压缩LOGO
if
(
width
>
LOGO_WIDTH
)
{
width
=
LOGO_WIDTH
;
}
if
(
height
>
LOGO_HEIGHT
)
{
height
=
LOGO_HEIGHT
;
}
Image
image
=
src
.
getScaledInstance
(
width
,
height
,
Image
.
SCALE_SMOOTH
);
BufferedImage
tag
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics
g
=
tag
.
getGraphics
();
g
.
drawImage
(
image
,
0
,
0
,
null
);
// 绘制缩小后的图
g
.
dispose
();
src
=
image
;
}
// 插入LOGO
Graphics2D
graph
=
source
.
createGraphics
();
int
x
=
(
QRCODE_SIZE
-
width
)
/
2
;
int
y
=
(
QRCODE_SIZE
-
height
)
/
2
;
graph
.
drawImage
(
src
,
x
,
y
,
width
,
height
,
null
);
Shape
shape
=
new
RoundRectangle2D
.
Float
(
x
,
y
,
width
,
width
,
6
,
6
);
graph
.
setStroke
(
new
BasicStroke
(
3
f
));
graph
.
draw
(
shape
);
graph
.
dispose
();
}
/**
* 生成二维码(内嵌LOGO)
* 二维码文件名随机,文件名可能会有重复
*
* @param content 内容
* @param logoPath LOGO地址
* @param destPath 存放目录
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
String
encode
(
String
content
,
String
logoPath
,
String
destPath
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtils
.
createImage
(
content
,
logoPath
,
needCompress
);
mkdirs
(
destPath
);
String
fileName
=
new
Random
().
nextInt
(
99999999
)
+
"."
+
FORMAT
.
toLowerCase
();
ImageIO
.
write
(
image
,
FORMAT
,
new
File
(
destPath
+
"/"
+
fileName
));
return
fileName
;
}
/**
* 生成二维码(内嵌LOGO)
* 调用者指定二维码文件名
*
* @param content 内容
* @param logoPath LOGO地址
* @param destPath 存放目录
* @param fileName 二维码文件名
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
String
encode
(
String
content
,
String
logoPath
,
String
destPath
,
String
fileName
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtils
.
createImage
(
content
,
logoPath
,
needCompress
);
mkdirs
(
destPath
);
fileName
=
fileName
.
substring
(
0
,
fileName
.
indexOf
(
"."
)
>
0
?
fileName
.
indexOf
(
"."
)
:
fileName
.
length
())
+
"."
+
FORMAT
.
toLowerCase
();
ImageIO
.
write
(
image
,
FORMAT
,
new
File
(
destPath
+
"/"
+
fileName
));
return
fileName
;
}
/**
* 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.
* (mkdir如果父目录不存在则会抛出异常)
*
* @param destPath 存放目录
*/
public
static
void
mkdirs
(
String
destPath
)
{
File
file
=
new
File
(
destPath
);
if
(!
file
.
exists
()
&&
!
file
.
isDirectory
())
{
file
.
mkdirs
();
}
}
/**
* 生成二维码(内嵌LOGO)
*
* @param content 内容
* @param logoPath LOGO地址
* @param destPath 存储地址
* @throws Exception
*/
public
static
String
encode
(
String
content
,
String
logoPath
,
String
destPath
)
throws
Exception
{
return
QRCodeUtils
.
encode
(
content
,
logoPath
,
destPath
,
false
);
}
/**
* 生成二维码
*
* @param content 内容
* @param destPath 存储地址
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
String
encode
(
String
content
,
String
destPath
,
boolean
needCompress
)
throws
Exception
{
return
QRCodeUtils
.
encode
(
content
,
null
,
destPath
,
needCompress
);
}
/**
* 生成二维码
*
* @param content 内容
* @param destPath 存储地址
* @throws Exception
*/
public
static
String
encode
(
String
content
,
String
destPath
)
throws
Exception
{
return
QRCodeUtils
.
encode
(
content
,
null
,
destPath
,
false
);
}
/**
* 生成二维码(内嵌LOGO)
*
* @param content 内容
* @param logoPath LOGO地址
* @param output 输出流
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
void
encode
(
String
content
,
String
logoPath
,
OutputStream
output
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtils
.
createImage
(
content
,
logoPath
,
needCompress
);
ImageIO
.
write
(
image
,
FORMAT
,
output
);
}
/**
* 生成二维码
*
* @param content 内容
* @param output 输出流
* @throws Exception
*/
public
static
void
encode
(
String
content
,
OutputStream
output
)
throws
Exception
{
QRCodeUtils
.
encode
(
content
,
null
,
output
,
false
);
}
/**
* 解析二维码
*
* @param file 二维码图片
* @return
* @throws Exception
*/
public
static
String
decode
(
File
file
)
throws
Exception
{
BufferedImage
image
;
image
=
ImageIO
.
read
(
file
);
if
(
image
==
null
)
{
return
null
;
}
BufferedImageLuminanceSource
source
=
new
BufferedImageLuminanceSource
(
image
);
BinaryBitmap
bitmap
=
new
BinaryBitmap
(
new
HybridBinarizer
(
source
));
Result
result
;
Hashtable
<
DecodeHintType
,
Object
>
hints
=
new
Hashtable
<
DecodeHintType
,
Object
>();
hints
.
put
(
DecodeHintType
.
CHARACTER_SET
,
CHARSET
);
result
=
new
MultiFormatReader
().
decode
(
bitmap
,
hints
);
String
resultStr
=
result
.
getText
();
return
resultStr
;
}
/**
* 解析二维码
*
* @param path 二维码图片地址
* @return
* @throws Exception
*/
public
static
String
decode
(
String
path
)
throws
Exception
{
return
QRCodeUtils
.
decode
(
new
File
(
path
));
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
text
=
"http://www.baidu.com"
;
//不含Logo
// QRCodeUtils.encode(text, null, "e:\\", true);
String
tex1
=
"www.baidu.com"
;
//不含Logo
QRCodeUtils
.
encode
(
tex1
,
null
,
"e:\\"
,
true
);
//含Logo,不指定二维码图片名
//QRCodeUtils.encode(text, "E:\\666.jpg", "E:\\", true);
//含Logo,指定二维码图片名
//QRCodeUtils.encode(text, "E:\\logo.png", "E:\\", "qrcode1", true);
//String decode = QRCodeUtil.decode("e:\\qrcode.jpg");
//System.out.println(decode);
}
}
PddServer/src/main/java/org/ta/pddserver/PDFTemplate/ZipUtil.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
PDFTemplate
;
import
jakarta.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
public
class
ZipUtil
{
public
boolean
makeZip
(
String
pdfName
,
Map
<
String
,
ByteArrayOutputStream
>
outMap
,
String
name
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"APPLICATION/OCTET-STREAM"
);
response
.
setHeader
(
"fileName"
,
name
);
ZipOutputStream
out
=
new
ZipOutputStream
(
response
.
getOutputStream
());
try
{
byte
[]
buf
=
new
byte
[
1024
];
for
(
String
key
:
outMap
.
keySet
())
{
out
.
putNextEntry
(
new
ZipEntry
(
pdfName
+
"-"
+
key
+
".pdf"
));
byte
[]
data
=
outMap
.
get
(
key
).
toByteArray
();
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
data
);
int
len
;
while
((
len
=
in
.
read
(
buf
))
!=
-
1
)
{
out
.
write
(
buf
,
0
,
len
);
}
out
.
closeEntry
();
in
.
close
();
response
.
flushBuffer
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
out
.
close
();
}
return
false
;
}
}
PddServer/src/main/java/org/ta/pddserver/cos/Uploader.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
cos
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClient
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.UUID
;
public
class
Uploader
{
private
static
final
String
OSS_END_POINT
=
"oss-cn-qingdao.aliyuncs.com"
;
private
static
final
String
OSS_ACCESS_KEY_ID
=
"LTAI5t8BWUq8KYFPaE6qoAt6"
;
private
static
final
String
OSS_ACCESS_KEY_SECRET
=
"WxtupLLdjZLPBwtJ8SL91W5IYVGBdF"
;
private
static
final
String
OSS_BUCKET_NAME
=
"tradeany-server"
;
public
String
uploadOssFile
(
MultipartFile
file
)
{
String
endpoint
=
OSS_END_POINT
;
String
accessKeyId
=
OSS_ACCESS_KEY_ID
;
String
accessKeySecret
=
OSS_ACCESS_KEY_SECRET
;
String
bucketName
=
OSS_BUCKET_NAME
;
String
url
=
null
;
try
{
//创建OSSClient实例。
OSS
ossClient
=
new
OSSClient
(
endpoint
,
accessKeyId
,
accessKeySecret
);
//获取上传文件输入流
InputStream
inputStream
=
file
.
getInputStream
();
//获取文件名称
String
fileName
=
file
.
getOriginalFilename
();
//保证文件名唯一,去掉uuid中的'-'
String
uuid
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
fileName
=
uuid
+
fileName
;
//把文件按日期分类,构建日期路径:avatar/2019/02/26/文件名
//String datePath = new Date().toString("yyyy/MM/dd");
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
time
=
formatter
.
format
(
new
Date
());
String
eName
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
//拼接
fileName
=
"files/"
+
time
+
"/"
+
uuid
+
eName
;
//调用oss方法上传到阿里云
//第一个参数:Bucket名称
//第二个参数:上传到oss文件路径和文件名称
//第三个参数:上传文件输入流
ossClient
.
putObject
(
bucketName
,
fileName
,
inputStream
);
//把上传后把文件url返回
//https://xppll.oss-cn-beijing.aliyuncs.com/01.jpg
url
=
"https://images.v2.tradeany.com/"
+
fileName
;
System
.
out
.
println
(
"file:"
+
url
);
//关闭OSSClient
ossClient
.
shutdown
();
return
url
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
url
;
}
public
static
String
uploadOssInputStream
(
InputStream
inputStream
,
String
fileName
)
{
String
endpoint
=
OSS_END_POINT
;
String
accessKeyId
=
OSS_ACCESS_KEY_ID
;
String
accessKeySecret
=
OSS_ACCESS_KEY_SECRET
;
String
bucketName
=
OSS_BUCKET_NAME
;
String
url
=
null
;
try
{
//创建OSSClient实例。
OSS
ossClient
=
new
OSSClient
(
endpoint
,
accessKeyId
,
accessKeySecret
);
//保证文件名唯一,去掉uuid中的'-'
String
uuid
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
fileName
=
uuid
+
fileName
;
//把文件按日期分类,构建日期路径:avatar/2019/02/26/文件名
//String datePath = new Date().toString("yyyy/MM/dd");
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
time
=
formatter
.
format
(
new
Date
());
String
eName
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
//拼接
fileName
=
"files/"
+
time
+
"/"
+
uuid
+
eName
;
//调用oss方法上传到阿里云
//第一个参数:Bucket名称
//第二个参数:上传到oss文件路径和文件名称
//第三个参数:上传文件输入流
ossClient
.
putObject
(
bucketName
,
fileName
,
inputStream
);
//把上传后把文件url返回
//https://xppll.oss-cn-beijing.aliyuncs.com/01.jpg
url
=
"https://images.v2.tradeany.com/"
+
fileName
;
System
.
out
.
println
(
"file:"
+
url
);
//关闭OSSClient
ossClient
.
shutdown
();
return
url
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
url
;
}
/**
* 上传到阿里云
*
* @param stream 文件内容
* @param filename 带路径文件名 postFiles/111.abc
* @return 链接
*/
public
static
String
uploadOssStream
(
ByteArrayOutputStream
stream
,
String
filename
)
{
String
endpoint
=
OSS_END_POINT
;
String
accessKeyId
=
OSS_ACCESS_KEY_ID
;
String
accessKeySecret
=
OSS_ACCESS_KEY_SECRET
;
String
bucketName
=
OSS_BUCKET_NAME
;
String
url
=
null
;
try
{
//创建OSSClient实例。
OSS
ossClient
=
new
OSSClient
(
endpoint
,
accessKeyId
,
accessKeySecret
);
//保证文件名唯一,去掉uuid中的'-'
String
uuid
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
filename
=
"pdfFiles/"
+
uuid
+
filename
;
//获取上传文件输入流
ByteArrayInputStream
inputStream
=
null
;
try
{
byte
[]
data
=
stream
.
toByteArray
();
inputStream
=
new
ByteArrayInputStream
(
data
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//调用oss方法上传到阿里云
//第一个参数:Bucket名称
//第二个参数:上传到oss文件路径和文件名称
//第三个参数:上传文件输入流
ossClient
.
putObject
(
bucketName
,
filename
,
inputStream
);
//把上传后把文件url返回
//https://xppll.oss-cn-beijing.aliyuncs.com/01.jpg
url
=
"https://images.v2.tradeany.com/"
+
filename
;
System
.
out
.
println
(
"file:"
+
url
);
//关闭OSSClient
ossClient
.
shutdown
();
return
url
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
url
;
}
}
PddServer/src/main/java/org/ta/pddserver/model/to/PrintOrderInfoTO.java
0 → 100644
View file @
f9f6fa73
package
org
.
ta
.
pddserver
.
model
.
to
;
import
lombok.Data
;
@Data
public
class
PrintOrderInfoTO
{
private
String
uid
;
private
String
expressTag
;
private
String
expressUid
;
private
String
landingUid
;
private
String
addressUpperLeft
;
private
String
addressUpperRight
;
private
String
addressBottomLeft
;
private
String
addressBottomRight
;
private
String
recipient
;
private
String
detailedAddress
;
private
String
orderCore
;
//暂时不用
private
String
pageNo
;
private
String
feeTag
;
private
String
goodNameTag
;
private
String
goodName
;
private
String
printTime
;
}
PddServer/src/main/java/org/ta/pddserver/utils/TimeTool.java
View file @
f9f6fa73
...
@@ -20,4 +20,10 @@ public class TimeTool {
...
@@ -20,4 +20,10 @@ public class TimeTool {
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
sdf
.
format
(
date
);
return
sdf
.
format
(
date
);
}
}
public
String
getNowDateString
()
{
Date
date
=
new
Date
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy.MM.dd"
);
return
sdf
.
format
(
date
);
}
}
}
\ No newline at end of file
PddServer/src/main/resources/pdfs/FormSale-sample.pdf
0 → 100644
View file @
f9f6fa73
File added
lotte_T.png
0 → 100644
View file @
f9f6fa73
1.16 KB
lotte_logo.png
0 → 100644
View file @
f9f6fa73
4.97 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