Appendix B
Copy
MyWordConverter.cs
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Office.Interop.Word;
using Aras.ConversionFramework.Converter;
using MyWordConverter.Configuration;
namespace MyWordConverter
{
public class MyWordConverter : VaultFileConverter
{
#region Overrided Protected Methods
protected override void Dispose(bool disposing)
{
}
protected override string GetFileKind(FileInfo file)
{
if (file == null)
{
throw new ArgumentNullException("file");
}
switch (file.Extension.ToUpperInvariant())
{
case ".PDF":
return "pdf";
default:
return String.Empty;
}
}
protected override IList<FileInfo> Convert(IDictionary<string, FileInfo> filePaths)
{
// Do the actual conversion ...
List<FileInfo> returnList = new List<FileInfo> { };
Application wordApplication = new Application();
Document wordDocument = null;
object paramSourceDocPath = filePaths[Context.ConversionTask.FileID].FullName;
string fileExt = filePaths[Context.ConversionTask.FileID].Extension;
object paramMissing = Type.Missing;
// Retrieve the settings from the ConversionServerConfig xml file
MyWordConverterConfig configuration = (MyWordConverterConfig)ConversionConfigurationManager.GetInstance().GetConverterConfiguration().GetSection("ConverterSettings/MyWordConverter");
string pdfSuffix = configuration.Settings.PdfSuffix;
string paramExportFilePath = filePaths[Context.ConversionTask.FileID].FullName.Replace(fileExt, pdfSuffix + ".pdf");
FileInfo returnItem = new FileInfo(paramExportFilePath);
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.wdExportCreateHeadingBookmarks;
bool paramDocStructureTags = false;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
object objMissing = System.Reflection.Missing.Value;
object objConfirmConversions = false;
object objReadOnly = true;
object objAddToRecentFiles = false;
object objPasswordDocument = objMissing;
object objPasswordTemplate = objMissing;
object objRevert = true;
object objWritePasswordDocument = objMissing;
object objWritePasswordTemplate = objMissing;
object objFormat = WdOpenFormat.wdOpenFormatAuto;
object objEncoding = 20127;
object objVisible = false;
object objOpenConflictDocument = false;
object objOpenAndRepair = false;
object objDocumentDirection = WdDocumentDirection.wdLeftToRight;
object objNoEncodingDialog = true;
object objXmlTransform = objMissing;
object ofalse = false;
wordDocument = wordApplication.Documents.Open(ref paramSourceDocPath,
ref objConfirmConversions, ref objReadOnly, ref objAddToRecentFiles,
ref objPasswordDocument, ref objPasswordTemplate, ref objRevert,
ref objWritePasswordDocument, ref objWritePasswordTemplate,
ref objFormat, ref objEncoding, ref objVisible, ref objOpenAndRepair,
ref objDocumentDirection, ref objNoEncodingDialog, ref objXmlTransform);
// Export it in the specified format.
if (wordDocument != null)
wordDocument.ExportAsFixedFormat(paramExportFilePath,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);
// Quit Word and release the ApplicationClass object.
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing,
ref paramMissing);
wordApplication = null;
}
returnList.Add(returnItem);
return returnList;
}
#endregion
}
}