/
ParagraphTextWithStyle.cs
48 lines (41 loc) · 1.43 KB
/
ParagraphTextWithStyle.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.IO;
using iText.IO.Font.Constants;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
namespace iText.Samples.Sandbox.Layout
{
public class ParagraphTextWithStyle
{
public static readonly String DEST = "results/sandbox/layout/paragraphTextWithStyle.pdf";
public static void Main(String[] args)
{
FileInfo file = new FileInfo(DEST);
file.Directory.Create();
new ParagraphTextWithStyle().ManipulatePdf(DEST);
}
protected void ManipulatePdf(String dest)
{
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
PdfFont code = PdfFontFactory.CreateFont(StandardFonts.COURIER);
Style style = new Style()
.SetFont(code)
.SetFontSize(14)
.SetFontColor(ColorConstants.RED)
.SetBackgroundColor(ColorConstants.LIGHT_GRAY);
Paragraph paragraph = new Paragraph()
.Add("In this example, named ")
.Add(new Text("HelloWorldStyles").AddStyle(style))
.Add(", we experiment with some text in ")
.Add(new Text("code style").AddStyle(style))
.Add(".");
using (Document document = new Document(pdf))
{
document.Add(paragraph);
}
}
}
}