-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathConvertTests.java
104 lines (87 loc) · 3.83 KB
/
ConvertTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Power by www.xiaoi.com
*/
package com.eastrobot.doc.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;
import java.util.Map;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.document.DefaultDocumentFormatRegistry;
import org.artofsolving.jodconverter.document.DocumentFamily;
import org.artofsolving.jodconverter.document.DocumentFormat;
import org.artofsolving.jodconverter.document.DocumentFormatRegistry;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
import org.junit.Test;
/**
* @author <a href="mailto:eko.z@outlook.com">eko.zhan</a>
* @date 2017年12月6日 下午7:55:08
* @version 1.0
*/
public class ConvertTests extends BaseTests {
@Test
public void testDocToXml(){
File inputFile = new File("E:/converter-html/local/4.25-1.doc");
File outputFile = new File("E:/converter-html/local/4.25-1.doc.xml");
//IOUtils.copy(new FileInputStream(inputFile), new FileOutputStream(outputFile));
convert(inputFile, outputFile);
}
@Test
public void testEncrypt(){
File inputFile = new File("E:/ConvertTester/encrypt/I_am_encrypt.docx");
File outputFile = new File("E:/ConvertTester/encrypt/I_am_encrypt.html");
convert(inputFile, outputFile, "xiaoi");
}
@Test
public void testVisioAsPdf(){
File inputFile = new File("E:/ConvertTester/TestFiles/I_am_a_vsdx.vsdx");
File outputFile = new File("E:/ConvertTester/TestFiles/I_am_a_vsdx_libreoffice.pdf");
convert(inputFile, outputFile);
}
@Test
public void testDocToDocx() throws FileNotFoundException, IOException{
File inputFile = new File("E:/ConvertTester/CeairFile/2015120209414170.doc");
File outputFile = new File("E:/ConvertTester/CeairFile/2015120209414170.docx");
//IOUtils.copy(new FileInputStream(inputFile), new FileOutputStream(outputFile));
convert(inputFile, outputFile);
}
@Test
public void testPptToPdf() throws FileNotFoundException, IOException{
File inputFile = new File("E:/ConvertTester/ppt/1527243826237.ppt");
File outputFile = new File("E:/ConvertTester/ppt/1527243826237.pdf");
convert(inputFile, outputFile);
}
@Test
public void testConvert() throws IOException {
// File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.doc");
File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1512561737109.html");
File outputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/" + Calendar.getInstance().getTimeInMillis() + ".docx");
// if (!outputFile.exists()){
// outputFile.createNewFile();
// }
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
configuration.setPortNumber(8100);
configuration.setOfficeHome(new File("D:/Program Files/LibreOffice"));
OfficeManager officeManager = configuration.buildOfficeManager();
officeManager.start();
DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry);
try {
converter.convert(inputFile, outputFile);
} catch (Exception e){
e.printStackTrace();
} finally {
officeManager.stop();
}
}
@Test
public void testGetFormatByExtension(){
DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
DocumentFormat formatByExtension = formatRegistry.getFormatByExtension("docx");
System.out.println(formatByExtension.getName());
Map<DocumentFamily, Map<String, ?>> storePropertiesByFamily = formatByExtension.getStorePropertiesByFamily();
System.out.println(storePropertiesByFamily.size());
}
}