diff --git a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs index 83c8834..3059cbd 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs @@ -13,6 +13,11 @@ namespace FileConverter.ConversionJobs return new ConversionJob_ExtractCDA(conversionPreset); } + if (inputFileExtension == "doc" || inputFileExtension == "docx") + { + return new ConversionJob_Word(conversionPreset); + } + if (conversionPreset.OutputType == OutputType.Ico) { return new ConversionJob_Ico(conversionPreset); @@ -23,17 +28,17 @@ namespace FileConverter.ConversionJobs return new ConversionJob_Gif(conversionPreset); } - if (Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Image || - Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Document) - { - return new ConversionJob_ImageMagick(conversionPreset); - } - if (conversionPreset.OutputType == OutputType.Pdf) { return new ConversionJob_ImageMagick(conversionPreset); } + if (Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Image || + Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Document) + { + return new ConversionJob_ImageMagick(conversionPreset); + } + return new ConversionJob_FFMPEG(conversionPreset); } } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs new file mode 100644 index 0000000..d23d41e --- /dev/null +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs @@ -0,0 +1,75 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ConversionJobs +{ + using System; + + public class ConversionJob_Word : ConversionJob + { + private static Microsoft.Office.Interop.Word.Application wordApplication; + private static int wordApplicationRefCount = 0; + + public ConversionJob_Word() : base() + { + } + + public ConversionJob_Word(ConversionPreset conversionPreset) : base(conversionPreset) + { + } + + protected override void Initialize() + { + base.Initialize(); + + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + + if (this.ConversionPreset.OutputType != OutputType.Pdf) + { + this.ConversionFailed("This conversion is not allowed"); + return; + } + + System.Threading.Interlocked.Increment(ref ConversionJob_Word.wordApplicationRefCount); + if (ConversionJob_Word.wordApplication == null) + { + Diagnostics.Debug.Log("Instantiate word application via interop."); + ConversionJob_Word.wordApplication = new Microsoft.Office.Interop.Word.Application + { + Visible = false + }; + } + } + + protected override void Convert() + { + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + + this.UserState = Properties.Resources.ConversionStateReadDocument; + + object inputFilePath = this.InputFilePath; + Microsoft.Office.Interop.Word.Document document = ConversionJob_Word.wordApplication.Documents.Open(ref inputFilePath); + + // Make this document the active document. + document.Activate(); + + this.UserState = Properties.Resources.ConversionStateConversion; + + object outputFilePath = this.OutputFilePath; + object outputFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; + document.SaveAs(ref outputFilePath, ref outputFileFormat); + + System.Threading.Interlocked.Decrement(ref ConversionJob_Word.wordApplicationRefCount); + if (ConversionJob_Word.wordApplicationRefCount == 0) + { + Diagnostics.Debug.Log("Quit word application via interop."); + ConversionJob_Word.wordApplication.Quit(); + } + } + } +} diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index f4f9c49..bd8b04b 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -66,7 +66,6 @@ true - ..\..\packages\Magick.NET-Q16-AnyCPU.7.0.2.900\lib\net40-client\Magick.NET-Q16-AnyCPU.dll True @@ -74,23 +73,19 @@ ..\..\Middleware\Markdown.Xaml.dll + + True + - False ..\..\Middleware\Ripper.dll - - - - - - 4.0 @@ -126,6 +121,7 @@ + @@ -257,6 +253,7 @@ PublicResXFileCodeGenerator Resources.Designer.cs + Designer diff --git a/Application/FileConverter/Helpers.cs b/Application/FileConverter/Helpers.cs index e748b31..77e8fb9 100644 --- a/Application/FileConverter/Helpers.cs +++ b/Application/FileConverter/Helpers.cs @@ -73,6 +73,8 @@ namespace FileConverter return InputCategoryNames.AnimatedImage; case "pdf": + case "doc": + case "docx": return InputCategoryNames.Document; } @@ -112,7 +114,7 @@ namespace FileConverter return category == InputCategoryNames.Image || category == InputCategoryNames.Video || category == InputCategoryNames.AnimatedImage; case OutputType.Pdf: - return category == InputCategoryNames.Image; + return category == InputCategoryNames.Image || category == InputCategoryNames.Document; default: return false; diff --git a/Installer/Product.wxs b/Installer/Product.wxs index 9ffc523..43e0207 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -142,7 +142,7 @@ - +