iTextSharp:无法在 PdfSmartCopy 编写器上附加 PageEvent
iTextSharp : Cannot attach PageEvent on a PdfSmartCopy writer
此代码使用 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" 时抛出 "Operation is not valid due to the current state of the object."(在执行无参数的 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();
有什么想法吗?
Pdf[Smart]Copy
类 用于 read-only 用法。它记录在原始源代码中:
/// 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 Documentation Comments using the <summary>
tag are used instead of the current style, comments will show up in Visual Studio IntelliSense。
此代码使用 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" 时抛出 "Operation is not valid due to the current state of the object."(在执行无参数的 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();
有什么想法吗?
Pdf[Smart]Copy
类 用于 read-only 用法。它记录在原始源代码中:
/// 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 Documentation Comments using the <summary>
tag are used instead of the current style, comments will show up in Visual Studio IntelliSense。