使用iText生成PDF时rowspan出现问题

使用iText生成PDF时rowspan出现问题,itext,Itext,下面是我的示例应用程序,我在其中遇到了一个在线错误 Add2CellRow(表“年龄”,1,“性别”,2) 我认为rowspan值造成了问题,因为下一行没有生成 有人能帮忙吗 代码是针对阿拉伯文化的,因此需要设置 Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA"); private stat

下面是我的示例应用程序,我在其中遇到了一个在线错误 Add2CellRow(表“年龄”,1,“性别”,2)

我认为rowspan值造成了问题,因为下一行没有生成

有人能帮忙吗

代码是针对阿拉伯文化的,因此需要设置

Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SA");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA");

private static void Add3CellRow(PdfPTable table, string cell1Value, string cell2Value, int rowspan, string imgPath) 
{

    PdfPCell new1Cell = new PdfPCell(new Phrase(cell1Value, tableFont));
    new1Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
    new1Cell.MinimumHeight = 25f;
    new1Cell.Padding = 6f;
    table.AddCell(new1Cell);

    PdfPCell new2Cell = new PdfPCell(new Phrase(cell2Value, tableFont));
    new2Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
    new2Cell.MinimumHeight = 25f;
    new2Cell.Padding = 6f;
    new2Cell.Colspan = 2;
    table.AddCell(new2Cell);

    PdfPCell new3Cell = null;

    if (!String.IsNullOrWhiteSpace(imgPath))
    {
        Image img = Image.GetInstance(imgPath);
        img.ScaleToFit(150, 150);
        new3Cell = new PdfPCell(img);
    }
    else
    {
        new3Cell = new PdfPCell(new Phrase(String.Empty));
    }

    new3Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
    new3Cell.HorizontalAlignment = Element.ALIGN_CENTER;
    new3Cell.MinimumHeight = 25f;
    new3Cell.Rowspan = rowspan;
    new3Cell.Colspan = 2;
    new3Cell.Padding = 6f;
    table.AddCell(new3Cell);
}             

private static void Add2CellRow(PdfPTable table, string cell1Value, int colspanCell1, string cell2Value, int colspanCell2 = 2)
{
    PdfPCell new1Cell = new PdfPCell(new Phrase(cell1Value, tableFont));
    new1Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
    new1Cell.MinimumHeight = 25f;
    new1Cell.Colspan = colspanCell1;
    table.AddCell(new1Cell);

    PdfPCell new2Cell = new PdfPCell(new Phrase(cell2Value, tableFont));
    new2Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
    new2Cell.Colspan = colspanCell2;
    new2Cell.MinimumHeight = 25f;
    new2Cell.Padding = 6f;
    table.AddCell(new2Cell);
}

public static MemoryStream Generate()
{                        
    var doc = new Document(PageSize.A4, 10, 10, 90, 110);

    MemoryStream memoryStream = new MemoryStream();
    PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);            

    doc.Open();

    PdfPTable table = new PdfPTable(5);

    table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;


    table.WidthPercentage = 89.5f;
    table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
    table.DefaultCell.Padding = 6f;
    table.DefaultCell.UseAscender = true;
    table.DefaultCell.UseDescender = true;

    Add3CellRow(table,"Name","Harshit Verma",4,"");            
    Add2CellRow(table, "Age", 1, "Gender", 2);
    Add2CellRow(table, "Age", 1, "Gender", 2);
    Add2CellRow(table, "Age", 1, "Gender", 2);

    table.SplitLate = false;

    Paragraph p = new Paragraph("");
    doc.Add(p);
    table.SpacingBefore = 30f;
    doc.Add(table);

    writer.CloseStream = false;
    doc.Close();
    memoryStream.Position = 0;

    return memoryStream;
}

有很多行和列的跨度,这让我头疼,但我终于能够重现你的问题。当表格在
LTR
模式下运行时,一切正常,但是当切换到
RTL
模式时,我会得到
系统。IndexOutOfRangeException
异常来自iTextSharp 5.5.5.0(我本地仅有的一个)。我也遇到了同样的问题。在RTL中,如果您删除rowsapn并创建PDF,它也可以正常工作。这看起来应该发布到而不是StackOverflow。@Bruno不是成员。无法登录。@Nikita仅供客户使用。请您的项目经理了解您是否是客户。如果您在商业环境中使用iText(您似乎正在这样做),您应该这样做。在这种情况下,最多有三名同事登录。