Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
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
fangxinjiang
yifu-mvp
Commits
7badd3a1
Commit
7badd3a1
authored
May 29, 2025
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MVP1.7.11-是否自动生成解除劳动合同书 0否1是
parent
6a7130f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
12 deletions
+39
-12
pom.xml
yifu-social/yifu-social-biz/pom.xml
+6
-0
WordToImageUtil.java
.../yifu/cloud/plus/v1/yifu/social/util/WordToImageUtil.java
+33
-12
No files found.
yifu-social/yifu-social-biz/pom.xml
View file @
7badd3a1
...
...
@@ -121,6 +121,12 @@
<version>
2.0.27
</version>
</dependency>
<dependency>
<groupId>
com.itextpdf
</groupId>
<artifactId>
itextpdf
</artifactId>
<version>
5.5.13.3
</version>
</dependency>
</dependencies>
<build>
...
...
yifu-social/yifu-social-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/social/util/WordToImageUtil.java
View file @
7badd3a1
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
social
.
util
;
import
com.itextpdf.text.pdf.PdfWriter
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.social.config.SocialFriendConfig
;
...
...
@@ -15,13 +16,11 @@ import org.jodconverter.local.office.LocalOfficeManager;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.PostConstruct
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.*
;
import
java.nio.file.DirectoryNotEmptyException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
...
...
@@ -105,10 +104,14 @@ public class WordToImageUtil {
return
"-"
;
}
// 在生产环境中,建议在整个应用生命周期中共享一个OfficeManager:
public
OfficeManager
officeManager
;
public
void
initOfficeManager
()
{
this
.
officeManager
=
LocalOfficeManager
.
builder
()
/*private static OfficeManager officeManager;
@PostConstruct
public void init() {
String tempDir = System.getProperty("java.io.tmpdir");
String officeHome = tempDir + "officeManager";
officeManager = LocalOfficeManager.builder()
.officeHome(officeHome)
.portNumbers(2003)
.build();
try {
...
...
@@ -116,7 +119,8 @@ public class WordToImageUtil {
} catch (OfficeException e) {
e.printStackTrace();
}
}
}*/
public
String
convertAndAddSeal
(
String
inputDocx
,
InputStream
sealImagePath
,
String
outputImagePath
,
String
projectRoot
,
RestTemplate
restTemplate
,
SocialFriendConfig
socialFriendConfig
,
TSocialFriendBackLog
backLog
)
throws
IOException
,
OfficeException
{
...
...
@@ -124,9 +128,8 @@ public class WordToImageUtil {
File
pdfFile
=
null
;
File
imgFile
=
null
;
try
{
initOfficeManager
();
// Step 1: Word 转为 PDF(中间格式)
pdfFile
=
new
File
(
inputDocx
.
replace
(
".docx"
,
".pdf"
));
/*
pdfFile = new File(inputDocx.replace(".docx", ".pdf"));
Map<String, Object> pdfProps = new HashMap<>();
pdfProps.put("FilterName", "writer_pdf_Export");
pdfProps.put("SelectPdfVersion", 1); // PDF/A-1
...
...
@@ -136,7 +139,9 @@ public class WordToImageUtil {
.build()
.convert(new File(inputDocx))
.to(pdfFile)
.
execute
();
.execute();*/
convertDocxToPdf
(
inputDocx
,
PDF_TEMP
);
// Step 2: PDF 转为 PNG 图片(可使用 Apache PDFBox 或 ImageMagick 转换)
BufferedImage
pageImage
=
convertPdfToImage
(
pdfFile
.
getAbsolutePath
());
...
...
@@ -172,6 +177,22 @@ public class WordToImageUtil {
return
"---"
;
}
public
void
convertDocxToPdf
(
String
inputPath
,
String
outputPath
)
throws
Exception
{
FileInputStream
fis
=
new
FileInputStream
(
inputPath
);
XWPFDocument
document
=
new
XWPFDocument
(
fis
);
com
.
itextpdf
.
text
.
Document
pdfDoc
=
new
com
.
itextpdf
.
text
.
Document
();
PdfWriter
.
getInstance
(
pdfDoc
,
new
FileOutputStream
(
outputPath
));
pdfDoc
.
open
();
for
(
XWPFParagraph
para
:
document
.
getParagraphs
())
{
pdfDoc
.
add
(
new
com
.
itextpdf
.
text
.
Paragraph
(
para
.
getText
()));
}
pdfDoc
.
close
();
document
.
close
();
}
private
File
compressImage
(
String
projectRoot
,
File
originalFile
)
throws
IOException
{
BufferedImage
image
=
ImageIO
.
read
(
originalFile
);
int
quality
=
100
;
// 从100%开始
...
...
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