Skip to content

Instantly share code, notes, and snippets.

@sonukapoor
Created March 3, 2009 15:00
Show Gist options
  • Save sonukapoor/73355 to your computer and use it in GitHub Desktop.
Save sonukapoor/73355 to your computer and use it in GitHub Desktop.
Public Class RenderUnit
' 1 inch = 72 points
Public WidthPoints As Integer
Public HeightPoints As Integer
Public Items As IEnumerable
Public FileName As String
End Class
Public Interface IPDFGenerator
Function Generate(ByVal renderUnit As RenderUnit) As String
End Interface
Public Interface ILayoutHandler
Function Layout(ByVal widthInches As Integer, ByVal heightInches As Integer, ByVal items As IEnumerable) As RenderUnit
End Interface
Public Interface IDataSource
Function GetData() As IEnumerable
End Interface
Public Class PDFGenerator
Private ReadOnly generator As IPDFGenerator
Private ReadOnly layout As ILayoutHandler
Private ReadOnly dataSource As IDataSource
Public Sub New(ByVal generator As IPDFGenerator, ByVal layout As ILayoutHandler, ByVal dataSource As IDataSource)
Me.generator = generator
Me.layout = layout
Me.dataSource = dataSource
End Sub
Public Function Generate() As String
Dim dataItems As IEnumerable = dataSource.GetData()
Dim renderUnit As RenderUnit = layout.Layout(5, 7, dataItems)
Return generator.Generate(renderUnit)
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment