为ITextSharp格式化HTML

时间:2018-08-15 06:17:46

标签: c# itext

尝试实现这一目标(使用htmlpdf转换为itextsharp): enter image description here

使用:

  StringBuilder pdfHtmlBody = new StringBuilder();

                    pdfHtmlBody.Append("<table cellspacing='2' width='100%'>");

                    foreach (var scoreSheetItem in reportCardList)
                    {





                        pdfHtmlBody.Append("<tr>");
                        pdfHtmlBody.Append("<th></th>");
                        foreach(var header in scoreSheetItem.ReportHeader)
                        {
                            pdfHtmlBody.Append("<th>");

                            pdfHtmlBody.Append(header.HeaderTitle);

                            pdfHtmlBody.Append("</th>");

                        }


                        pdfHtmlBody.Append("<th></th>");

                        pdfHtmlBody.Append("</tr>");



                        foreach (var item in scoreSheetItem.ScoreSheet)
                        {
                            pdfHtmlBody.Append("<tr>");

                            pdfHtmlBody.Append("<td>");
                            pdfHtmlBody.Append(item.Subject);
                            pdfHtmlBody.Append("</td>");
                            pdfHtmlBody.Append("<td>");

                            pdfHtmlBody.Append(item.TotalCAScore == null ? "-" : item.TotalCAScore);

                            pdfHtmlBody.Append("</td>");
                            pdfHtmlBody.Append("<td>");
                            pdfHtmlBody.Append(item.TotalExamScore == null ? "-" : item.TotalExamScore);
                            pdfHtmlBody.Append("</td>");

                            foreach(var col in item.Cummulative)
                            {
                                pdfHtmlBody.Append("<td>");
                                pdfHtmlBody.Append(col.TotalScore == null ? "-" : col.TotalScore);
                                pdfHtmlBody.Append("</td>");
                            }



                                         pdfHtmlBody.Append("<td>");
                            pdfHtmlBody.Append(item.GradeLabel);
                            pdfHtmlBody.Append("</td>");


                            pdfHtmlBody.Append("<td>");
                            pdfHtmlBody.Append(item.GradeInterpretation);
                            pdfHtmlBody.Append("</td>");




                                                     pdfHtmlBody.Append("</tr>");

                        }



                    }

                    pdfHtmlBody.Append("</table>");

获取此结果代替: enter image description here

注意:在stack上发现的类似问题无法解决该问题

0 个答案:

没有答案