Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-backend
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AutogeneralShanghai
yd-backend
Commits
d9610587
Commit
d9610587
authored
Apr 21, 2022
by
wenyang
Committed by
akexiu
Apr 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
经纪人名片4.经纪人电子名片由后端返回,支持PDF/png
parent
fed53cc9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
36 deletions
+50
-36
yd-api/src/main/java/com/yd/api/practitioner/service/impl/PractitionerServiceImpl.java
+50
-36
No files found.
yd-api/src/main/java/com/yd/api/practitioner/service/impl/PractitionerServiceImpl.java
View file @
d9610587
...
...
@@ -5194,8 +5194,6 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
String
tmpPathPDF
=
PDFConfiguration
.
getProperty
(
"businessCardE.pdf.temp.path"
);
//PDF模板输出结果文件
String
templateResultPDF
=
tmpPathPDF
+
practitionerId
+
"-businessCardE.pdf"
;
//JPG模板输出结果文件
String
templateResultPNG
=
tmpPathPDF
+
practitionerId
+
"-businessCardE.png"
;
//填充数据
Map
<
String
,
String
>
initDatas
=
new
HashMap
<>();
Map
<
String
,
String
>
initImages
=
new
HashMap
<>();
...
...
@@ -5252,21 +5250,40 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
PDFTemplate
.
generatePDF
(
templatePDF
,
templateResultPDF
,
initDatas
,
initImages
);
try
{
resp
.
setBusinessCardPdfUrl
(
putContractFileToOSS
(
"businessCardEPDF"
,
templateResultPDF
,
practitionerId
));
PDDocument
doc
=
null
;
ByteArrayOutputStream
os
=
null
;
InputStream
stream
=
null
;
OutputStream
out
=
null
;
try
{
// pdf路径
stream
=
new
FileInputStream
(
templateResultPDF
);
// 加载解析PDF文件
doc
=
PDDocument
.
load
(
stream
);
PDFRenderer
pdfRenderer
=
new
PDFRenderer
(
doc
);
PDPageTree
pages
=
doc
.
getPages
();
int
pageCount
=
pages
.
getCount
();
for
(
int
i
=
0
;
i
<
pageCount
;
i
++)
{
BufferedImage
bim
=
pdfRenderer
.
renderImageWithDPI
(
i
,
70
);
ImageIO
.
write
(
bim
,
"png"
,
new
File
(
templateResultPNG
));
// getBusinessCardImg(resp, practitionerId, templateResultPDF, tmpPathPDF);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 把PDF转换为图片
* @param resp
* @param practitionerId
* @param templateResultPDF
* @param tmpPathPDF
* @throws Exception
* @throws IOException
*/
private
void
getBusinessCardImg
(
PractitionerBusinessCardResponseVO
resp
,
Long
practitionerId
,
String
templateResultPDF
,
String
tmpPathPDF
)
throws
Exception
,
IOException
{
//JPG模板输出结果文件
String
templateResultPNG
=
tmpPathPDF
+
practitionerId
+
"-businessCardE.png"
;
PDDocument
doc
=
null
;
ByteArrayOutputStream
os
=
null
;
InputStream
stream
=
null
;
OutputStream
out
=
null
;
try
{
// pdf路径
stream
=
new
FileInputStream
(
templateResultPDF
);
// 加载解析PDF文件
doc
=
PDDocument
.
load
(
stream
);
PDFRenderer
pdfRenderer
=
new
PDFRenderer
(
doc
);
PDPageTree
pages
=
doc
.
getPages
();
int
pageCount
=
pages
.
getCount
();
for
(
int
i
=
0
;
i
<
pageCount
;
i
++)
{
BufferedImage
bim
=
pdfRenderer
.
renderImageWithDPI
(
i
,
70
);
ImageIO
.
write
(
bim
,
"png"
,
new
File
(
templateResultPNG
));
// os = new ByteArrayOutputStream();
// Image image = bim.getScaledInstance(70,45,Image.SCALE_SMOOTH); //设置图像的缩放大小
// AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(1,1),null); //设置图像的缩放比例
...
...
@@ -5282,25 +5299,22 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
// }
// out = new FileOutputStream(file);
// out.write(dataList);
if
(
i
==
0
){
resp
.
setBusinessCardProsImg
(
putContractFileToOSS
(
"businessCardEPros"
,
templateResultPNG
,
practitionerId
));
}
else
if
(
i
==
1
){
resp
.
setBusinessCardConsImg
(
putContractFileToOSS
(
"businessCardECons"
,
templateResultPNG
,
practitionerId
));
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
finally
{
if
(
doc
!=
null
)
doc
.
close
();
if
(
os
!=
null
)
os
.
close
();
if
(
stream
!=
null
)
stream
.
close
();
if
(
out
!=
null
)
out
.
close
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
if
(
i
==
0
){
resp
.
setBusinessCardProsImg
(
putContractFileToOSS
(
"businessCardEPros"
,
templateResultPNG
,
practitionerId
));
}
else
if
(
i
==
1
){
resp
.
setBusinessCardConsImg
(
putContractFileToOSS
(
"businessCardECons"
,
templateResultPNG
,
practitionerId
));
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
finally
{
if
(
doc
!=
null
)
doc
.
close
();
if
(
os
!=
null
)
os
.
close
();
if
(
stream
!=
null
)
stream
.
close
();
if
(
out
!=
null
)
out
.
close
();
}
}
/**
* 经纪人申请开通邮箱
...
...
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