Adding text to PDF for Silverlight documents is easy – all the work is done by the C1PdfDocument.DrawString method.
C1PdfDocument.DrawString draws a given string at a specified location using a given font and brush. For example:
pdf.DrawString("Hello World!", font, Colors.Black, rect)
•C#
pdf.DrawString("Hello World!", font, Colors.Black, rect);
By default, C1PdfDocument.DrawString will align the text to the left and to the top of the given rectangle, will wrap the string within the rectangle, and will not clip the output to the rectangle. You can change all these options by specifying a StringFormat parameter in the call to C1PdfDocument.DrawString. The StringFormat has members that allow you to specify the horizontal alignment (Alignment), vertical alignment (LineAligmnent), and flags that control wrapping and clipping (FormatFlags).
For example, the code below creates a StringFormat object and uses it to align the text to the center of the rectangle, both vertically and horizontally:
Dim font As New Font("Arial", 12)
Dim rect As New Rect(72, 72, 100, 50)
Dim text As String = "Some long string to be rendered into a small rectangle. "
text = text & text & text & text & text & text
' Center align string.
Dim sf As New StringFormat()
sf.Alignment = HorizontalAlignment.Center
sf.LineAlignment = VerticalAlignment.Center
pdf.DrawString(text, font, Colors.Black, rect, sf)
pdf.DrawRectangle(Pens.Gray, rect)
•C#
Font font = new Font("Arial", 12);
Rect rect = new Rect(72, 72, 100, 50);
string text = "Some long string to be rendered into a small rectangle. ";
text = text + text + text + text + text + text;
// Center align string.
StringFormat sf = new StringFormat();
sf.Alignment = HorizontalAlignment.Center;
sf.LineAlignment = VerticalAlignment.Center;
pdf.DrawString(text, font, Colors.Black, rect, sf);
pdf.DrawRectangle(Pens.Gray, rect);
Here is the resulting PDF document: