5 Private Sub ShowStripePattern(ByRef page As HPdfPage, ByVal x As Single, ByVal y As Single)
9 page.SetRGBStroke(0.0F, 0.0F, 0.5F)
11 page.MoveTo(x, y + iy)
12 page.LineTo(x + page.TextWidth("ABCabc123"), y + iy)
18 page.SetLineWidth(2.5F)
21 Private Sub ShowDescription(ByRef page As HPdfPage, ByVal x As Single, ByVal y As Single, ByVal text As String)
22 Dim fsize As Single = page.GetCurrentFontSize()
23 Dim font As HPdfFont = page.GetCurrentFont()
24 Dim c As HPdfRGBColor = page.GetRGBFill()
27 page.SetRGBFill(0, 0, 0)
28 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL)
29 page.SetFontAndSize(font, 10)
30 page.TextOut(x, y - 12, text)
33 page.SetFontAndSize(font, fsize)
34 page.SetRGBFill(c.r, c.g, c.b)
38 Const page_title As String = "Text Demo"
39 Const samp_text As String = "abcdefgABCDEFG123!#$%&+-@?"
40 Const samp_text2 As String = "The quick brown fox jumps over the lazy dog."
41 Console.WriteLine("libhpdf-" & HPdfDoc.HPdfGetVersion())
44 Dim pdf As HPdfDoc = New HPdfDoc()
46 pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL)
49 Dim font As HPdfFont = pdf.GetFont("Helvetica", Nothing)
51 ' add a new page object.
52 Dim page As HPdfPage = pdf.AddPage()
54 ' print the title of the page (with positioning center).
55 page.SetFontAndSize(font, 24)
56 Dim tw As Single = page.TextWidth(page_title)
58 page.TextOut((page.GetWidth() - tw) / 2, page.GetHeight() - 50, page_title)
62 page.MoveTextPos(60, page.GetHeight() - 60)
67 Dim fsize As Single = 8
70 ' set style and size of font.
71 page.SetFontAndSize(font, fsize)
73 ' set the position of the text.
74 page.MoveTextPos(0, -5 - fsize)
76 ' measure the number of characters which included in the page.
77 Dim tlen As UInt32 = page.MeasureText(samp_text, page.GetWidth() - 120, False)
79 page.ShowText(samp_text.Substring(0, tlen))
81 ' print the description.
82 page.MoveTextPos(0, -10)
83 page.SetFontAndSize(font, 8)
84 page.ShowText("Fontsize=" & fsize)
92 page.SetFontAndSize(font, 8)
93 page.MoveTextPos(0, -30)
94 page.ShowText("Font color")
96 page.SetFontAndSize(font, 18)
97 page.MoveTextPos(0, -20)
98 Dim len As Integer = samp_text.Length
100 For i As Integer = 0 To len - 1
103 Dim r As Single = i / len
104 Dim g As Single = 1 - (i / len)
105 buf = samp_text.Substring(i, 1)
107 page.SetRGBFill(r, g, 0)
111 page.MoveTextPos(0, -25)
113 For i As Integer = 0 To len - 1
116 Dim r As Single = i / len
117 Dim b As Single = 1 - (i / len)
118 buf = samp_text.Substring(i, 1)
120 page.SetRGBFill(r, 0, b)
124 page.MoveTextPos(0, -25)
126 For i As Integer = 0 To len - 1
129 Dim b As Single = i / len
130 Dim g As Single = 1 - (i / len)
131 buf = samp_text.Substring(i, 1)
133 page.SetRGBFill(0, g, b)
139 Dim ypos As Integer = 450
142 ' Font rendering mode
144 page.SetFontAndSize(font, 32)
145 page.SetRGBFill(0.5F, 0.5F, 0)
146 page.SetLineWidth(1.5F)
149 ShowDescription(page, 60, ypos, "RenderingMode=PDF_FILL")
150 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL)
152 page.TextOut(60, ypos, "ABCabc123")
156 ShowDescription(page, 60, ypos - 50, "RenderingMode=PDF_STROKE")
157 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_STROKE)
159 page.TextOut(60, ypos - 50, "ABCabc123")
162 ' PDF_FILL_THEN_STROKE
163 ShowDescription(page, 60, ypos - 100, "RenderingMode=PDF_FILL_THEN_STROKE")
164 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL_THEN_STROKE)
166 page.TextOut(60, ypos - 100, "ABCabc123")
170 ShowDescription(page, 60, ypos - 150, "RenderingMode=PDF_FILL_CLIPPING")
172 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL_CLIPPING)
174 page.TextOut(60, ypos - 150, "ABCabc123")
176 ShowStripePattern(page, 60, ypos - 150)
179 ' PDF_STROKE_CLIPPING
180 ShowDescription(page, 60, ypos - 200, "RenderingMode=PDF_STROKE_CLIPPING")
182 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_STROKE_CLIPPING)
184 page.TextOut(60, ypos - 200, "ABCabc123")
186 ShowStripePattern(page, 60, ypos - 200)
189 ' PDF_FILL_STROKE_CLIPPING
190 ShowDescription(page, 60, ypos - 250, "RenderingMode=PDF_FILL_STROKE_CLIPPING")
192 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL_STROKE_CLIPPING)
194 page.TextOut(60, ypos - 250, "ABCabc123")
196 ShowStripePattern(page, 60, ypos - 250)
199 ' Reset text attributes
200 page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL)
201 page.SetRGBFill(0, 0, 0)
202 page.SetFontAndSize(font, 30)
208 Dim angle1 As Single = 30 ' A rotation of 30 degrees.
209 Dim rad1 As Single = angle1 / 180 * 3.141592F ' Calculate the radian value.
211 ShowDescription(page, 320, ypos - 60, "Rotating text")
213 page.SetTextMatrix(Math.Cos(rad1), Math.Sin(rad1), -Math.Sin(rad1), Math.Cos(rad1), 330, ypos - 60)
214 page.ShowText("ABCabc123")
221 ShowDescription(page, 320, ypos - 120, "Skewing text")
225 Dim angle2 As Single = 20
226 rad1 = angle1 / 180 * 3.141592F
227 Dim rad2 As Single = angle2 / 180 * 3.141592F
229 page.SetTextMatrix(1, Math.Tan(rad1), Math.Tan(rad2), 1, 320, ypos - 120)
230 page.ShowText("ABCabc123")
235 ' scaling text (X direction)
237 ShowDescription(page, 320, ypos - 175, "Scaling text (X direction)")
239 page.SetTextMatrix(1.5F, 0, 0, 1, 320, ypos - 175)
240 page.ShowText("ABCabc12")
245 ' scaling text (Y direction)
247 ShowDescription(page, 320, ypos - 250, "Scaling text (Y direction)")
249 page.SetTextMatrix(1, 0, 0, 2, 320, ypos - 250)
250 page.ShowText("ABCabc123")
255 ' char spacing, word spacing
258 ShowDescription(page, 60, 140, "char-spacing 0")
259 ShowDescription(page, 60, 100, "char-spacing 1.5")
260 ShowDescription(page, 60, 60, "char-spacing 1.5, word-spacing 2.5")
262 page.SetFontAndSize(font, 20)
263 page.SetRGBFill(0.1F, 0.3F, 0.1F)
267 page.TextOut(60, 140, samp_text2)
271 page.SetCharSpace(1.5F)
274 page.TextOut(60, 100, samp_text2)
277 ' char-spacing 1.5, word-spacing 3.5
278 page.SetWordSpace(2.5F)
281 page.TextOut(60, 60, samp_text2)
284 ' save the document to a file
285 pdf.SaveToFile("TextDemo.pdf")
288 Catch ex As Exception
289 Console.Error.WriteLine(ex.Message)