简体   繁体   English

将Datalist导出为PDF,每页限制行数

[英]Export Datalist to PDF with restricted rows per Page

I am trying to export SqlData to pdf,for that i am trying to get data list to print preview.I have followed this example. 我正在尝试将SqlData导出为pdf,因为我正在尝试获取数据列表以打印预览。我已经按照这个示例。 http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-pdf.html here grid view data Displayed.But I have done some modification and tried to to take data on DataList.Now every thing works fine,I am able to take print preview of DataList.Only one problem is there,I want to restrict number of data display per page..Like i just want to Restrict 10Row per single page of pdf.Any one have idea how to achieve such functionality? http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-pdf.html此处显示网格视图数据。但我做了一些修改并试图获取数据DataList.Now每件事都运行正常,我能够进行DataList的打印预览。只有一个问题就在那里,我想限制每页数据显示数量。就像我只想限制10Row每页pdf.Any一个人有想法如何实现这样的功能?

In short i need a page break functionality on exported pdf, here is pdf i am getting currently 简而言之,我需要在导出的pdf上使用分页功能, 这里是我目前正在获取的pdf

Sorry for if my question is too simple,But i am newbie on Asp.Net 很抱歉,如果我的问题太简单了,但我是Asp.Net的新手

Thanks 谢谢

The approach show on that link is bit simpler but you can modify that to resolve your problem. 该链接上的方法显示有点简单,但您可以修改它以解决您的问题。 Here is a bit of code: 这是一些代码:

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");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM