forked from cyotek/HTML-Renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (65 loc) · 3.15 KB
/
Copy pathProgram.cs
File metadata and controls
76 lines (65 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace HtmlRenderer.Demo
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
{
// TestPrint();
// TestImage1();
// return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new DemoForm());
// Application.Run(new PerfForm());
// PerfForm.Run();
}
private static void TestImage1()
{
var html1 = "<p><h2>Hellow</h2><img height='80' src='d:\\b.png'/><h2>world</h2><img height='80' src='http://i.tinyuploads.com/Co66A2.jpg'/><h2>bla</h2></p>";
var img = HtmlRender.RenderToImageGdiPlus(html1, new Size(600, 400));
img.Save(@"d:\test1.png", ImageFormat.Png);
}
private static void TestImage2()
{
var html1 = "<p style='font-size:2em;color: gray'>This is an <b>HtmlLabel</b> on transparent background with <span style='color: red'>colors</span> and links: <a href='http://htmlrenderer.codeplex.com/'>HTML Renderer</a></p>";
var img = HtmlRender.RenderToImageGdiPlus(html1, new Size(600, 200));
// var img = HtmlRender.RenderToImage(html, new Size(600, 200));
img.Save(@"d:\test1.png", ImageFormat.Png);
var image = Image.FromFile(@"d:\b.png");
HtmlRender.RenderToImage(image, html1, new Point(50, 0), new Size(620, 0));
image.Save(@"d:\test2.png");
var html2 = "<html><body style=\"margin: 0px; height: 461px; background-image:url(d:/b.png);background-repeat:no-repeat;\"><h1 style=\" margin-top:40px;margin-left:150px;\">"
+ "<span style=\"font-family:Monotype Corsiva;\"><em>Test HTML</em></span></h1><div style=\"width:560px;height:200px;margin-top:120px;margin-right:55px;margin-left:150px;\"><em>"
+ "<span style=\"font-family:Monotype Corsiva;\"><span style=\"font-size:22px;\">Some Text Here</span></span></em></div></body></html>";
var img2 = HtmlRender.RenderToImage(html2, new Size(755, 461));
img2.Save(@"d:\test3.png", ImageFormat.Png);
}
private static void TestPrint()
{
var html = "<p style='font-size:3em;color: gray'>This is an <b>HtmlLabel</b> on transparent background with <span style='color: red'>colors</span> and links: <a href='http://htmlrenderer.codeplex.com/'>HTML Renderer</a></p>";
var doc = new PrintDocument();
doc.PrintPage += (sender, args) => HtmlRender.RenderGdiPlus(args.Graphics, html, args.MarginBounds.Location, args.MarginBounds.Size);
doc.Print();
}
}
}