Я работаю над приложением PDF Builder и просмотрел этот учебник.
Есть ли способ добавить текст в ячейку с несколькими изображениями. Я пробовал разные способы, но это приводит к ошибке в PDF.
Я пробовал это:
let table = PDFTable()
let str = String(format: "Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
let str1 = String(format: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \n\nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. ")
do {
try table.generateCells(
data:[
["Name", "Image", "Description"],
[project.name + "\n" + project.address1, UIImage(named: "demo")!, str],
[project.name + "\n" + project.address1, UIImage(named: "demo")!, str1]
],
alignments: [
[.topLeft, .top, .top],
[.topLeft, .top, .top],
[.topLeft, .top, .top]
])
} 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)
}
table.widths = [
0.23, 0.30, 0.47
]
let style = PDFTableStyleDefaults.simple
table.style = style
do {
// Style each cell individually
try table.setCellStyle(row: 1, column: 0, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
try table.setCellStyle(row: 1, column: 1, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
try table.setCellStyle(row: 1, column: 2, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
try table.setCellStyle(row: 2, column: 0, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
try table.setCellStyle(row: 2, column: 1, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
try table.setCellStyle(row: 2, column: 2, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
} catch PDFError.tableIndexOutOfBounds(let index, let length){
// In case the index is out of bounds
print("Requested cell is out of bounds! \(index) / \(length)")
} catch {
// General error handling in case something goes wrong.
print("Error while setting cell style: " + error.localizedDescription)
}
table.padding = 1.0
table.margin = 2.0
table.showHeadersOnEveryPage = true
document.add(table: table)
Пожалуйста, помогите мне найти обходной путь. Спасибо.
0
Yama Puvar
21 Ноя 2019 в 16:06
1
Автор TPPDF (с ним можно связаться через страницу github) очень отзывчив и ответит на любой запрос, который вы ему отправите.
– Magnas
21 Ноя 2019 в 16:14
Нидертшайдер: Пожалуйста, помогите мне в этом. Спасибо.
– Yama
22 Ноя 2019 в 08:46
1 ответ
Лучший ответ
Прошу прощения, что не ответила раньше (как-то не уведомили).
- Попробуйте использовать группу внутри ячейки таблицы.
- Попробуйте новый API и логику таблицы (все еще в разработке, см. ветку
develop
), и если это все еще не решит вашу проблему, откройте новую проблему. Пожалуйста, предоставьте мне пример проекта кода, чтобы воспроизвести ваш вариант использования.
1
Phil Niedertscheider
16 Май 2020 в 12:20
Похожие вопросы
3
Обновите или перезагрузите UITableView после завершения действия удаления в подробном представлении
Новые вопросы
swift
Swift — это язык программирования общего назначения, разработанный Apple Inc., впервые выпущенный в 2014 году для своих платформ и Linux. Swift имеет открытый исходный код. Используйте тег только для вопросов о языковых функциях или необходимости кода в Swift. Используйте теги [ios], [ipados], [macos], [watch-os], [tvos], [swiftui], [cocoa-touch] и [cocoa] для (не зависящих от языка) вопросов о платформах или рамки.