Hello. I would like to create a custom element and Instantiate it from a page. In essence, I would like to create a usercontrol.
I have a class that inherits the PageElement. I have a page that creates MyClass and adds the 'control' to the Elements collection. However when I call DrawToWeb() it throws an error: "Collection was modified".
Is this a limitation of Dynamic PDF?
Public Class MyClass
Inherits ceTe.DynamicPDF.PageElement
Public Overrides Sub Draw(ByVal writer As ceTe.DynamicPDF.IO.PageWriter)
Dim MyGroup As Group = New Group
MyGroup.Add(New Label("Sub-element added", 0, 0, 120, 12))
writer.Page.Elements.Add(MyGroup)
End Sub
End Class
Partial Public Class ReportsTest
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mydoc As Document = New Document
Dim mypage As ceTe.DynamicPDF.Page = New ceTe.DynamicPDF.Page
'This works. I can add the label
'mypage.Elements.Add(New Label("Hello!", 0, 0, 100, 12, Font.Helvetica, 12))
mypage.Elements.Add(New MyClass())
mydoc.Pages.Add(mypage)
mydoc.DrawToWeb()
End Sub
End Class
Custom element
Re: Custom element
Support · Nov 10, 2011Hello,
Yes, you can create custom page element by inheriting the DynamicPDF page element. Please feel free to contact our support team at: [^a|mailto:support@cete.com|opennewiwndow|support@cete.com^] so that they can provide you the sample code for the same.
Thanks,
ceTe Software Support Team.
Re: Custom element
Forum member · Nov 10, 2011Yes, I have done that in the code snippet posted. However it appears that when overriding the Draw method, you have to physically draw an element. Is it not possible to leverage the built-in DynamicPDF elements and just return a Label element?
Re: Custom element
Forum member · Nov 10, 2011Thank you for the help. Your suggestion worked.
For future reference, this is the code suggested:
Public Class MyClass
Inherits ceTe.DynamicPDF.PageElements.Group
Public Overrides Sub Draw(ByVal writer As ceTe.DynamicPDF.IO.PageWriter)
Me.Add(New Label("Sub-element added", 0, 0, 120, 12))
MyBase.Draw(writer)
End Sub
End Class