我正在尝试将 SqlData 导出为 pdf,为此我正在尝试获取数据列表以进行打印预览。我已按照此示例进行操作。 http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-pdf.html这里显示了 GridView 数据。但是我做了一些修改并尝试在 DataList 上获取数据。现在一切正常,我能够打印 DataList 的预览。只有一个问题,我想限制数据的数量每页显示..就像我只想限制每页 pdf 10 行。有人知道如何实现这样的功能吗?
简而言之,我需要在导出的 pdf 上使用分页符功能,here我现在得到的是 pdf
对不起,如果我的问题太简单了,但我是 Asp.Net 的新手
谢谢
最佳答案
该链接上显示的方法比较简单,但您可以修改它来解决您的问题。这是一些代码:
using System.Diagnostics;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace RowsCountSample
{
class Program
{
static void Main(string[] args)
{
using (var pdfDoc = new Document(PageSize.A4))
{
var pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream("Test.pdf", FileMode.Create));
pdfDoc.Open();
var table1 = new PdfPTable(3);
table1.HeaderRows = 2;
table1.FooterRows = 1;
//header row
var headerCell = new PdfPCell(new Phrase("header"));
headerCell.Colspan = 3;
headerCell.HorizontalAlignment = Element.ALIGN_CENTER;
table1.AddCell(headerCell);
//footer row
var footerCell = new PdfPCell(new Phrase("footer"));
footerCell.Colspan = 3;
footerCell.HorizontalAlignment = Element.ALIGN_CENTER;
table1.AddCell(footerCell);
//adding some rows
for (int i = 0; i < 70; i++)
{
//adds a new row
table1.AddCell(new Phrase("Cell[0], Row[" + i + "]"));
table1.AddCell(new Phrase("Cell[1], Row[" + i + "]"));
table1.AddCell(new Phrase("Cell[2], Row[" + i + "]"));
//sets the number of rows per page
if (i > 0 && table1.Rows.Count % 7 == 0)
{
pdfDoc.Add(table1);
table1.DeleteBodyRows();
pdfDoc.NewPage();
}
}
pdfDoc.Add(table1);
}
//open the final file with adobe reader for instance.
Process.Start("Test.pdf");
}
}
}
关于c# - 将 Datalist 导出为每页限制行的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20142937/