Tuesday, May 6, 2014

How to Convert Word to PDF for Free in C#

This is an all-in-one solution to convert Word to PDF. Within this solution, you can either create a word from scratch or load a word template from folder, and then edit the document as you like; finally you can effortlessly convert word to PDF in C#, VB.NET. The conversion can be doc or docxto PDF.
Free Spire.Doc for .NET is a Community Edition of the Spire.Doc for .NET. It is a free.NET word library which enables users to directly manage word editing without Microsoft Word being installed, after the editing, you can convert the document to PDF in 2 steps.

Below is an effective screenshot of the document which will be converted to PDF. At the end of this post, you can find the target PDFdocument.
Now download the free version of Spire.Doc for .NET and convert word to PDF for personal use or evaluation. The whole process of converting word to PDF in C#, VB.NET can be described as 2 simple steps.
1. Declare a document and load document which you prepare by using ocument.LoadFromFile() method. The parameter passed to this method is file name string.
2. Save Word document as PDF by using document.SaveToFile() method. Parameters passed to this method is file name string and file format. The file format must be PDF.
[C#]
using System;
using Spire.Doc;
usingSpire.Doc.Documents;
namespaceDoctoPDF

{
classProgram
    {
staticvoid Main(string[] args)
{

Documentdocument = newDocument();
document.LoadFromFile("Word.doc"); 

//Convert Word to PDF 
document.SaveToFile("toPDF.PDF", FileFormat.PDF);

//Launch Document 
System.Diagnostics.Process.Start("toPDF.PDF"); 
        }
    }
}
[VB]
mports System

Imports Spire.Doc 

ImportsSpire.Doc.Documents

NamespaceDoctoPDF
FriendClasstoPDF
SharedSubMain(ByValargs() AsString)

'Load Document 
Dim document AsNewDocument()
document.LoadFromFile("E:\work\documents\TestSample.docx")

'Convert Word to PDF 
document.SaveToFile("toPDF.PDF", FileFormat.PDF)

'Launch Document 

System.Diagnostics.Process.Start("toPDF.PDF")

EndSub

EndClass

EndNamespace
After running the demo, you may find a PDF document launched on your computer:


1 comment:

  1. Why don't you give this JPG to PDF converter a try. You must try this JPG to PDF converter and you will be surprised

    ReplyDelete