"'System.StackOverflowException"在"&的OnEndPage QUOT;事件处理程序 [英] "'System.StackOverflowException" in "OnEndPage" event handler

查看:164
本文介绍了"'System.StackOverflowException"在"&的OnEndPage QUOT;事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码,你可以看到,我推翻的OnEndPage 事件,并试图以一个段落添加到文档中。不过,我尝试运行代码时得到一个System.StackOverflowException错误。
没有任何人有任何想法,为什么发生这种情况,我该如何解决这个问题?



 公共覆盖无效的OnEndPage(PdfWriter作家,文档文件)
{
base.OnEndPage(作家,文件);
款P =新的段落(段落);
document.Add(对);
}


解决方案

禁止在一个页面事件使用 document.Add()。作为参数传递的文件对象实际上是一个 PdfDocument 对象。你应该使用它仅用于只读目的。这是记录在我的书的iText在行动 - 第二版



如果您要添加在的OnEndPage 法的内容,你需要在作家,例如 writer.DirectContent


In the code below, you can see that I overrode OnEndPage event and tried to add a paragraph to the document. However, I get an "System.StackOverflowException" error when attempting to run the code. Does anyone have any idea why this is happening and how can I fix it?

public override void OnEndPage(PdfWriter writer, Document document)
{
    base.OnEndPage(writer, document);
    Paragraph p = new Paragraph("Paragraph");
    document.Add(p);
}

解决方案

It is forbidden to use document.Add() in a page event. The document object passed as a parameter is actually a PdfDocument object. You should use it for read-only purposes only. This is documented in my book iText in Action - Second Edition.

If you want to add content in the OnEndPage method, you need the writer, for instance writer.DirectContent.

这篇关于"'System.StackOverflowException"在"&的OnEndPage QUOT;事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