|
| 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 | +} |
0 commit comments