-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoDOCX.java
More file actions
36 lines (32 loc) · 1.02 KB
/
toDOCX.java
File metadata and controls
36 lines (32 loc) · 1.02 KB
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
import java.io.File;
import java.io.FileOutputStream;
import java.util.Scanner;
import com.itextpdf.text.Paragraph;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class toDOCX {
public static Boolean convertDOCX(File file,String address)throws Exception {
Boolean written=false;
//Blank Document
XWPFDocument document = new XWPFDocument();
//Path of docx file to be created if not existing already
FileOutputStream out = new FileOutputStream( new File(address+"/License.docx"));
XWPFParagraph paragraph;
XWPFRun run;
//Write the Document in file system
Scanner readobj = new Scanner(file);
//Loop until we find the EOF
while (readobj.hasNextLine()){
paragraph = document.createParagraph();
run= paragraph.createRun();
String dataInfo = readobj.nextLine();
run.setText(dataInfo+"\n");
written=true;
}
document.write(out);
out.close();
readobj.close();
return written?true:false;
}
}