gpt4 book ai didi

c# - 获取生成 PDF 的堆栈溢出异常

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:35 25 4
gpt4 key购买 nike

<分区>

作为我的 earlier question 的延续我一直在为我的 PDF 尝试页眉和页脚功能。经过一番讨论后,我更改了 PdfPageEventHelper 类上的很多代码。以下是我所拥有的:

public class ReportHeaderFooter : PdfPageEventHelper
{
public string HeaderTitle { get; set; }
public IReportsAccessor ReportsAccessor { get; set; }
private Image footerImg;
private Image headerImg;
private BaseColor headerColor;
private PdfPTable tblHeader;
public ReportHeaderFooter(IReportsAccessor reportsAccessor)
{
this.ReportsAccessor = reportsAccessor;
var rootPath = ConfigurationManager.AppSettings["SaveFileRootPath"];
headerColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#ffffff")); // Not really but I don't want to give away the color

}

public override void OnOpenDocument(PdfWriter writer, Document document)
{
base.OnOpenDocument(writer, document);
// Set the initial header image...
var headerImgInfo = ReportsAccessor.GetImage(4);
headerImg = Image.GetInstance(headerImgInfo.ReportImage);

// Set the initial footer image...
var footerImgInfo = ReportsAccessor.GetImage(2);
footerImg = Image.GetInstance(footerImgInfo.ReportImage);

// Create the header table...
tblHeader = new PdfPTable(2)
{
TotalWidth = document.Right,
};
tblHeader.SetWidths(new float[2] { document.Right - 70f, 70f });
PdfPCell titleCell = new PdfPCell(new Phrase(HeaderTitle))
{
BackgroundColor = headerColor
};
tblHeader.AddCell(titleCell);
PdfPCell imgCell = new PdfPCell(headerImg)
{
BackgroundColor = headerColor,
HorizontalAlignment = PdfPCell.ALIGN_RIGHT,
};
tblHeader.AddCell(imgCell);
}

public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
// Add the header table to the tops of the documents...
document.Add(tblHeader);

// Create the image at the footer.
footerImg.SetAbsolutePosition(0, document.Bottom);
document.Add(footerImg);
}

但是,当我到达其中一个页面上的 document.Add(tblHeader) 行时(这是一个相当大的 pdf(可能有 10 页))。我得到一个堆栈溢出异常)。

我在这里做错了什么(如果有的话)?我问的最后一个问题收到了礼貌的 RTM,但是,在阅读了大量文档后,我不明白为什么相对简单的事情会导致堆栈溢出。请帮助我理解。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com