1

此代码使用 ItextSharp 5.5.10:

 var msOutput = new MemoryStream();
 var document = new Document(PageSize.A4, 0, 0, 0, 20);
 var writer = new PdfSmartCopy(document, msOutput);
 writer.PageEvent = new MyHeaderFooterEvents();

抛出“由于对象的当前状态,操作无效。” 分配“writer.PageEvent”时(在执行无参数的 new Document() 时也会失败)。

当此代码完美运行时:

 var outputStream = new MemoryStream();
 var document = new Document(PageSize.A4, leftMargin, rightMargin, topMargin, bottomMargin);
 var writer = PdfWriter.GetInstance(document, outputStream);
 writer.PageEvent = new MyHeaderFooterEvents();

任何想法 ?

4

1 回答 1

3

这些Pdf[Smart]Copy类仅供只读使用。它记录在原始源代码中:

/// Setting page events isn't possible with Pdf(Smart)Copy.
/// Use the PageStamp class if you want to add content to copied pages.

iText 开发团队注意 - 如果使用标记的XML 文档注释<summary>而不是当前样式,注释将显示在 Visual Studio IntelliSense中。

于 2017-02-07T22:00:27.597 回答