private string[] Paginate(StringBuilder fullText, CairoFont font, double pageWidth, double pageHeight, double lineHeight) { TextSizeProber prober = new TextSizeProber(); Stack <string> lines = new Stack <string>(prober.InsertAutoLineBreaks(font, fullText, pageWidth).Reverse()); double lineheight = prober.GetLineHeight(font, lineHeight); int maxlinesPerPage = (int)(pageHeight / lineheight); List <string> pagesTemp = new List <string>(); StringBuilder pageBuilder = new StringBuilder(); while (lines.Count > 0) { int currentPageLines = 0; while (currentPageLines < maxlinesPerPage && lines.Count > 0) { string line = lines.Pop(); string[] parts = line.Split(new string[] { "___NEWPAGE___" }, 2, StringSplitOptions.None); if (parts.Length > 1) { pageBuilder.AppendLine(parts[0]); if (parts[1].Length > 0) { lines.Push(parts[1]); } break; } currentPageLines++; pageBuilder.AppendLine(line); } string pageText = pageBuilder.ToString().TrimEnd(); if (pageText.Length > 0) { pagesTemp.Add(pageText); } pageBuilder.Clear(); } return(pagesTemp.ToArray()); }