Skip to content

Commit 3d4a449

Browse files
committed
new project
1 parent 5c89fa1 commit 3d4a449

12 files changed

Lines changed: 278 additions & 0 deletions

File tree

doctopdf/.classpath

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="output" path="target/classes"/>
26+
</classpath>

doctopdf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

doctopdf/.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>doctopdf</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/test/java=UTF-8
4+
encoding/<project>=UTF-8
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.5
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

doctopdf/hf.fo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><layout-master-set xmlns="http://www.w3.org/1999/XSL/Format"><simple-page-master margin-bottom="0.5in" margin-left="1in" margin-right="1in" margin-top="0.5in" master-name="s1-simple" page-height="11.69in" page-width="8.27in"><region-body margin-bottom="420.0pt" margin-left="0mm" margin-right="0mm" margin-top="420.0pt"/><region-before extent="420.0pt" region-name="xsl-region-before-simple"/><region-after extent="420.0pt" region-name="xsl-region-after-simple"/></simple-page-master><page-sequence-master master-name="s1"><repeatable-page-master-alternatives><conditional-page-master-reference master-reference="s1-simple"/></repeatable-page-master-alternatives></page-sequence-master></layout-master-set><fo:page-sequence id="section_s1" format="" master-reference="s1"><fo:flow flow-name="xsl-region-body">
2+
3+
<fo:block break-before="auto" line-height="115%" space-after="14mm" space-before="14mm"><inline xmlns="http://www.w3.org/1999/XSL/Format" font-size="48.0pt"><inline font-family="Calibri">BODY CONTENT</inline></inline></fo:block>
4+
5+
<fo:block line-height="115%" space-after="14mm" space-before="14mm"><inline xmlns="http://www.w3.org/1999/XSL/Format" font-size="48.0pt"><inline font-family="Calibri">BODY CONTENT</inline></inline></fo:block>
6+
7+
<fo:block line-height="115%" space-after="14mm" space-before="14mm"><inline xmlns="http://www.w3.org/1999/XSL/Format" font-size="48.0pt"><inline font-family="Calibri">BODY CONTENT</inline></inline></fo:block>
8+
9+
<fo:block line-height="115%" space-after="14mm" space-before="14mm"><inline xmlns="http://www.w3.org/1999/XSL/Format" font-size="48.0pt"><inline font-family="Calibri">BODY CONTENT</inline></inline></fo:block>
10+
11+
12+
13+
</fo:flow></fo:page-sequence></fo:root>

doctopdf/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com</groupId>
6+
<artifactId>doctopdf</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>doctopdf</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
19+
<dependency>
20+
<groupId>org.docx4j</groupId>
21+
<artifactId>docx4j</artifactId>
22+
<version>3.2.1</version>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.apache.poi</groupId>
27+
<artifactId>poi</artifactId>
28+
<version>3.12</version>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.apache.poi</groupId>
33+
<artifactId>poi-ooxml</artifactId>
34+
<version>3.12</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>fr.opensagres.xdocreport</groupId>
39+
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
40+
<version>1.0.5</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.apache.poi</groupId>
45+
<artifactId>poi-scratchpad</artifactId>
46+
<version>3.12</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>junit</groupId>
51+
<artifactId>junit</artifactId>
52+
<version>3.8.1</version>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.doctopdf;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.FileOutputStream;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.io.OutputStream;
10+
11+
public class App {
12+
public static void main(String[] args) throws Exception {
13+
14+
String inPath = "C:\\Users\\ankur.singhal\\Desktop\\testing\\Keshav-Resume.docx";
15+
String lowerCaseInPath = inPath.toLowerCase();
16+
17+
InputStream inStream = getInFileStream(inPath);
18+
OutputStream outStream = getOutFileStream("C:\\Users\\ankur.singhal\\Desktop\\testing\\Keshav-Resume.pdf");
19+
20+
if (lowerCaseInPath.endsWith("doc")) {
21+
DocToPDFConverter.DocToPDFConvert(inStream, outStream);
22+
} else if (lowerCaseInPath.endsWith("docx")) {
23+
DocxToPDFConverter.DocxToPDFConvert(inStream, outStream);
24+
}
25+
26+
inStream.close();
27+
outStream.close();
28+
29+
}
30+
31+
private static InputStream getInFileStream(String inputFilePath) throws FileNotFoundException {
32+
File inFile = new File(inputFilePath);
33+
FileInputStream iStream = new FileInputStream(inFile);
34+
return iStream;
35+
}
36+
37+
private static OutputStream getOutFileStream(String outputFilePath) throws IOException {
38+
File outFile = new File(outputFilePath);
39+
40+
try {
41+
// Make all directories up to specified
42+
outFile.getParentFile().mkdirs();
43+
} catch (NullPointerException e) {
44+
// Ignore error since it means not parent directories
45+
}
46+
47+
outFile.createNewFile();
48+
FileOutputStream oStream = new FileOutputStream(outFile);
49+
return oStream;
50+
}
51+
52+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.doctopdf;
2+
3+
import java.io.InputStream;
4+
import java.io.OutputStream;
5+
import java.io.PrintStream;
6+
7+
import org.docx4j.Docx4J;
8+
import org.docx4j.convert.in.Doc;
9+
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
10+
11+
public class DocToPDFConverter {
12+
13+
public static void DocToPDFConvert(InputStream inStream, OutputStream outStream) throws Exception {
14+
15+
InputStream iStream = inStream;
16+
WordprocessingMLPackage wordMLPackage = getMLPackage(iStream);
17+
Docx4J.toPDF(wordMLPackage, outStream);
18+
19+
}
20+
21+
private static WordprocessingMLPackage getMLPackage(InputStream iStream) throws Exception {
22+
PrintStream originalStdout = System.out;
23+
24+
// Disable stdout temporarily as Doc convert produces alot of output
25+
System.setOut(new PrintStream(new OutputStream() {
26+
public void write(int b) {
27+
// DO NOTHING
28+
}
29+
}));
30+
31+
WordprocessingMLPackage mlPackage = Doc.convert(iStream);
32+
33+
System.setOut(originalStdout);
34+
return mlPackage;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)