C # convert Word to multiple formats (convert Word to XPS/SVG/EMF/EPUB/TIFF ),

Source: Internet
Author: User

C # convert Word to multiple formats (convert Word to XPS/SVG/EMF/EPUB/TIFF ),

A tool with powerful document conversion functions, wherever and whenever it is necessary in a modern office environment. In this article, we will continue to introduce the Word document Conversion Function (Word to XPS/SVG/EMF/EPUB/TIFF). We hope that the code in the method can provide some reference value for developers.

PS: For more information about Word conversion, see the two articles.

  • Convert Word to HTML/XML/PDF/IMAGE
  • Convert Word to TXT

Tools used:Free Spire. Doc for. NET

Usage:DownloadAfter installing the control, add the reference Spire. Doc. dll file in the VS console application (the dll file can be obtained in the Bin of the installation folder)

1. Word To XPS
Using Spire. doc; using System; namespace WordtoXPS_Doc {class Program {static void Main (string [] args) {// initialize the String class, the element is the word document to be converted String file = "sample.docx "; // create a Document object, load the sample file Document doc = new Document (file); // Save the Word file as XPS, and run the generated Document doc. saveToFile ("Word2XPS. xps ", FileFormat. XPS); System. diagnostics. process. start ("Word2XPS. xps ");}}}

Debug and run the project generation documents, such:

2. Word Transfer SVG
Using Spire. doc; namespace WordtoSVG_Doc {class Program {static void Main (string [] args) {// instantiate the Document class and load Word sample Document doc = new Document (); doc. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ sample.docx"); // save as svg doc. saveToFile ("result. svg ", FileFormat. SVG );}}}

3. Word Transfer Emf
Using Spire. doc; using System. drawing; using System. drawing. imaging; namespace WordtoEmf_Doc {class Program {static void Main (string [] args) {// instantiate a Document class and load Word sample Document doc = new Document (); doc. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ sample.docx", FileFormat. docx); // call the method SaveToImages () to convert the first page of Word to image and save it as System in Emf format. drawing. image image = doc. saveToImages (0, Spire. doc. documents. imageType. metafile); image. save ("WordtoEmf. emf ", ImageFormat. emf );}}}

4. Word Transfer Epub
Using Spire. doc; namespace WordtoEPUB {class Epub {static void Main (string [] args) {// instantiate the Document class and load Word sample Document document = new Document (); document. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ sample.docx"); // save the file as Epub and run the generated document. saveToFile ("ToEpub. epub ", FileFormat. EPub); System. diagnostics. process. start ("ToEpub. epub ");}}}

5. Word Transfer Word XML
Using Spire. doc; namespace WordtoWordXML_Doc {class Program {static void Main (string [] args) {// create a Document class object and load Word sample Document doc = new Document (); doc. loadFromFile ("sample.docx"); // call the SaveToFile () method to save Word as Word Xml doc. saveToFile ("WordToWordXML. xml ", FileFormat. wordXml );}}}

6. Word Transfer Tiff
Using Spire. doc; using Spire. doc. documents; using System. drawing; using System. drawing. imaging; namespace convert_word_to_tiff {class Program {static void Main (string [] args) {// instantiate a Document class and load Word sample Document document = new Document (@ "C: \ Users \ Administrator \ Desktop \ sample.docx "); // call join1_images () to save Word as tiff, and run the generated document join1_images (SaveAsImage (document)," result. tiff ", EncoderValue. compressionLZW); System. diagnostics. process. start ("result. tiff ");} // custom method SaveAsImage () Save the Word Document as an Image private static Image [] SaveAsImage (document) {Image [] images = Document. saveToImages (ImageType. bitmap); return images;} private static ImageCodecInfo GetEncoderInfo (string mimeType) {ImageCodecInfo [] encoders = ImageCodecInfo. getImageEncoders (); for (int j = 0; j <encoders. length; j ++) {if (encoders [j]. mimeType = mimeType) return encoders [j];} throw new Exception (mimeType + "mime type not found in ImageCodecInfo");} // custom method join1_images () save Word as TIFF Image format (using the specified encoder and Image encoding parameters) public static void join1_images (Image [] images, string outFile, EncoderValue compressEncoder) {System. drawing. imaging. encoder enc = System. drawing. imaging. encoder. saveFlag; EncoderParameters ep = new EncoderParameters (2); ep. param [0] = new EncoderParameter (enc, (long) EncoderValue. multiFrame); ep. param [1] = new EncoderParameter (System. drawing. imaging. encoder. compression, (long) compressEncoder); Image pages = images [0]; int frame = 0; ImageCodecInfo info = GetEncoderInfo ("image/tiff"); foreach (Image img in images) {if (frame = 0) {pages = img; pages. save (outFile, info, ep);} else {ep. param [0] = new EncoderParameter (enc, (long) EncoderValue. frameDimensionPage); pages. saveAdd (img, ep);} if (frame = images. length-1) {ep. param [0] = new EncoderParameter (enc, (long) EncoderValue. flush); pages. saveAdd (ep) ;}frame ++ ;}}}}

The above is the specific description of converting Word into other format files. The code in the method is for reference. You are welcome to reprint it (please indicate the source)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.