public string RenderSummaryInternal(SummaryDocument summary) { // for how-to see lib\dotnetrtfwriter\demo\program.cs & \demo_psa_summary_rtf\program.cs // Create document by specifying paper size and orientation, and default language. RtfDocument doc = new RtfDocument(PaperSize.A4, PaperOrientation.Portrait, Lcid.TraditionalChinese); // Create fonts and colors for later use FontDescriptor courier = doc.CreateFont("Courier New"); // Don't instantiate RtfTable, RtfParagraph, and RtfImage objects by using // ``new'' keyword. Instead, use add* method in objects derived from // RtfBlockList class. (See Demos.) RtfParagraph svmrParagraph, hrvParagraph, finalParagraph; // Don't instantiate RtfCharFormat by using ``new'' keyword, either. // An addCharFormat method are provided by RtfParagraph objects. RtfCharFormat fmt; AddDefParagraph(doc, courier, courier).SetText(strings.SummaryText_P0_Format_Name + summary.Employee.ToString()); AddDefParagraph(doc, courier, courier).SetText(strings.SummaryText_P1_Format_Date + summary.CompletionTime.ToString(strings.SummaryText_DateFormat)); AddDefParagraph(doc, courier, courier).SetText(strings.SummaryText_P2_Format_Workstation + summary.HostName); AddDefParagraph(doc, courier, courier).SetText(strings.SummaryText_Separator); var hrvHeader = strings.SummaryText_P3_Format_HRV + $"{summary.HrvConclusion.TestId,8}" + Formatter.DefaultSpacing; var hrvStatus = summary.HrvConclusion.Text; var svmrHeader = strings.SummaryText_P4_Format_SVMR + $"{summary.SvmrConclusion.TestId,8}" + Formatter.DefaultSpacing; var svmrStatus = summary.SvmrConclusion.Text; AddDefParagraph(doc, courier, courier, out hrvParagraph).SetText(hrvHeader + hrvStatus); AddDefParagraph(doc, courier, courier, out svmrParagraph).SetText(svmrHeader + svmrStatus); AddDefParagraph(doc, courier, courier).SetText(" "); AddDefParagraph(doc, courier, courier, out finalParagraph).SetText(summary.FinalConclusion.Text); _log.Debug("HRV paragraph: " + hrvParagraph.Text); _log.Debug("SVMR paragraph: " + svmrParagraph.Text); _log.Debug($"hrv_header.Length = {hrvHeader.Length,4} ; hrv_status.Length = {hrvStatus.Length,4}"); _log.Debug($"svmr_header.Length = {svmrHeader.Length,4} ; svmr_status.Length = {svmrStatus.Length,4}"); // format HRV conclusion fmt = hrvParagraph.AddCharFormat(hrvHeader.Length, hrvHeader.Length + hrvStatus.Length - 1); var hrvStatusColor = PsaStatusColorProvider.StatusColor(summary.HrvConclusion.Status); fmt.FgColor = doc.CreateColor(hrvStatusColor); // fmt.FontStyle.addStyle(FontStyleFlag.Bold); // format SVMR conclusion fmt = svmrParagraph.AddCharFormat(svmrHeader.Length, svmrHeader.Length + svmrStatus.Length - 1); var svmrStatusColor = PsaStatusColorProvider.StatusColor(summary.SvmrConclusion.Status); fmt.FgColor = doc.CreateColor(svmrStatusColor); // fmt.FontStyle.addStyle(FontStyleFlag.Bold); // format final conclusion fmt = finalParagraph.AddCharFormat(0, summary.FinalConclusion.Text.Length - 1); var finalStatusColor = PsaStatusColorProvider.StatusColor(summary.FinalConclusion.Status); fmt.FgColor = doc.CreateColor(finalStatusColor); return(doc.Render()); }