You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用iTextSharp生成PDF表格时出现大空白页问题求助

iTextSharp生成PDF表格遇大面积空白问题

当收据包含大量单据时,用iTextSharp生成的PDF表格会出现大面积空白,直接跳转到新页面,示例如下:
问题示例图

填充表格的代码如下:

PdfPTable tablaGral = new PdfPTable(1);
 
PdfPTable tablaItems = new PdfPTable(9);
float[] widths2 = new float[] { 90f, 40f, 50f, 50f, 60f, 60f, 60f, 50f, 50f };
tablaItems.SetWidths(widths2);

PdfPCell pdfCellTipoComprobate = AgregarCelda("Tipo Comprobante", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, true);
pdfCellTipoComprobate.BorderWidthTop = 0f;
pdfCellTipoComprobate.BorderWidthLeft = 0f;
pdfCellTipoComprobate.BorderWidthBottom = 0.5f;

tablaItems.AddCell(pdfCellTipoComprobate);

tablaItems.AddCell(AgregarCelda("Pto. Venta", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
tablaItems.AddCell(AgregarCelda("Nro", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
tablaItems.AddCell(AgregarCelda("Fecha", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
tablaItems.AddCell(AgregarCelda("Total", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
tablaItems.AddCell(AgregarCelda("Monto Aplicado", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
tablaItems.AddCell(AgregarCelda("Saldo", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
tablaItems.AddCell(AgregarCelda("Moneda", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, false));
PdfPCell pdfCellPTotal = AgregarCelda("Cotizacion", FontEncabezados6, 0, Element.ALIGN_CENTER, Element.ALIGN_CENTER, true);
pdfCellPTotal.BorderWidthTop = 0f;
pdfCellPTotal.BorderWidthBottom = 0.5f;
pdfCellPTotal.BorderWidthRight = 0f;
tablaItems.AddCell(pdfCellPTotal);

int contador = 0;
int cantidad = lstReciboFactura.Count;
foreach (ReciboFactura rf in lstReciboFactura)
{
    string tipoDocumento = rf.TipoComprobanteNombre;
    PdfPCell pdfCellTipoComprobanteValue = AgregarCelda(tipoDocumento, FontDetalle6, 0, Element.ALIGN_LEFT, Element.ALIGN_CENTER, true);
    pdfCellTipoComprobanteValue.BorderWidthLeft = 0f;
    pdfCellTipoComprobanteValue.BorderWidthRight = 0f;

    tablaItems.AddCell(pdfCellTipoComprobanteValue);
    
    string ptoVenta = rf.PtoVenta == 0 ? "" : rf.PtoVenta.ToString("0000");
    PdfPCell pdfCellPtoVentaValue = AgregarCelda(ptoVenta, FontDetalle6, 0, Element.ALIGN_CENTER, Element.ALIGN_RIGHT, true);

    pdfCellPtoVentaValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellPtoVentaValue);

    PdfPCell pdfCellNroValue = AgregarCelda(rf.NroComprobante.ToString("000000000"), FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellNroValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellNroValue);

    PdfPCell pdfCellPUnitarionValue = AgregarCelda(rf.FechaStr, FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellPUnitarionValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellPUnitarionValue);

    PdfPCell pdfCellPUnitarionGravadoValue = AgregarCelda((rf.Importe).ToString("0,0.00"), FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellPUnitarionGravadoValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellPUnitarionGravadoValue);

    PdfPCell pdfCellPUnitarionNoGravadoValue = AgregarCelda(rf.MontoAplicado.ToString("0,0.00"), FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellPUnitarionNoGravadoValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellPUnitarionNoGravadoValue);

    PdfPCell pdfCellSaldoFacturaValue = AgregarCelda(rf.SaldoFactura.ToString("0,0.00"), FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellSaldoFacturaValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellSaldoFacturaValue);

    PdfPCell pdfCellMonedaValue = AgregarCelda(rf.MonedaStr, FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellMonedaValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellMonedaValue);

    string cotizacion = rf.MonedaId == 4 ? "1" : rf.Cotizacion.ToString("0,0.00");
    PdfPCell pdfCellCotizacionValue = AgregarCelda(cotizacion, FontDetalle6, 0, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, true);
    pdfCellCotizacionValue.BorderWidthRight = 0f;
    tablaItems.AddCell(pdfCellCotizacionValue);

    contador++;

    if (contador == 30 || contador == cantidad) //Used to make a line every 30 receipts.
    {
        PdfPCell celdaTable2 = new PdfPCell(tablaItems);
        tablaGral.AddCell(celdaTable2);

        tablaItems.DeleteBodyRows();

        contador = 0;
    }            
}

PdfPCell celdaGral2 = new PdfPCell(tablaGral);
celdaGral2.MinimumHeight = 300f;// : 440f;
table.AddCell(celdaGral2);

我已经尝试多种解决方案,但始终无法解决这个空白问题。


内容的提问来源于stack exchange,提问作者Ronald Petrussa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 18:52:01