C#,vb. NET how to convert Word to PDF and text

Source: Internet
Author: User

As we all know, Word is one of the most commonly used office software in our daily work, sometimes we need to convert Word documents to PDF and text for some kind of needs. So how to C#,VB. NET programming way to achieve this function?

Below I will separately describe how to use the free version of Spire.doc for. NET components for Word to PDF and text conversion.

Free Spire.doc for. NET Components Overview

Free Spire.doc for. NET is spire.doc for. NET, a free version of the word component that is completely free and available for commercial and personal use. With this component, developers can create, read, write, save, print, and convert Word documents in the application. Featured Features: You can convert Word documents (Word 97-2003,word 2007,word 2010,word 2013) to commonly used file formats such as PDF, TXT, XML, RTF, XPS, EPUB, HTML, images, and more.

As a stand-alone. NET component, free Spire.doc for. NET runs without having to install Microsoft Office.

    • How to convert Word to PDF:

Step 1: Create a new document and load the Word document that you want to convert

Document. LoadFromFile (@ "C:\Users\Administrator\Desktop\ Little Prince content introduction. docx");

Step 2: Save the Word document to a folder in PDF format

Document. SaveToFile ("result. PDF", fileformat.pdf);

Step 3: Run the document

System.Diagnostics.Process.Start ("result. PDF");

Here are the pre-and post-conversion comparison graphs:

                                                          before conversion;                                                                                                      

after conversion

C # full Code

usingSpire.doc;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceconvert{classProgram {Static voidMain (string[] args) {   //Create a new document andload a Word document that needs to be convertedDocument document =NewDocument (); Document. LoadFromFile (@"C:\Users\Administrator\Desktop\ Little Prince content introduction. docx"); //Save a Word document to a folder in PDF formatDocument. SaveToFile ("result. PDF", fileformat.pdf); //Run the documentSystem.Diagnostics.Process.Start ("result. PDF"); }    }}

Vb. NET full code

ImportsSpire.docImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.TextNamespaceConvertClass ProgramPrivate Shared SubMain (args as String())            ' Create a new document andload a Word document that needs to be converted            DimDocument as NewDocument (). LoadFromFile ("C:\Users\Administrator\Desktop\ Little Prince content introduction. docx")            'Save a Word document to a folder in PDF formatDocument. SaveToFile ("result. PDF", Fileformat.pdf)'Run the documentSystem.Diagnostics.Process.Start ("result. PDF")        End Sub    End ClassEnd Namespace

    • How to convert Word to text:

Converting a Word document to text saves disk space and can be compatible with almost any application.

Step 1: Create a new document and load the Word document that you want to convert

New Document ();d ocument. LoadFromFile (@ "C:\Users\Administrator\Desktop\ Little Prince published version. docx");

Step 2: Save the document to a folder in TXT format

Document. SaveToFile ("Sample.txt", FILEFORMAT.TXT);

Step 3: Run the document

Worddocviewer ("Sample.txt");

Step 4: write the following complete code into your project, which will automatically generate a TXT document after running

C # full Code

usingSpire.doc;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceword_to_text{classProgram {Static voidMain (string[] args) {   //Create a new document and load the Word document that you want to convertDocument document =NewDocument (); Document. LoadFromFile (@"C:\Users\Administrator\Desktop\ The Little Prince published version. docx"); //Save the document to a folder in TXT formatDocument. SaveToFile ("Sample.txt", FILEFORMAT.TXT); //Run the documentWorddocviewer ("Sample.txt"); }        Private Static voidWorddocviewer (stringfileName) {            Try{System.Diagnostics.Process.Start (fileName); }            Catch { }        }    }}

Vb. NET full code

ImportsSpire.docImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.TextNamespaceWord_to_textClass ProgramPrivate Shared SubMain (args as String())            'Create a new document and load the Word document that you want to convert            DimDocument as NewDocument (). LoadFromFile ("C:\Users\Administrator\Desktop\ The Little Prince published version. docx")            'Save the document to a folder in TXT formatDocument. SaveToFile ("Sample.txt", FILEFORMAT.TXT)'Run the documentWorddocviewer ("Sample.txt")        End Sub        Private Shared SubWorddocviewer (fileName as String)            TrySystem.Diagnostics.Process.Start (fileName)Catch            End Try        End Sub    End ClassEnd Namespace


Here are the pre-and post-conversion comparison graphs:

Before conversion

after conversion

Today to share with you here, hoping to bring you some help.

C#,vb. NET how to convert Word to PDF and text

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.