I have been using TPPDF to generate pdfs utilising tables. With the old version I was able to populate, set alignment and styles as per the code below.
The _bodyData [Array] is comprised of [String, String, UIImage as Any, String, UIImage as Any]
static func addTextTableBody(_bodyData: [Array<Any>], _bodyAlign: [Array<PDFTableCellAlignment>], _bodyWidth: Array<CGFloat>, _bodyStyle: [Array<PDFTableCellStyle>], _colHeaderCount: Int, _colHeaderStyle: PDFTableCellStyle, _rowHeaderStyle: PDFTableCellStyle, _contentStyle: PDFTableCellStyle, _altContentStyle: PDFTableCellStyle, _outlineStyle: PDFLineStyle, _padding: CGFloat, formType: Int) ->PDFTable {
let tableData = PDFTable()
// Tables can contain Strings, Numbers, Images or nil, in case you need an empty cell. If you add a unknown content type, an error will be thrown and the rendering will stop.
do {
try tableData.generateCells(
data: _bodyData,
alignments: _bodyAlign)
} catch PDFError.tableContentInvalid(let value) {
// In case invalid input is provided, this error will be thrown.
print("This type of object is not supported as table content: " + String(describing: (type(of: value))))
} catch {
// General error handling in case something goes wrong.
print("Error while creating table: " + error.localizedDescription)
}
// The widths of each column is proportional to the total width, set by a value between 0.0 and 1.0, representing percentage.
tableData.widths = _bodyWidth
// To speed up table styling, use a default and change it
let style = PDFTableStyleDefaults.simple
style.columnHeaderStyle = _colHeaderStyle
style.rowHeaderStyle = _colHeaderStyle
style.contentStyle = _colHeaderStyle
style.alternatingContentStyle = _colHeaderStyle
style.columnHeaderCount = _colHeaderCount
style.rowHeaderCount = 0
style.footerCount = 0
style.outline = _outlineStyle//PDFLineStyle(type: .full)
tableData.style = style
// Set table padding and margin
tableData.padding = _padding
tableData.margin = 0.0
return tableData
}
With the new version I have seen examples like this TPPDF Table Alignments How do I mix strings, ints, images into table data, when it appears the table content accepts data in the following form.
let tableData: [[String]] = [...] // This is your nested data
I would appreciate any help on this please.