-
Notifications
You must be signed in to change notification settings - Fork 12
/
HtmlToPdfHelper.cs
48 lines (38 loc) · 1.37 KB
/
HtmlToPdfHelper.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace iDiTect.Converter.Demo
{
public static class HtmlToPdfHelper
{
public static void Convert()
{
HtmlToPdfConverter converter = new HtmlToPdfConverter();
//Load html from stream
using (Stream stream = File.OpenRead("sample.html"))
{
converter.Load(stream);
}
//Choose pdf compliance level, PDF or PDF/A
converter.PdfStandard = PdfStandard.Pdf;
//Convert html to pdf, and save it to file stream
using (var stream = File.OpenWrite("convert.pdf"))
{
converter.Save(stream);
}
}
public static void Convert2()
{
HtmlToPdfConverter converter = new HtmlToPdfConverter();
//Define the css for the html content
converter.DefaultStyleSheet = ".para{font-size: 24px; color: #FF0000;}";
string htmlContent = "<p class=\"para\">Content with special style.</p><p>Content without style</p>";
converter.Load(htmlContent);
//Choose pdf compliance level, PDF or PDF/A
converter.PdfStandard = PdfStandard.Pdf;
File.WriteAllBytes("convert.pdf", converter.SaveAsBytes());
}
}
}