Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuespetre committed Jan 21, 2015
2 parents bf77c16 + bd6d682 commit 757d1be
Show file tree
Hide file tree
Showing 30 changed files with 701 additions and 63 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ TuesPechkin is a .NET Wrapper for the [wkhtmltopdf](https://github.com/wkhtmltop
- [Azure Websites does not currently support the use of wkhtmltopdf.](http://social.msdn.microsoft.com/Forums/windowsazure/en-US/eb48e701-8c0b-4be3-b694-2e11cc6ff2e1/wkhtmltopdf-in-windows-azure?forum=windowsazurewebsitespreview)
- It is not tested with any operating systems besides Windows.
- [It is available as a *NuGet package* for your convenience.](https://www.nuget.org/packages/TuesPechkin/)
- It is built and tested around wkhtmltopdf 0.11.0, 0.12.0, and 0.12.1.
- It is built and tested around wkhtmltopdf 0.12.2.
- Even if you use the IIS-compatible method documented below, you may only use one converter/toolset instance per application pool/process. A workaround is being researched for a future version.

### wkhtmltox.dll
The wkhtmltox.dll file and any dependencies it might have (for older versions, 0.11.0-) are not included in the TuesPechkin NuGet package; however, you can bring your own copy of the library or download one of the following NuGet packages that contain the library:
Expand All @@ -29,7 +30,7 @@ For 2.0.0 I am wanting to use the 'git flow' style of branching/merging/releasin

### 1. Choose a deployment

TuesPechkin exposes an 'IDeployment' interface to represent the folder where wkhtmltox.dll resides. There exists a `StaticDeployment` implementation that accepts a string path, and there exists an abstract `EmbeddedDeployment` class that can be implemented to automatically deploy the wkhtmltopdf dll(s) wherever you need them.
TuesPechkin exposes an 'IDeployment' interface to represent the folder where wkhtmltox.dll resides. There exists a `StaticDeployment` implementation that accepts a string path, a `TempFolderDeployment` implementation that generates an application-scoped folder path under the `%Temp%` folder, and an abstract `EmbeddedDeployment` class that can be implemented to automatically deploy the wkhtmltopdf dll(s) wherever you need them.

### 2. Choose a toolset

Expand Down Expand Up @@ -99,7 +100,8 @@ var document = new HtmlToPdfDocument
IConverter converter =
new StandardConverter(
new PdfToolset(
new StaticDeployment(DLL_FOLDER_PATH)));
new Win32EmbeddedDeployment(
new TempFolderDeployment())));

byte[] result = converter.convert(document);
```
Expand All @@ -109,7 +111,8 @@ byte[] result = converter.convert(document);
IConverter converter =
new ThreadSafeConverter(
new PdfToolset(
new StaticDeployment(DLL_FOLDER_PATH)));
new Win32EmbeddedDeployment(
new TempFolderDeployment())));

// Keep the converter somewhere static, or as a singleton instance!
Expand All @@ -121,20 +124,21 @@ byte[] result = converter.convert(document);
IConverter converter =
new ThreadSafeConverter(
new RemotingToolset<PdfToolset>(
new StaticDeployment(DLL_FOLDER_PATH)));
new Win32EmbeddedDeployment(
new TempFolderDeployment())));

// Keep the converter somewhere static, or as a singleton instance!
byte[] result = converter.convert(document);
```

### Use the embedded library from the TuesPechkin.Wkhtmltox.Win32 NuGet package.
### Use the embedded library from the TuesPechkin.Wkhtmltox.Win64 NuGet package instead.
```csharp
IConverter converter =
new StandardConverter(
new PdfToolset(
new Win32EmbeddedDeployment(
new StaticDeployment(DLL_FOLDER_PATH))));
new StandardConverter(
new PdfToolset(
new Win64EmbeddedDeployment(
new TempFolderDeployment())));

byte[] result = converter.convert(document);
```
Expand Down
65 changes: 55 additions & 10 deletions TuesPechkin.TestWebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,41 @@ namespace TuesPechkin.TestWebApp.Controllers
{
public class HomeController : Controller
{
private static IDeployment specificPath =
new StaticDeployment(
Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"../TuesPechkin.Tests/wk-ver/0.12.2"));

private static string randomPath = Path.Combine(
Path.GetTempPath(),
Guid.NewGuid().ToString(),
"wkhtmltox.dll");

private static IConverter converter =
new ThreadSafeConverter(
new RemotingToolset<PdfToolset>(
new Win32EmbeddedDeployment(
new StaticDeployment(
Path.Combine(
Path.GetTempPath(),
Guid.NewGuid().ToString(),
"wkhtmltox.dll")))));
new TempFolderDeployment())));

