Please install ms-office 2007 and plug-in save as pdf and xps...
then
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
namespace PDFExport
{
public class Class1
{
public void saveaspdf(string rptname)
{
object readOnly = false;
object Unknown = System.Reflection.Missing.Value; //Type.Missing;
object missing = Type.Missing;
ApplicationClass wordApplication = new ApplicationClass();
Document wordDocument = null;
object paramSourceDocPath = rptname;
object paramMissing = Type.Missing;
string paramExportFilePath = rptname + ".pdf";
//WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
//bool paramOpenAfterExport = false;
//WdExportOptimizeFor paramExportOptimizeFor =
// WdExportOptimizeFor.wdExportOptimizeForPrint;
//WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
//int paramStartPage = 0;
//int paramEndPage = 0;
//WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
//bool paramIncludeDocProps = true;
//bool paramKeepIRM = true;
//WdExportCreateBookmarks paramCreateBookmarks =
// WdExportCreateBookmarks.wdExportCreateWordBookmarks;
//bool paramDocStructureTags = true;
//bool paramBitmapMissingFonts = true;
//bool paramUseISO19005_1 = false;
wordDocument = wordApplication.Documents.Open(ref paramSourceDocPath, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing);
wordApplication.Application.Visible = false;
wordApplication.WindowState = WdWindowState.wdWindowStateMinimize;
//wordApplication.ActivePrinter = "Microsoft XPS Document Writer";
try
{
if (wordDocument != null)
wordDocument.ExportAsFixedFormat(paramExportFilePath, WdExportFormat.wdExportFormatPDF, false,
WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 1, 1,
WdExportItem.wdExportDocumentContent, true, true,
WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, true, true, ref missing);
}
catch (Exception ex)
{
// Respond to the error
}
finally
{
// Close and release the Document object.
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing,
ref paramMissing);
wordDocument = null;
}
// Quit Word and release the ApplicationClass object.
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing,
ref paramMissing);
wordApplication = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
}