Convert Document to Other Formats

Microsoft Word - Conversion to Other Formats

Documents can be converted to other formats using Save As option in the File menu.

Aspose.Words - Conversion to Other Formats

To convert a document to other formats using Aspose.Words, simply invoke the save() method of Document class and specify a file name with the desired and supported extension.

Aspose.Words allows exporting or converting word documents to PDF, XPS, XamlFixed, XamlFlow, XamlFlowPack, EPUB, HTML, HtmlFixed, OpenXPS, PostScript, TXT and popular image/multimedia file formats including TIFF, JPG, PNG, BMP, SVG, SVG and SWF.

The following code example demonstrates how to convert a whole document from DOC to other formats using default options. Java

// The path to the documents directory.
String dataDir = Utils.getDataDir(AsposeConvertToFormats.class);

// Load the document from disk.
Document doc = new Document(dataDir + "document.doc"); + "Aspose_DocToHTML.html",SaveFormat.HTML); //Save the document in HTML format. + "Aspose_DocToPDF.pdf",SaveFormat.PDF); //Save the document in PDF format. + "Aspose_DocToTxt.txt",SaveFormat.TEXT); //Save the document in TXT format. + "Aspose_DocToJPG.jpg",SaveFormat.JPEG); //Save the document in JPEG format.

Apache POI WP - Conversion to Other Formats

The WordToHtmlConverter is used to convert a DOC to HTML format using Apache POI. Apache POI also allows to covert in FO and text format.


// The path to the documents directory.
String dataDir = Utils.getDataDir(ApacheConvertToFormats.class);

HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc(new FileInputStream(dataDir + "document.doc"));

WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
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);

FileOutputStream outputStream = new FileOutputStream(dataDir + "Apache_DocToHTML.html");

Download Running Code

Download Sample Code