private static IConverter anotherConverter =
new ThreadSafeConverter(
new RemotingToolset<PdfToolset>(
specificPath));

private static IConverter imageConverter =
new ThreadSafeConverter(
new RemotingToolset<ImageToolset>(
new Win32EmbeddedDeployment(
new TempFolderDeployment())));

// GET: /Home/
public ActionResult Index()
{
return View();
}

public ActionResult PdfTest()
{
var doc = new HtmlToPdfDocument();
doc.Objects.Add(new ObjectSettings { PageUrl = "www.google.com " });
Expand All @@ -34,25 +57,47 @@ public ActionResult Index()
return this.View();
}

/*[HttpGet]
[HttpGet]
public FileResult ScratchPad()
{
var doc = new HtmlDocument();
var doc = new HtmlToPdfDocument();
var obj = new ObjectSettings();

obj.PageUrl = Url.Action("PostAnything", "Home", routeValues: null, protocol: Request.Url.Scheme);
obj.LoadSettings.CustomHeaders.Add("X-MY-HEADER", "my value");
obj.LoadSettings.Cookies.Add("my_awesome_cookie", "cookie value");
obj.LoadSettings.PostItems.Add(new PostItem
{
Name = "my_special_value",
Value = "is an amazing value"
});

var converter = Factory.Create();
var result = converter.Convert(obj);
doc.Objects.Add(obj);

var result = anotherConverter.Convert(doc);

return File(result, "application/pdf");
}*/
}

public ActionResult PostAnything()
{
return View();
}

[HttpGet]
public FileResult ImageTest()
{
var doc = new HtmlToImageDocument()
{
In = "www.google.com",
Format = "jpg",
ScreenWidth = 500,
ScreenHeight = 500
};

var result = imageConverter.Convert(doc);

return File(result, "image/jpeg");
}
}
}
5 changes: 2 additions & 3 deletions TuesPechkin.TestWebApp/TuesPechkin.TestWebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<AssemblyName>TuesPechkin.TestWebApp</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>false</UseIISExpress>
<IISExpressSSLPort>443</IISExpressSSLPort>
<UseIISExpress>true</UseIISExpress>
<IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
<IISExpressWindowsAuthentication>disabled</IISExpressWindowsAuthentication>
<IISExpressUseClassicPipelineMode>false</IISExpressUseClassicPipelineMode>
Expand Down Expand Up @@ -262,7 +261,7 @@
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>50249</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost/TuesPechkin.TestWebApp</IISUrl>
<IISUrl>http://localhost:65432</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
27 changes: 21 additions & 6 deletions TuesPechkin.TestWebApp/Views/Home/PostAnything.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<th>Name</th>
<th>Value</th>
</tr>
@foreach (HttpCookie cookie in Request.Cookies)
@foreach (HttpCookie cookie in Request.Cookies.AllKeys.Select(k => Request.Cookies[k]))
{
<tr>
<td>@cookie.Name</td>
Expand All @@ -25,11 +25,26 @@
<th>Name</th>
<th>Value</th>
</tr>
@foreach (string key in Request.Headers)
{
@foreach (string key in Request.Headers)
{
<tr>
<td>@key</td>
<td>@Request.Headers[key]</td>
</tr>
}
</table>

<h3>Post values</h3>
<table>
<tr>
<td>@key</td>
<td>@Request.Headers[key]</td>
<th>Name</th>
<th>Value</th>
</tr>
}
@foreach (string key in Request.Form)
{
<tr>
<td>@key</td>
<td>@Request.Form[key]</td>
</tr>
}
</table>
6 changes: 2 additions & 4 deletions TuesPechkin.Tests/EventSubscriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public void BeginDoesNotBlockConversion()
Assert.IsTrue(count > 0);
}

