我用itextsharp生成pdf
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
StringBuilder sb = BuildData();
StringReader sr = new StringReader(sb.ToString());
Document pdfDoc = new Document(new iTextSharp.text.Rectangle(288f, 144f), 20, 20, 40, 20);
pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4);
//save
System.IO.FileStream fs = new System.IO.FileStream(DestinationPath + fileName, System.IO.FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, fs);
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
fs.Close();
fs.Dispose();
}
}
private StringBuilder BuildData()
{
StringBuilder sb = new StringBuilder();
sb.Append("<table>");
sb.Append("<tbody>");
//loop Repeater and get data here
sb.Append("</tbody></table>");
return sb;
}
我能够成功生成PDF但我的问题是我希望在某些条件下将数据打印成3页。
我怎样才能实现这一目标?请帮帮我
答案 0 :(得分:0)
我通过在html表中添加分页来修复它,它运行正常
<p style='page-break-before:always;'></p>