/// <Summary>
/// This function copy from Microsoft msdn
/// </Summary>
/// <Param name = "wordinputpath"> </param>
/// <Param name = "pdfoutputpath"> </param>
/// <Param name = "CommonName"> </param>
Public static void convertword2pdf (string wordinputpath, string pdfoutputpath, string CommonName)
{
Try
{
String extension = ". pdf ";
// Validate patameter
If (! Directory. exists (pdfoutputpath) {directory. createdirectory (pdfoutputpath );}
If (partition name. Trim (). Length = 0) {partition name = path. getfilenamewithoutextension (wordinputpath );}
If (! (Path. getextension (pipeline name). toupper () = pipeline extension. toupper () {pipeline name = pipeline name + pipeline extension ;}
Object paramsourcedocpath = wordinputpath;
Object parammissing = type. missing;
String paramexportfilepath = path. Combine (pdfoutputpath, parameter name );
// Create a word Application Object
Applicationclass wordapplication = new applicationclass ();
Microsoft. Office. InterOP. Word. Document worddocument = NULL;
// Set exportformat to 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 paramdid dedocprops = true;
Bool paramkeepsert = true;
Wdexportcreatebookmarks paramcreatebookmarks = wdexportcreatebookmarks. wdexportcreatewordbookmarks;
Bool paramdocstructuretags = true;
Bool parambitmapmissingfonts = true;
Bool paramuseiso19005_1 = false;
Try
{
// Open the source document.
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 );
// Export it in the specified format.
If (worddocument! = NULL)
Worddocument. exportasfixedformat (paramexportfilepath,
Paramexportformat, paramopenafterexport,
Paramexportoptimizefor, paramexportrange, paramstartpage,
Paramendpage, paramexportitem, paramincludedocprops,
Paramkeepsert, paramcreatebookmarks, paramdocstructuretags,
Parambitmapmissingfonts, paramuseiso19005_1,
Ref parammissing );
}
Catch (exception ex)
{
Throw ex;
}
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 ();
}
}
Catch (exception ex)
{
Throw ex;
}
}