Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpenHtmlToPdf.Tests/HtmlToPdfConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void Convert_multiple_documents_concurrently()
var tasks = new List<Task<byte[]>>();

for (var i = 0; i < documentCount; i++)
tasks.Add(Task.Run(() => Pdf.From(html).Content()));
tasks.Add(Task.Factory.StartNew(() => Pdf.From(html).Content()));

Task.WaitAll(tasks.OfType<Task>().ToArray());

Expand Down Expand Up @@ -202,7 +202,7 @@ public void Convert_massive_number_of_documents()
var tasks = new List<Task<byte[]>>();

for (var i = 0; i < documentCount; i++)
tasks.Add(Task.Run(() => Pdf.From(html).Content()));
tasks.Add(Task.Factory.StartNew(() => Pdf.From(html).Content()));

Task.WaitAll(tasks.OfType<Task>().ToArray());

Expand Down
3 changes: 2 additions & 1 deletion OpenHtmlToPdf.Tests/OpenHtmlToPdf.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenHtmlToPdf.Tests</RootNamespace>
<AssemblyName>OpenHtmlToPdf.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand All @@ -18,6 +18,7 @@
<TestProjectType>UnitTest</TestProjectType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
6 changes: 3 additions & 3 deletions OpenHtmlToPdf.WkHtmlToPdf/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
</configuration>
15 changes: 8 additions & 7 deletions OpenHtmlToPdf.WkHtmlToPdf/Assets/ZipArchiveHelper.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using System.IO;
using Ionic.Zip;
using System.IO;
using System.IO.Compression;
using System.Linq;

namespace OpenHtmlToPdf.WkHtmlToPdf.Assets
{
static class ZipArchiveHelper
{
public static byte[] ReadFile(this ZipArchive zipArchive, string filename)
public static byte[] ReadFile(this ZipFile zipFile, string filename)
{
return zipArchive.Entries
.Where(e => e.FullName == filename)
return zipFile.Entries
.Where(e => e.FileName == filename)
.Select(Read).Single();
}

private static byte[] Read(this ZipArchiveEntry zipArchiveEntry)
private static byte[] Read(this ZipEntry zipEntry)
{
using (var stream = zipArchiveEntry.Open())
using (var stream = zipEntry.OpenReader())
{
return stream.Read(zipArchiveEntry.Length);
return stream.Read(zipEntry.UncompressedSize);
}
}

Expand Down
10 changes: 8 additions & 2 deletions OpenHtmlToPdf.WkHtmlToPdf/OpenHtmlToPdf.WkHtmlToPdf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenHtmlToPdf.WkHtmlToPdf</RootNamespace>
<AssemblyName>OpenHtmlToPdf.WkHtmlToPdf</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -40,9 +43,11 @@
</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetZip, Version=1.13.8.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.13.8\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down Expand Up @@ -73,6 +78,7 @@
<ItemGroup>
<None Include="App.config" />
<EmbeddedResource Include="Assets\wkhtmltox.zip" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down
7 changes: 4 additions & 3 deletions OpenHtmlToPdf.WkHtmlToPdf/WkHtmlToX/WkHtmlToPdfLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.IO.Compression;
using System.Reflection;
using Ionic.Zip;
using OpenHtmlToPdf.WkHtmlToPdf.Assets;
using OpenHtmlToPdf.WkHtmlToPdf.Interop;

Expand All @@ -23,15 +24,15 @@ private static byte[] LoadLibraryContent()
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
throw new PlatformNotSupportedException(String.Format("Platform {0} is not supported", Platform()));

using (var wkhtmltoxZipArchive = WkHtmlToXZipArchive())
using (var wkhtmltoxZipArchive = WkHtmlToXZipFile())
{
return wkhtmltoxZipArchive.ReadFile(CompressedLibraryFilename());
}
}

private static ZipArchive WkHtmlToXZipArchive()
private static ZipFile WkHtmlToXZipFile()
{
return new ZipArchive(GetManifestResourceStream());
return ZipFile.Read(GetManifestResourceStream());
}

private static Stream GetManifestResourceStream()
Expand Down
4 changes: 4 additions & 0 deletions OpenHtmlToPdf.WkHtmlToPdf/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.13.8" targetFramework="net40" />
</packages>
36 changes: 31 additions & 5 deletions OpenHtmlToPdf/Assets/ConverterExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace OpenHtmlToPdf.Assets
sealed class ConverterExecutable
{
private const string ConverterExecutableFilename = "OpenHtmlToPdf.WkHtmlToPdf.exe";
private const string ConverterExecutableReferenceFilename = "DotNetZip.dll";

private ConverterExecutable()
{
Expand All @@ -21,20 +22,31 @@ public static ConverterExecutable Get()
return bundledFile;
}


public string FullConverterExecutableReferenceFilename
{
get { return ResolveFullPathToConverterExecutableReferenceFile(); }
}


public string FullConverterExecutableFilename
{
get { return ResolveFullPathToConverterExecutableFile(); }
}

private void CreateIfConverterExecutableDoesNotExist()
{
if (!File.Exists(FullConverterExecutableReferenceFilename))
Create(GetConverterExecutableContent(GetConverterReferenceExecutable()), FullConverterExecutableReferenceFilename);

if (!File.Exists(FullConverterExecutableFilename))
Create(GetConverterExecutableContent());
Create(GetConverterExecutableContent(GetConverterExecutable()), FullConverterExecutableFilename);

}

private static byte[] GetConverterExecutableContent()
private static byte[] GetConverterExecutableContent(Stream stream)
{
using (var resourceStream = GetConverterExecutable())
using (var resourceStream = stream)
{
var resource = new byte[resourceStream.Length];

Expand All @@ -44,20 +56,29 @@ private static byte[] GetConverterExecutableContent()
}
}



private static Stream GetConverterExecutable()
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenHtmlToPdf.Assets.OpenHtmlToPdf.WkHtmlToPdf.exe");
}

private void Create(byte[] fileContent)
private static Stream GetConverterReferenceExecutable()
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenHtmlToPdf.Assets.DotNetZip.dll");
}



