Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ UpgradeLog*.XML

*.DotSettings
/Source/.vs/
/Source/Demo/Console/HtmlRenderer.Demo.Console/Output
4 changes: 2 additions & 2 deletions Source/Demo/Common/TestSamples/06.External Image.htm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div>
From web:
</div>
<img height="100" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg"/>
<img height="100" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg"/>
<hr />
<div>
GIF:
Expand All @@ -21,6 +21,6 @@
<img height="100" byevent="1000"/>
<br/>
<br/>
<img style="width: 100%" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg"/>
<img style="width: 100%" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg"/>
</body>
</html>
6 changes: 3 additions & 3 deletions Source/Demo/Common/TestSamples/15.MaxWidth.htm
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ <h2>
metus. Integer leo dolor, tristique a, dignissim ac, iaculis eget, elit. Donec arcu.
</p>
<div>The image should also be limited by size because it has: <code><span color="red">style</span><span color="blue">="</span><span color="maroon">width</span><span color="blue">:90%"</span></code></div>
<img style="width: 90%" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg"/>
<img style="width: 500px; max-width: 90%" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg"/>
<img style="width: 90%" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg"/>
<img style="width: 500px; max-width: 90%" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg"/>
<p style="margin: 0 200px">
<img style="width: 500px; max-width: 90%" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg"/>
<img style="width: 500px; max-width: 90%" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg"/>
</p>
</div>
</body>
Expand Down
98 changes: 49 additions & 49 deletions Source/Demo/Common/TestSamples/19.Many images.htm
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,102 @@
<body>
<h2>Contains many images that should not load until in scroll view</h2>
<h3>Image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
<h3>Another image</h3>
<img width="500" src="http://www.canadianpetconnection.com/wp-content/uploads/2011/09/Cats1.jpg" />
<img width="500" src="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg" />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\HtmlRenderer.Core\HtmlRenderer.Core.csproj" />
<ProjectReference Include="..\..\..\HtmlRenderer.PdfSharp.Core\HtmlRenderer.PdfSharp.Core.csproj" />
<ProjectReference Include="..\..\..\HtmlRenderer.SkiaSharp\HtmlRenderer.SkiaSharp.csproj" />
<ProjectReference Include="..\..\Common\HtmlRenderer.Demo.Common.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TheArtOfDev.HtmlRenderer.Demo.Common;
using TheArtOfDev.HtmlRenderer.PdfSharp;

namespace HtmlRenderer.Demo.Console
{
public class PdfSharpCoreConverter : SampleConverterBase
{
public PdfSharpCoreConverter(string sampleRunIdentifier, string basePath) : base(sampleRunIdentifier, basePath)
{
}

public void GenerateSample(HtmlSample sample)
{
var config = new PdfGenerateConfig();

config.PageSize = PdfSharpCore.PageSize.A4;
config.MarginLeft = 0;
config.MarginRight = 0;
config.MarginTop = 0;
config.MarginBottom = 0;

var pdf = PdfGenerator.GeneratePdf(sample.Html, config, base.CssData, base.StylesheetLoad, base.ImageLoad);
pdf.Save(GetSamplePath(sample));
}
}
}
30 changes: 30 additions & 0 deletions Source/Demo/Console/HtmlRenderer.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HtmlRenderer.Demo.Console;
using System.Diagnostics;
using TheArtOfDev.HtmlRenderer.Demo.Common;

//By default, write to a sub folder 'output'
string basePath= @".\Ouput";
if (args.Length > 0)
{
//And if there's an output path given, use that.
basePath = args[0];
}

//Probably won't be running a suite of tests more than once a second, so this will do.
string runIdentifier = DateTime.Now.ToString("ddMMyyyy-hhMMss");

var skia = new SkiaConverter(runIdentifier, basePath);
var pdfSharp = new PdfSharpCoreConverter(runIdentifier, basePath);

SamplesLoader.Init("Console", typeof(Program).Assembly.GetName().Version.ToString());

var samples = SamplesLoader.TestSamples;

foreach (var htmlSample in samples)
{
skia.GenerateSample(htmlSample);
pdfSharp.GenerateSample(htmlSample);
}


//At this point.. there should be something!!
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"HtmlRenderer.Demo.Console": {
"commandName": "Project",
"commandLineArgs": "..\\..\\..\\Output"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using TheArtOfDev.HtmlRenderer.Demo.Common;

namespace HtmlRenderer.Demo.Console
{
public class SampleConverterBase
{
private string _sampleRunIdentifier;
private string _thisTypeName;
private string _basePath;

public SampleConverterBase(string sampleRunIdentifier, string basePath)
{
_sampleRunIdentifier = sampleRunIdentifier;
_basePath = basePath;
_thisTypeName = this.GetType().Name;
}

protected string GetSamplePath(HtmlSample sample)
{
var path = Path.Combine(_basePath, _sampleRunIdentifier);
Directory.CreateDirectory(path);
return Path.Combine(path, sample.FullName + _thisTypeName + "_" + ".pdf");
}
}
}
36 changes: 36 additions & 0 deletions Source/Demo/Console/HtmlRenderer.Demo.Console/SkiaConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TheArtOfDev.HtmlRenderer.Demo.Common;
using TheArtOfDev.HtmlRenderer.SkiaSharp;

namespace HtmlRenderer.Demo.Console
{
public class SkiaConverter : SampleConverterBase
{
public SkiaConverter(string sampleRunIdentifier, string basePath) : base(sampleRunIdentifier, basePath)
{
}

public void GenerateSample(HtmlSample sample)
{
var config = new PdfGenerateConfig();

config.PageSize = PageSizeType.A4;
//TODO: 'Units' on config, rather than this c/p 🤮
config.MarginLeft = PdfGenerateConfig.MilimitersToPixels(0);
config.MarginRight = PdfGenerateConfig.MilimitersToPixels(0);
config.MarginTop = PdfGenerateConfig.MilimitersToPixels(0);
config.MarginBottom = PdfGenerateConfig.MilimitersToPixels(0);

var pdf = PdfGenerator.GeneratePdf(sample.Html, config, base.CssData, base.StylesheetLoad, base.ImageLoad);
using (var fileStream = File.Open(GetSamplePath(sample), FileMode.CreateNew))
{
pdf.CopyTo(fileStream);
fileStream.Flush();
}
}
}
}
Loading