Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
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
poc
poc-api
Commits
bd82d679
Commit
bd82d679
authored
Jun 26, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
广新配置
parent
4d197a7d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
109 deletions
+118
-109
FileUtils.java
src/main/java/cn/com/poc/common/utils/FileUtils.java
+25
-28
jdbc-gxsit.properties
src/main/resources/framemax-config/jdbc-gxsit.properties
+12
-0
FileUtilsTest.java
src/test/java/cn/com/poc/utils/FileUtilsTest.java
+81
-81
No files found.
src/main/java/cn/com/poc/common/utils/FileUtils.java
View file @
bd82d679
package
cn
.
com
.
poc
.
common
.
utils
;
import
cn.com.yict.framemax.core.exception.BusinessException
;
import
com.aspose.words.SaveFormat
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.Date
;
...
...
@@ -73,29 +70,29 @@ public class FileUtils {
return
null
;
}
/**
* word转pdf文件转换工具
*
* @param docFile doc文件 / docx文件
* @return
*/
public
static
File
wordConvertPDF
(
File
docFile
)
{
try
{
FileInputStream
fileInputStream
=
new
FileInputStream
(
docFile
);
com
.
aspose
.
words
.
Document
doc
=
new
com
.
aspose
.
words
.
Document
(
fileInputStream
);
File
tempFile
=
File
.
createTempFile
(
UUID
.
randomUUID
().
toString
(),
".pdf"
);
FileOutputStream
os
=
new
FileOutputStream
(
tempFile
);
doc
.
save
(
os
,
SaveFormat
.
PDF
);
os
.
close
();
fileInputStream
.
close
();
return
tempFile
;
}
catch
(
IOException
e
)
{
logger
.
error
(
"doc2pdf error:"
+
e
.
getMessage
());
throw
new
BusinessException
(
"文件加载失败"
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"doc2pdf error:"
+
e
.
getMessage
());
throw
new
BusinessException
(
"文件解析失败"
);
}
}
//
/**
//
* word转pdf文件转换工具
//
*
//
* @param docFile doc文件 / docx文件
//
* @return
//
*/
//
public static File wordConvertPDF(File docFile) {
//
try {
//
FileInputStream fileInputStream = new FileInputStream(docFile);
//
com.aspose.words.Document doc = new com.aspose.words.Document(fileInputStream);
//
File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".pdf");
//
FileOutputStream os = new FileOutputStream(tempFile);
//
doc.save(os, SaveFormat.PDF);
//
//
os.close();
//
fileInputStream.close();
//
return tempFile;
//
} catch (IOException e) {
//
logger.error("doc2pdf error:" + e.getMessage());
//
throw new BusinessException("文件加载失败");
//
} catch (Exception e) {
//
logger.error("doc2pdf error:" + e.getMessage());
//
throw new BusinessException("文件解析失败");
//
}
//
}
}
src/main/resources/framemax-config/jdbc-gxsit.properties
0 → 100644
View file @
bd82d679
######mysql数据配置示例#######
hibernate.dialect
=
org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.show_sql
=
true
hibernate.format_sql
=
true
jdbc.driver
=
com.mysql.jdbc.Driver
jdbc.url
=
jdbc:mysql://192.168.21.31:3306/gsst_modellink_sit?useSSL=false&useUnicode=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8
jdbc.username
=
modellink_root
jdbc.password
=
56a6a2854424
ds.maxActive
=
20
ds.minIdle
=
1
ds.initialSize
=
1
ds.validationQuery
=
select 1 from dual
\ No newline at end of file
src/test/java/cn/com/poc/utils/FileUtilsTest.java
View file @
bd82d679
package
cn
.
com
.
poc
.
utils
;
import
cn.com.poc.common.utils.DocumentLoad
;
import
cn.com.poc.common.utils.FileUtils
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
com.aspose.words.Document
;
import
com.aspose.words.HtmlSaveOptions
;
import
com.aspose.words.HtmlVersion
;
import
com.aspose.words.SaveFormat
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.text.PDFTextStripper
;
import
org.junit.runner.RunWith
;
import
org.junit.Test
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
java.io.*
;
/**
* @author alex.yao
* @date 2025/6/12
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
initializers
=
SingleContextInitializer
.
class
)
@WebAppConfiguration
public
class
FileUtilsTest
{
@Test
public
void
test_wordConvertPDF
()
throws
Exception
{
String
filePath
=
""
;
File
file
=
FileUtils
.
wordConvertPDF
(
new
File
(
filePath
));
System
.
out
.
println
(
DocumentLoad
.
loadPDF
(
file
));
}
@Test
public
void
test_word2html
()
throws
Exception
{
String
filePath
=
"C:\\Users\\52747\\Desktop\\test_motionDetailExport.docx"
;
String
dataDir
=
"C:\\Users\\52747\\Desktop\\"
;
Document
doc
=
new
Document
(
filePath
);
HtmlSaveOptions
opts
=
new
HtmlSaveOptions
(
SaveFormat
.
HTML
);
opts
.
setHtmlVersion
(
HtmlVersion
.
HTML_5
);
opts
.
setExportImagesAsBase64
(
true
);
opts
.
setExportPageMargins
(
true
);
doc
.
save
(
dataDir
+
"TestFile.html"
,
opts
);
}
@Test
public
void
test_pdf2word
()
{
try
{
String
pdfFile
=
"C:\\Users\\52747\\Documents\\dataset\\EMSD_Regulatory_Services_Handbook_LPG16.pdf"
;
String
wordFile
=
"C:\\Users\\52747\\Documents\\dataset\\EMSD_Regulatory_Services_Handbook_LPG16.doc"
;
// 加载PDF文档
PDDocument
pdfDoc
=
PDDocument
.
load
(
new
File
(
pdfFile
));
int
totalPages
=
pdfDoc
.
getNumberOfPages
();
// 使用追加模式打开Word文件
try
(
Writer
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
wordFile
,
true
),
"UTF-8"
))
{
PDFTextStripper
stripper
=
new
PDFTextStripper
();
stripper
.
setSortByPosition
(
true
);
for
(
int
i
=
1
;
i
<=
totalPages
;
i
++)
{
stripper
.
setStartPage
(
i
);
stripper
.
setEndPage
(
i
);
String
pageText
=
stripper
.
getText
(
pdfDoc
);
// 追加当前页内容
writer
.
write
(
pageText
);
writer
.
write
(
"\f"
);
}
}
pdfDoc
.
close
();
System
.
out
.
println
(
"总计追加 "
+
totalPages
+
" 页到现有文件"
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"转换失败:"
+
e
.
getMessage
());
e
.
printStackTrace
();
}
}
}
//
package cn.com.poc.utils;
//
//
import cn.com.poc.common.utils.DocumentLoad;
//
import cn.com.poc.common.utils.FileUtils;
//
import cn.com.yict.framemax.core.spring.SingleContextInitializer;
//
import com.aspose.words.Document;
//
import com.aspose.words.HtmlSaveOptions;
//
import com.aspose.words.HtmlVersion;
//
import com.aspose.words.SaveFormat;
//
import org.apache.pdfbox.pdmodel.PDDocument;
//
import org.apache.pdfbox.text.PDFTextStripper;
//
import org.junit.runner.RunWith;
//
import org.junit.Test;
//
import org.springframework.test.context.ContextConfiguration;
//
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//
import org.springframework.test.context.web.WebAppConfiguration;
//
//
import java.io.*;
//
/
//
**
//
* @author alex.yao
//
* @date 2025/6/12
//
*/
//
@RunWith(SpringJUnit4ClassRunner.class)
//
@ContextConfiguration(initializers = SingleContextInitializer.class)
//
@WebAppConfiguration
//
public class FileUtilsTest {
//
//
//
@Test
//
public void test_wordConvertPDF() throws Exception {
//
String filePath = "";
//
File file = FileUtils.wordConvertPDF(new File(filePath));
//
System.out.println(DocumentLoad.loadPDF(file));
//
}
//
//
@Test
//
public void test_word2html() throws Exception {
//
String filePath = "C:\\Users\\52747\\Desktop\\test_motionDetailExport.docx";
//
String dataDir = "C:\\Users\\52747\\Desktop\\";
//
Document doc = new Document(filePath);
//
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.HTML);
//
opts.setHtmlVersion(HtmlVersion.HTML_5);
//
opts.setExportImagesAsBase64(true);
//
opts.setExportPageMargins(true);
//
doc.save(dataDir + "TestFile.html", opts);
//
}
//
//
@Test
//
public void test_pdf2word() {
//
try {
//
String pdfFile = "C:\\Users\\52747\\Documents\\dataset\\EMSD_Regulatory_Services_Handbook_LPG16.pdf";
//
String wordFile = "C:\\Users\\52747\\Documents\\dataset\\EMSD_Regulatory_Services_Handbook_LPG16.doc";
//
//
// 加载PDF文档
//
PDDocument pdfDoc = PDDocument.load(new File(pdfFile));
//
int totalPages = pdfDoc.getNumberOfPages();
//
//
// 使用追加模式打开Word文件
//
try (Writer writer = new OutputStreamWriter(new FileOutputStream(wordFile, true), "UTF-8")) {
//
PDFTextStripper stripper = new PDFTextStripper();
//
stripper.setSortByPosition(true);
//
for (int i = 1; i <= totalPages; i++) {
//
stripper.setStartPage(i);
//
stripper.setEndPage(i);
//
String pageText = stripper.getText(pdfDoc);
//
//
// 追加当前页内容
//
writer.write(pageText);
//
writer.write("\f");
//
}
//
}
//
pdfDoc.close();
//
System.out.println("总计追加 " + totalPages + " 页到现有文件");
//
} catch (IOException e) {
//
System.err.println("转换失败:" + e.getMessage());
//
e.printStackTrace();
//
}
//
}
//
//
}
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