|
Thursday, 31 December 2015
distance between 2 geo codes with square
distance between 2 geo points
|
Wednesday, 16 December 2015
Thursday, 26 November 2015
Example of javascript and CSS
2 Panel Demo
as
|
Demo
Sample Name Sample Addres
|
|
|||||||||||||||||||||||||||||||
Wednesday, 25 November 2015
Convert DOC/DOCX files to HTML
Sample Code to Convert DOC/DOCX files to HTML
Required Jars
-dom4j.jar
-log4j-1.2.15.jar
-ooxml-schemas-1.1.jar
-org.apache.poi.xwpf.converter.core-1.0.0.jar
-org.apache.poi.xwpf.converter.xhtml-1.0.0.jar
-poi-3.9.jar
-poi-ooxml-3.9.jar
-poi-ooxml-schemas-3.9.jar
-poi-scratchpad-3.9.jar
-xdocreport-1.0.4.jar
-xmlbeans-2.5.0.jar
-xmlbeans-xmlpublic-2.4.0.jar
Sample Code import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.converter.WordToHtmlConverter; import org.apache.poi.hwpf.converter.WordToHtmlUtils; import org.apache.poi.xwpf.converter.core.FileURIResolver; import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter; import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.w3c.dom.Document; public class Converter { public static void main(String[] args) { String filePath = "UR_FILE_NAME.doc"; String destinationPath = "DEST_LOCATION"; try{ if(filePath.toLowerCase().endsWith("docx")){ Converter.DocxConverter(filePath, destinationPath); } else{ Converter.DocConverter(filePath, destinationPath); } }catch(Exception e){ System.out.println("Error while converting "+filePath); e.printStackTrace(); } } /** * @param filePath * @param destinationPath * @throws Exception */ public static void DocxConverter(String filePath, String destinationPath) throws Exception{ String htmlFileName = ((new File(filePath)).getName().split("\\.")[0])+".html"; InputStream in= new FileInputStream(new File(filePath)); XWPFDocument document = new XWPFDocument(in); // 2) Prepare XHTML options (here we set the IURIResolver to load images from a "word/media" folder) XHTMLOptions options = XHTMLOptions.create().URIResolver(new FileURIResolver(new File("word/media"))); // 3) Convert XWPFDocument to XHTML OutputStream out = new FileOutputStream(new File(destinationPath+File.separator+htmlFileName)); XHTMLConverter.getInstance().convert(document, out, options); } /** * @param filePath * @param destinationPath * @throws Exception */ public static void DocConverter(String filePath, String destinationPath) throws Exception{ String htmlFileName = ((new File(filePath)).getName().split("\\.")[0])+".html"; HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc(new FileInputStream(filePath)); WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter( DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument()); wordToHtmlConverter.processDocument(wordDocument); Document htmlDocument = wordToHtmlConverter.getDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(htmlDocument); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); String result = new String(out.toByteArray()); result = result.replaceAll("â€", "").replaceAll("ï‚§â€", ""); // System.out.println(result); // File file = new File("F:\\demo.html"); PrintWriter writer = new PrintWriter(destinationPath+File.separator+htmlFileName, "UTF-8"); writer.println(result); writer.close(); } }
Subscribe to:
Posts (Atom)