forked from ivanagui2/PDFjet-Open-Source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example_31.cs
97 lines (74 loc) · 2.85 KB
/
Example_31.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using PDFjet.NET;
/**
* Example_31.cs
*/
public class Example_31 {
public Example_31() {
PDF pdf = new PDF(new BufferedStream(
new FileStream("Example_31.pdf", FileMode.Create)));
Page page = new Page(pdf, Letter.PORTRAIT);
Font f1 = new Font(pdf,
new FileStream("fonts/Noto/NotoSansDevanagari-Regular.ttf",
FileMode.Open,
FileAccess.Read));
f1.SetSize(15f);
Font f2 = new Font(pdf,
new FileStream("fonts/Droid/DroidSans.ttf",
FileMode.Open,
FileAccess.Read));
f2.SetSize(15f);
StringBuilder buf = new StringBuilder();
StreamReader reader = new StreamReader(
new FileStream("data/marathi.txt", FileMode.Open, FileAccess.Read));
String line = null;
while ((line = reader.ReadLine()) != null) {
buf.Append(line + "\n");
}
reader.Close();
TextBox textBox = new TextBox(f1, buf.ToString(), 500f, 300f);
textBox.SetFallbackFont(f2);
textBox.SetLocation(50f, 50f);
textBox.SetNoBorders();
textBox.DrawOn(page);
String str = "असम के बाद UP में भी CM कैंडिडेट का ऐलान करेगी BJP?";
TextLine textLine = new TextLine(f1, str);
textLine.SetFallbackFont(f2);
textLine.SetLocation(50f, 175f);
textLine.DrawOn(page);
page.SetPenColor(Color.blue);
page.SetBrushColor(Color.blue);
page.FillRect(50f, 200f, 200f, 200f);
GraphicsState gs = new GraphicsState();
gs.Set_CA(0.5f); // The stroking alpha constant
gs.Set_ca(0.5f); // The nonstroking alpha constant
page.SetGraphicsState(gs);
page.SetPenColor(Color.green);
page.SetBrushColor(Color.green);
page.FillRect(100f, 250f, 200f, 200f);
page.SetPenColor(Color.red);
page.SetBrushColor(Color.red);
page.FillRect(150, 300, 200f, 200f);
// Reset the parameters to the default values
page.SetGraphicsState(new GraphicsState());
page.SetPenColor(Color.orange);
page.SetBrushColor(Color.orange);
page.FillRect(200, 350, 200f, 200f);
page.SetBrushColor(0x00003865);
page.FillRect(50, 550, 200f, 200f);
pdf.Close();
}
public static void Main(String[] args) {
Stopwatch sw = Stopwatch.StartNew();
long time0 = sw.ElapsedMilliseconds;
new Example_31();
long time1 = sw.ElapsedMilliseconds;
sw.Stop();
Console.WriteLine("Example_31 => " + (time1 - time0));
}
} // End of Example_31.cs