Hi All.
Would you please help me. I'm writing an application for an Insurance company,the application create a word document and attaches it to an email and send the email to a client.
The company wants that word document to be programmatically converted to PDF and get save in the local folder. How do I convert MS Word document to PDF in C# or VB.Net.
Thank you in advanced.
Mpumelelo
Mpumelelo KhuzwayoPosted Jun 15, 2007, 5:22 AM
Would you please tell me where in that code does the actual conversion of the Word document to PDF take place and how to to save that converted document.
Thank You
Mpumelelo
David IsaacPosted Jun 15, 2007, 4:38 AM
(using Microsoft.Office.Interop.Word;)
ApplicationClass wordApp = new ApplicationClass(); Document wordDoc = null; string paramExportFilePath = @"C:\\Test.xps";
WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatXPS;
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
bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; try= WdExportCreateBookmarks.wdExportCreateWordBookmarks;
{
// Open the source document.wordDoc = wordApp.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 (wordDoc != null)wordDoc.ExportAsFixedFormat(paramExportFilePath,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);}
catch (Exception ex){
// Respond to the error}
finally{
// Close and release the Document object. if (wordDoc != null){
wordDoc.Close(
ref paramMissing, ref paramMissing, ref paramMissing);wordDoc =
null;}
// Quit Word and release the ApplicationClass object. if (wordApp != null){
wordApp.Quit(
ref paramMissing, ref paramMissing, ref paramMissing);wordApp =
null;}
GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers();