mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-20 17:42:20 +01:00
Add possibility to convert word documents to pdf.
This commit is contained in:
1 parent
0b3ccca685
commit
77d33cbb95
5 files changed
+95
-16
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// <copyright file="ConversionJob_ImageMagick.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,6 @@
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Accessibility" />
|
||||
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.0.2.900\lib\net40-client\Magick.NET-Q16-AnyCPU.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -74,23 +73,19 @@
|
||||
<Reference Include="Markdown.Xaml">
|
||||
<HintPath>..\..\Middleware\Markdown.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Office.Interop.Word, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="PresentationUI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="ReachFramework" />
|
||||
<Reference Include="Ripper, Version=1.0.5806.33932, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\Middleware\Ripper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Printing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
@@ -126,6 +121,7 @@
|
||||
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_Gif.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_Ico.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_Word.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_ImageMagick.cs" />
|
||||
<Compile Include="ConversionJobs\VideoEncodingSpeed.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionSettingsOverride.cs" />
|
||||
@@ -257,6 +253,7 @@
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
<Component Id="RegistryEntries" Guid="{C3EF3D67-0206-4DBD-B2EA-78FF2E290093}">
|
||||
<RegistryKey Root="HKCU" Key="Software\FileConverter" ForceDeleteOnUninstall="yes">
|
||||
<RegistryValue Name="Path" Type="string" Value="[INSTALLFOLDER]FileConverter.exe"/>
|
||||
<RegistryValue Name="CompatibleInputExtensions" Type="string" Value="3gp;aac;aiff;ape;avi;bik;bmp;cda;exr;flac;flv;gif;ico;jpg;jpeg;m4a;m4v;mkv;mov;mp3;mp4;mpeg;oga;ogg;ogv;pdf;png;psd;svg;tga;tiff;vob;wav;webm;wma;wmv"/>
|
||||
<RegistryValue Name="CompatibleInputExtensions" Type="string" Value="3gp;aac;aiff;ape;avi;bik;bmp;cda;doc;docx;exr;flac;flv;gif;ico;jpg;jpeg;m4a;m4v;mkv;mov;mp3;mp4;mpeg;oga;ogg;ogv;pdf;png;psd;svg;tga;tiff;vob;wav;webm;wma;wmv"/>
|
||||
</RegistryKey>
|
||||
</Component>
|
||||
</ComponentGroup>
|
||||
|
||||
Reference in new issue
Block a user