Converting word doc file to pdf without using Microsoft.Office.Interop.Word Dll

Karthikreddy
Posted by Karthikreddy under ASP.NET category on | Points: 40 | Views : 23382
1.First we need to download the UseOffice.dll from http://www.fileflash.com/download/87066/ .
2.Extract the download file copy the useOffice.dll and paste it in the bin folder in solution file
3.open the visual studio 2010 and
4.add aspx form and drag and drop one Fileupload comtrol ,button and one label
5.write the following code in code behind


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string extention = Path.GetExtension(FileUpload1.PostedFile.FileName);
if (extention.ToLower() == ".doc" || extention.ToLower() == ".docx")
{
string path = System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);
string filename = TextBox1.Text;
FileUpload1.SaveAs(@"I:\karthik\pdf\pdf\" + filename);
ConvertTopdf(path,filename);
Label1.Text = "File upload Successfull";
}
else
{
Label1.Text = "Please Select the word file only";
}
}
else
{
Label1.Text = "Please Selet the File";
}
}
public void ConvertTopdf(string path,string filename)
{
SautinSoft.UseOffice u = new SautinSoft.UseOffice();
if (u.InitWord() == 0)
{
//convert Word (RTF, DOC, DOCX to PDF)
u.ConvertFile(path, @"I:\karthik\pdf\pdf\" + filename, SautinSoft.UseOffice.eDirection.DOC_to_PDF);
}
u.CloseOffice();
}
}

Comments or Responses

Login to post response