how can we convert word document into pdf by asp.net. I browse a ms-word file by FileUpload & when i click on OK, it automatically convert that file into PDF. Can anybody guide me how can be it possible. I got some code by google but thats are incomplete. If Anybody know the solution kindly share with me.
Asked
Active
Viewed 3,596 times
2 Answers
0
From: Convert word doc to pdf
private Microsoft.Office.Interop.Word.ApplicationClass MSdoc;
//Use for the parameter whose type are not known or say Missing
object Unknown = Type.Missing;
private void word2PDF(object Source, object Target)
{ //Creating the instance of Word Application
if (MSdoc == null)MSdoc = new Microsoft.Office.Interop.Word.ApplicationClass();
try
{
MSdoc.Visible = false;
MSdoc.Documents.Open(ref Source, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
MSdoc.Application.Visible = false;
MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
MSdoc.ActiveDocument.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (MSdoc != null)
{
MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown);
//WordDoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown);
}
// for closing the application
WordDoc.Quit(ref Unknown, ref Unknown, ref Unknown);
}
}
Refer these:
Convert word to pdf file for codebehind in asp.net in c#
Convert DOC to PDF
a .NET dll for office 2010 to convert word to pdf and code in c#
Convert word to pdf using free third party dll
iTextSharp is also an option.
Hope this help..

Community
- 1
- 1

Niranjan Singh
- 18,017
- 2
- 42
- 75
0
@Niranjan Kala's answer is a well and good option
still if you need an another option you can go for: which provides SDK's for the same..

RohitWagh
- 1,999
- 3
- 22
- 43