Skip to content

Commit 74af9c0

Browse files
committed
Adding CSS styling example
1 parent b7a51f1 commit 74af9c0

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

Documentation/PDFGeneration.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1-
Generate PDF
1+
**Generate PDF**
22

3+
IN order to get started, add the following snippet in your main method:
4+
5+
```
6+
class Program
7+
{
8+
private static void Main(string[] args)
9+
{
10+
string html = "<p><h1>Hello World</h1>This is html rendered text</p>";
11+
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4);
12+
pdf.Save("document.pdf");
13+
}
14+
}
15+
```
16+
17+
**Applying CSS**
18+
19+
Adjust your HTML to include a class definition to customize html within your text.
20+
21+
```
22+
string html = "<p><h1>Hello World</h1>This is html rendered text <span class='blue'>with css styling in blue</span></p>";
23+
```
24+
25+
Add a new css definition
26+
```
27+
string css = ".blue { color: blue; } ";
28+
```
29+
30+
Adjust your GeneratePdf parameters to include style sheet parsing and a margin setting matching the default of 20
31+
```
32+
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4, 20, PdfGenerator.ParseStyleSheet(css));
33+
```
34+
35+
Your code should now look like this
36+
```
37+
class Program
38+
{
39+
private static void Main(string[] args)
40+
{
41+
string html = "<p><h1>Hello World</h1>This is html rendered text <span class='blue'>with css styling in blue</span></p>";
42+
string css = ".blue { color: blue; }";
43+
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4, 20, PdfGenerator.ParseStyleSheet(css));
44+
pdf.Save("document.pdf");
45+
}
46+
}
47+
```
48+
49+
If you run this code you should now see your sample with some styled text

0 commit comments

Comments
 (0)