// Not fully implemented yet; haven't figured out how to force Error
[TestMethod, Ignore]
[TestMethod]
public void ErrorDoesNotBlockConversion()
{
var count = 0;
Expand Down Expand Up @@ -76,8 +75,7 @@ public void ProgressChangeDoesNotBlockConversion()
Assert.IsTrue(count > 0);
}

// Not fully implemented yet; haven't figured out how to force Error
[TestMethod, Ignore]
[TestMethod]
public void WarningDoesNotBlockConversion()
{
var count = 0;
Expand Down
2 changes: 1 addition & 1 deletion TuesPechkin.Tests/GeneralTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void TwoSequentialConversionsFromString()
Assert.IsNotNull(result);
}

[TestMethod, Ignore]
[TestMethod]
public void MultipleObjectConversionFromString()
{
// See: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1790
Expand Down
3 changes: 3 additions & 0 deletions TuesPechkin.Tests/TuesPechkin.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<Content Include="wk-ver\0.12.1\wkhtmltox.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="wk-ver\0.12.2\wkhtmltox.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Expand Down
2 changes: 1 addition & 1 deletion TuesPechkin.Tests/TuesPechkinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TuesPechkin.Tests
[TestClass]
public abstract class TuesPechkinTests
{
protected const string TEST_WK_VER = "0.12.1";
protected const string TEST_WK_VER = "0.12.2";
protected const string TEST_URL = "www.google.com";

// Simulates 1.x.x
Expand Down
Binary file added TuesPechkin.Tests/wk-ver/0.12.2/wkhtmltox.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion TuesPechkin.Wkhtmltox.Win32/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// 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("0.12.1.0")]
[assembly: AssemblyVersion("0.12.2.1")]
15 changes: 15 additions & 0 deletions TuesPechkin.Wkhtmltox.Win32/TuesPechkin.Wkhtmltox.Win32.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>TuesPechkin.Wkhtmltox.Win32</id>
<version>$version$</version>
<title>TuesPechkin.Wkhtmltox.Win32</title>
<authors>tuespetre</authors>
<owners>tuespetre</owners>
<projectUrl>https://github.com/tuespetre/TuesPechkin</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A bundled copy of wkhtmltox.dll for use with TuesPechkin.</description>
<copyright>Copyright 2015</copyright>
<tags>wkhtmltopdf html pdf</tags>
</metadata>
</package>
16 changes: 13 additions & 3 deletions TuesPechkin.Wkhtmltox.Win32/WinEmbeddedDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ public class Win32EmbeddedDeployment : EmbeddedDeployment
{
public Win32EmbeddedDeployment(IDeployment physical) : base(physical) { }

protected override IEnumerable<KeyValuePair<string, Stream>> GetContents()
public override string Path
{
var raw = Resources.wkhtmltox_32_dll;
get
{
return System.IO.Path.Combine(
base.Path,
GetType().Assembly.GetName().Version.ToString());
}
}

protected override IEnumerable<KeyValuePair<string, Stream>> GetContents()
{
return new []
{
new KeyValuePair<string, Stream>(
key: WkhtmltoxBindings.DLLNAME,
value: new GZipStream(new MemoryStream(raw), CompressionMode.Decompress))
value: new GZipStream(
new MemoryStream(Resources.wkhtmltox_32_dll),
CompressionMode.Decompress))
};
}
}
Expand Down
Binary file modified TuesPechkin.Wkhtmltox.Win32/wkhtmltox_32.dll.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion TuesPechkin.Wkhtmltox.Win64/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// 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("0.12.1")]
[assembly: AssemblyVersion("0.12.2.1")]
15 changes: 15 additions & 0 deletions TuesPechkin.Wkhtmltox.Win64/TuesPechkin.Wkhtmltox.Win64.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>TuesPechkin.Wkhtmltox.Win64</id>
<version>$version$</version>
<title>TuesPechkin.Wkhtmltox.Win64</title>
<authors>tuespetre</authors>
<owners>tuespetre</owners>
<projectUrl>https://github.com/tuespetre/TuesPechkin</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A bundled copy of wkhtmltox.dll for use with TuesPechkin.</description>
<copyright>Copyright 2015</copyright>
<tags>wkhtmltopdf html pdf</tags>
</metadata>
</package>
18 changes: 14 additions & 4 deletions TuesPechkin.Wkhtmltox.Win64/WinEmbeddedDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ public class Win64EmbeddedDeployment : EmbeddedDeployment
{
public Win64EmbeddedDeployment(IDeployment physical) : base(physical) { }

protected override IEnumerable<KeyValuePair<string, Stream>> GetContents()
public override string Path
{
var raw = Resources.wkhtmltox_64_dll;
get
{
return System.IO.Path.Combine(
base.Path,
GetType().Assembly.GetName().Version.ToString());
}
}

return new []
protected override IEnumerable<KeyValuePair<string, Stream>> GetContents()
{
return new[]
{
new KeyValuePair<string, Stream>(
key: WkhtmltoxBindings.DLLNAME,
value: new GZipStream(new MemoryStream(raw), CompressionMode.Decompress))
value: new GZipStream(
new MemoryStream(Resources.wkhtmltox_64_dll),
CompressionMode.Decompress))
};
}
}
Expand Down
Binary file modified TuesPechkin.Wkhtmltox.Win64/wkhtmltox_64.dll.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions TuesPechkin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ Global
{023DF833-B252-48B3-B6AF-DBBB13E39B13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{023DF833-B252-48B3-B6AF-DBBB13E39B13}.Release|Any CPU.Build.0 = Release|Any CPU
{35E72E2C-DE58-4ED7-9B47-5EF13860AF42}.Debug|Any CPU.ActiveCfg = Debug|x64
{35E72E2C-DE58-4ED7-9B47-5EF13860AF42}.Debug|Any CPU.Build.0 = Debug|x64
{35E72E2C-DE58-4ED7-9B47-5EF13860AF42}.Release|Any CPU.ActiveCfg = Release|x64
{35E72E2C-DE58-4ED7-9B47-5EF13860AF42}.Release|Any CPU.Build.0 = Release|x64
{D58769FA-E008-4016-A81C-A85C606B3691}.Debug|Any CPU.ActiveCfg = Debug|x86
{D58769FA-E008-4016-A81C-A85C606B3691}.Debug|Any CPU.Build.0 = Debug|x86
{D58769FA-E008-4016-A81C-A85C606B3691}.Release|Any CPU.ActiveCfg = Release|x86
{D58769FA-E008-4016-A81C-A85C606B3691}.Release|Any CPU.Build.0 = Release|x86
{B12D40DF-C865-4116-9C42-0EEDCF9FB19A}.Debug|Any CPU.ActiveCfg = Debug|x86
{B12D40DF-C865-4116-9C42-0EEDCF9FB19A}.Debug|Any CPU.Build.0 = Debug|x86
{B12D40DF-C865-4116-9C42-0EEDCF9FB19A}.Release|Any CPU.ActiveCfg = Release|x86
{B12D40DF-C865-4116-9C42-0EEDCF9FB19A}.Release|Any CPU.Build.0 = Release|x86
{1BCD70EF-32EF-4339-9CCF-EA07415A39A9}.Debug|Any CPU.ActiveCfg = Debug|x86
Expand Down
Loading

0 comments on commit 757d1be

Please sign in to comment.