尝试实现这一目标(使用html
将pdf
转换为itextsharp
):
使用:
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>");
注意:在stack
上发现的类似问题无法解决该问题