@@ -20,7 +20,7 @@ class TableExampleFactory: ExampleFactory {
2020 let document = PDFDocument ( format: . a4)
2121
2222 // Create a table
23- let table = PDFTable ( rows: 10 , columns: 4 )
23+ var table = PDFTable ( rows: 10 , columns: 4 )
2424
2525 // Tables can contain Strings, Numbers, Images or nil, in case you need an empty cell.
2626 // If you add a unknown content type, an assertion will be thrown and the rendering will stop.
@@ -85,6 +85,40 @@ class TableExampleFactory: ExampleFactory {
8585
8686 document. add ( table: table)
8787
88+ // Another table:
89+
90+ table = PDFTable ( rows: 50 , columns: 4 )
91+ table. widths = [ 0.1 , 0.3 , 0.3 , 0.3 ]
92+ table. margin = 10
93+ table. padding = 10
94+ table. showHeadersOnEveryPage = false
95+ table. style. columnHeaderCount = 3
96+
97+ for row in 0 ..< table. size. rows {
98+ table [ row, 0 ] . content = " \( row) " . asTableContent
99+ for column in 1 ..< table. size. columns {
100+ table [ row, column] . content = " \( row) , \( column) " . asTableContent
101+ }
102+ }
103+
104+ for i in stride ( from: 3 , to: 48 , by: 3 ) {
105+ table [ rows: i... ( i + 2 ) , column: 1 ] . merge ( with: PDFTableCell ( content: Array ( repeating: " \( i) ,1 " , count: 3 ) . joined ( separator: " \n " ) . asTableContent,
106+ alignment: . center) )
107+ }
108+ for i in stride ( from: 4 , to: 47 , by: 3 ) {
109+ table [ rows: i... ( i + 2 ) , column: 2 ] . merge ( with: PDFTableCell ( content: Array ( repeating: " \( i) ,2 " , count: 3 ) . joined ( separator: " \n " ) . asTableContent,
110+ alignment: . center) )
111+ }
112+ for i in stride ( from: 5 , to: 48 , by: 3 ) {
113+ table [ rows: i... ( i + 2 ) , column: 3 ] . merge ( with: PDFTableCell ( content: Array ( repeating: " \( i) ,3 " , count: 3 ) . joined ( separator: " \n " ) . asTableContent,
114+ alignment: . center) )
115+ }
116+
117+ table [ rows: 0 ..< 2 , column: 2 ] . merge ( )
118+ table [ rows: 1 ..< 3 , column: 3 ] . merge ( )
119+
120+ document. add ( table: table)
121+
88122 return [ document]
89123 }
90124}
0 commit comments