2011-08-09 78 views

回答

2

您可以随时在您自己的IPdfPageEvent接口实现中声明您的变量。然后您就可以在IPdfPageEvent实现之外的任何位置设置该变量的值。

writer.PageEvent.variable = "Some value"; 

使用的OnStartPage事件,你可以这样做:

public class MyPageEvent:IPdfPageEvent 
{ 
    public string variable=""; 
public void OnStartPage(PdfWriter writer, Document document) 
{ 
     PdfContentByte cb = riter.DirectContent;; 
     cb.BeginText(); 
     cb.SetFontAndSize(myBaseFont, 10f); 
     cb.SetTextMatrix(600, 15); 
     cb.ShowText(this.variable); 
     cb.EndText(); 
} 
...... 
} 
1

不知道,如果你仍然需要一个答案,但什么我目前做的是铸造我pdfwriter。 pageevent对象直到显式子类,然后在该子类中设置公共属性。

CType(pdfWriter.PageEvent, PDFDocEventHelper).currentValue = value 

和子类PdfPageEventHelper类:

Public Class PDFDocEventHelper 
Inherits PdfPageEventHelper 

Public Property currentValue as String 
. 
. 
. 
End Class 

有意义

在课堂生成PDF

?我并不喜欢使用CType(),但它似乎工作。

相关问题