PDF for WPF and Silverlight Overview > Features: PDF for WPF and Silverlight > Adding Text > Making Text Flow From Page to Page |
The C1PdfDocument.DrawString method returns an integer. This is the index of the first character that was not printed because it did not fit the output rectangle. You can use this value make text flow from page to page or from one frame to another within a page. For example:
VB |
Copy Code
|
---|---|
Dim font As New C1.WPF.Pdf.Font("Arial", 12) Dim rect As New Rect(72, 72, 100, 50) Dim text As String = "This is the random text...This is the random text...This is the random text...This is the random text..." ' Render a string spanning multiple pages. While True ' Render as much as will fit into the rectangle. Dim nextChar As Integer = pdf.DrawString(text, font, Colors.Black, rect) pdf.DrawRectangle(Colors.LightGray, rect) ' Break when done. If nextChar >= text.Length Then Exit While End If ' Get rid of the part that was rendered. text = text.Substring(nextChar) ' Move on to the next page. pdf.NewPage() End While |
C# |
Copy Code
|
---|---|
C1.WPF.Pdf.Font font = new C1.WPF.Pdf.Font("Arial", 12); Rect rect = new Rect(72, 72, 100, 50); string text = "This is the random text...This is the random text...This is the random text...This is the random text..."; // Render a string spanning multiple pages. while (true) { // Render as much as will fit into the rectangle. int nextChar = pdf.DrawString(text, font, Colors.Black, rect); pdf.DrawRectangle(Colors.LightGray, rect); // Break when done. if (nextChar >= text.Length) { break; } // Get rid of the part that was rendered. text = text.Substring(nextChar); // Move on to the next page. pdf.NewPage(); } |
Rect rect = pdf.PageRectangle();
rect.Inflate(-72, -72);
// Stretch image to fill the rectangle.
pdf.DrawImage(pictureBox1.Image, rect);
// Center image within the rectangle, scale keeping aspect ratio.
pdf.DrawImage(pictureBox1.Image, rect, ContentAlignment.MiddleCenter, C1.WPF.Pdf.ImageSizeModeEnum.Scale);
// Render the image to the top left corner of the rectangle.
pdf.DrawImage(pictureBox1.Image, rect, ContentAlignment.TopLeft, 1.C1Pdf.ImageSizeModeEnum.Clip);
By combining the C1PdfDocument.MeasureString and C1PdfDocument.DrawString methods, you can develop rendering routines that provide extensive control over how paragraphs are rendered, including keeping paragraphs together on a page, keeping with the next paragraph, and controlling widows and orphans (single lines that render on the current or next page).