Add pdf to png conversion

This commit is contained in:
Tichau committed 2016-07-02 16:21:22 +02:00
1 parent 4e81f4637d
commit 27be265436
9 files changed
+118 -8

No files matched your search

@@ -6,9 +6,9 @@ namespace FileConverter.ConversionJobs
{
public static ConversionJob Create(ConversionPreset conversionPreset, string inputFilePath)
{
string extension = System.IO.Path.GetExtension(inputFilePath);
extension = extension.ToLowerInvariant().Substring(1, extension.Length - 1);
if (extension == "cda")
string inputFileExtension = System.IO.Path.GetExtension(inputFilePath);
inputFileExtension = inputFileExtension.ToLowerInvariant().Substring(1, inputFileExtension.Length - 1);
if (inputFileExtension == "cda")
{
return new ConversionJob_ExtractCDA(conversionPreset);
}
@@ -23,11 +23,17 @@ namespace FileConverter.ConversionJobs
return new ConversionJob_Gif(conversionPreset);
}
if (Helpers.GetExtensionCategory(extension) == Helpers.InputCategoryNames.Image)
if (Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Image)
{
return new ConversionJob_ImageMagick(conversionPreset);
}
if (conversionPreset.OutputType == OutputType.Pdf ||
Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Document)
{
return new ConversionJob_Pdf(conversionPreset);
}
return new ConversionJob_FFMPEG(conversionPreset);
}
}
@@ -0,0 +1,93 @@
// <copyright file="ConversionJob_ImageMagick.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ConversionJobs
{
using System;
using FileConverter.Diagnostics;
using ImageMagick;
public class ConversionJob_Pdf : ConversionJob
{
private int pageCount = 0;
public ConversionJob_Pdf() : base()
{
}
public ConversionJob_Pdf(ConversionPreset conversionPreset) : base(conversionPreset)
{
}
protected override void Initialize()
{
base.Initialize();
string applicationDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
MagickNET.SetGhostscriptDirectory(applicationDirectory);
if (this.ConversionPreset == null)
{
throw new Exception("The conversion preset must be valid.");
}
}
protected override int GetOuputFilesCount()
{
using (MagickImageCollection images = new MagickImageCollection())
{
MagickReadSettings settings = new MagickReadSettings();
settings.Density = new Density(1, 1);
images.Read(this.InputFilePath);
return images.Count;
}
}
protected override void Convert()
{
if (this.ConversionPreset == null)
{
throw new Exception("The conversion preset must be valid.");
}
this.UserState = Properties.Resources.ConversionStateReadPdf;
MagickReadSettings settings = new MagickReadSettings();
// Settings the density to 300 dpi will create an image with a better quality
settings.Density = new Density(300, 300);
using (MagickImageCollection images = new MagickImageCollection())
{
// Add all the pages of the pdf file to the collection
images.Read(this.InputFilePath, settings);
Debug.Log("Load pdf {0} succeed.", this.InputFilePath);
this.pageCount = images.Count;
this.CurrentOuputFilePathIndex = 0;
foreach (MagickImage image in images)
{
this.UserState = Properties.Resources.ConversionStateConversion;
Debug.Log("Write page {0}/{1}.", this.CurrentOuputFilePathIndex + 1, this.pageCount);
image.Progress += this.Image_Progress;
// Write page to file that contains the page number
image.Write(this.OutputFilePath);
this.CurrentOuputFilePathIndex++;
image.Progress -= this.Image_Progress;
}
}
}
private void Image_Progress(object sender, ProgressEventArgs eventArgs)
{
float alreadyCompletedPages = this.CurrentOuputFilePathIndex / (float)this.pageCount;
this.Progress = alreadyCompletedPages + (float)eventArgs.Progress.ToDouble() / (100f * this.pageCount);
}
}
}
@@ -47,7 +47,7 @@
<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.0.0101\lib\net40-client\Magick.NET-Q16-AnyCPU.dll</HintPath>
<HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.0.2.100\lib\net40-client\Magick.NET-Q16-AnyCPU.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Markdown.Xaml">
@@ -101,6 +101,7 @@
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
<Compile Include="ConversionJobs\ConversionJob_Gif.cs" />
<Compile Include="ConversionJobs\ConversionJob_Ico.cs" />
<Compile Include="ConversionJobs\ConversionJob_Pdf.cs" />
<Compile Include="ConversionJobs\ConversionJob_ImageMagick.cs" />
<Compile Include="ConversionJobs\VideoEncodingSpeed.cs" />
<Compile Include="ConversionPreset\ConversionSettingsOverride.cs" />
@@ -268,6 +269,8 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(SolutionDir)Middleware\ffmpeg.exe" "$(TargetDir)ffmpeg.exe"
copy /Y "$(SolutionDir)Middleware\gsdll64.dll" "$(TargetDir)gsdll64.dll"
copy /Y "$(SolutionDir)Middleware\gswin64c.exe" "$(TargetDir)gswin64c.exe"
copy /Y "$(ProjectDir)Settings.default.xml" "$(TargetDir)Settings.default.xml"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+8 -1
View File
@@ -70,6 +70,9 @@ namespace FileConverter
case "gif":
return InputCategoryNames.AnimatedImage;
case "pdf":
return InputCategoryNames.Document;
}
return InputCategoryNames.Misc;
@@ -102,11 +105,14 @@ namespace FileConverter
case OutputType.Ico:
case OutputType.Jpg:
case OutputType.Png:
return category == InputCategoryNames.Image;
return category == InputCategoryNames.Image || category == InputCategoryNames.Document;
case OutputType.Gif:
return category == InputCategoryNames.Image || category == InputCategoryNames.Video || category == InputCategoryNames.AnimatedImage;
case OutputType.Pdf:
return category == InputCategoryNames.Image || category == InputCategoryNames.Document;
default:
return false;
}
@@ -118,6 +124,7 @@ namespace FileConverter
public const string Video = "Video";
public const string Image = "Image";
public const string AnimatedImage = "Animated Image";
public const string Document = "Document";
public const string Misc = "Misc";
}
+1
View File
@@ -17,6 +17,7 @@ namespace FileConverter
Mp4,
Ogg,
Ogv,
Pdf,
Png,
Wav,
Webm,
+1 -1
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Magick.NET-Q16-AnyCPU" version="7.0.0.0101" targetFramework="net45" />
<package id="Magick.NET-Q16-AnyCPU" version="7.0.2.100" targetFramework="net45" />
</packages>
+1 -1
View File
@@ -125,7 +125,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;png;psd;svg;tga;tiff;vob;wav;webm;wma;wmv"/>
<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"/>
</RegistryKey>
</Component>
</ComponentGroup>
Binary file not shown.
Binary file not shown.