在将PDF与iTextSharp合并时构建PDF书签

时间:2015-11-03 13:33:10

标签: c# pdf itextsharp bookmarks

我正在使用iTextSharp将PDF合并到一个循环中。在同一个循环中,我创建了应该有3个级别的书签(章节,章节,小节)。每个条目都正确显示3级结构,但不属于同一章节,部分或子部分的页面。

怎么做? 此致,马丁

private void MergePDFs()
{
    DataSourceSelectArguments args = new DataSourceSelectArguments();
    DataView view = (DataView)SqlDataSource1.Select(args);

    DataTable table = view.ToTable();
    List<PdfReader> readerList = new List<PdfReader>();

    Document document = new Document();
    PdfCopy copy = new PdfCopy(document, Response.OutputStream);
    document.Open();

    foreach (DataRow myRow in table.Rows)
    {

        PdfReader Reader = new PdfReader(Convert.ToString(myRow[0]));

        Chapter Chapter = new Chapter(Convert.ToString(Convert.ToInt32(myRow[1])), 0);
        Chapter.NumberDepth = 0;
        Section Section = Chapter.AddSection(Convert.ToString(myRow[10]), 0);
        Section.NumberDepth = 0;
        Section SubSection = Section.AddSection(Convert.ToString(myRow[7]), 0);
        SubSection.NumberDepth = 0;
        document.Add(Chapter);

        readerList.Add(Reader);

        for (int i = 1; i <= Reader.NumberOfPages; i++)
        {
            copy.AddPage(copy.GetImportedPage(Reader, i));
        }
        Reader.Close();
    }

    document.Close();

    Response.AppendHeader("content-disposition", "inline; filename=OutPut.pdf");
    Response.ContentType = "application/pdf";
}

0 个答案:

没有答案