private void Create(byte[] fileContent, string Name)
{
try
{
if (!Directory.Exists(BundledFilesDirectory()))
Directory.CreateDirectory(BundledFilesDirectory());


using (var file = File.Open(FullConverterExecutableFilename, FileMode.Create))
using (var file = File.Open(Name, FileMode.Create))
{

file.Write(fileContent, 0, fileContent.Length);
Expand All @@ -73,6 +94,11 @@ private static string ResolveFullPathToConverterExecutableFile()
return Path.Combine(BundledFilesDirectory(), ConverterExecutableFilename);
}

private static string ResolveFullPathToConverterExecutableReferenceFile()
{
return Path.Combine(BundledFilesDirectory(), ConverterExecutableReferenceFilename);
}

private static string BundledFilesDirectory()
{
return Path.Combine(Path.GetTempPath(), "OpenHtmlToPdf", Version());
Expand Down
Binary file added OpenHtmlToPdf/Assets/DotNetZip.dll
Binary file not shown.
Binary file modified OpenHtmlToPdf/Assets/OpenHtmlToPdf.WkHtmlToPdf.exe
Binary file not shown.
Binary file added OpenHtmlToPdf/Key.snk
Binary file not shown.
14 changes: 11 additions & 3 deletions OpenHtmlToPdf/OpenHtmlToPdf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenHtmlToPdf</RootNamespace>
<AssemblyName>OpenHtmlToPdf</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
Expand Down Expand Up @@ -95,10 +95,15 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.XML" />
</ItemGroup>
Expand All @@ -119,9 +124,12 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="HtmlToPdfConverterProcess.cs" />
<Compile Include="TemporaryPdf.cs" />
<None Include="Key.snk" />
<None Include="Properties\OpenHtmlToPdf.nuspec" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="Assets\DotNetZip.dll" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\OpenHtmlToPdf.WkHtmlToPdf.exe" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions OpenHtmlToPdf/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.12.0")]
[assembly: AssemblyFileVersion("1.12.0")]
[assembly: AssemblyVersion("1.12.1")]
[assembly: AssemblyFileVersion("1.12.1")]