Is there a way to keep a section as whole and not split between 2 pages?
Opened this issue · 5 comments
Hi,
First of all, great job for that tool!
I create a section
and wonder if it is possible to make sure it does not split between two pages?
For that case, should I use a group
instead?
Thanks
Hi there, sorry for the late response.
I am not entirely sure if I understand your case correctly.
Do I understand correctly, that you are using multiple columns in a section, but they should not extend to the next page?
No worries, I understand that you are not 100% dedicated to this superb project! :-)
So, what I meant is I have a section (see function below) that I want to make sure everything stick together if a new page is needed. Right now, it just cut the section in half between 2 pages. I would like to have similar behavior, like you do with a regular table. The new table row will move to the next page and not be truncated between 2 pages. Also, I don't want to see any lines for my section.
Is it something doable with a section. If not, you have an alternative to that?
pdfDocument!.add(section: myNewSection(with: item))
func myNewSection(with item: Item) -> PDFSection {
let section = PDFSection(columnWidths: [0.5, 0.5])
let itemImage = PDFImage(image: image, size: CGSize(width: 125, height: 125), sizeFit: .height)
section.columns[0].add(.center, image: nodeImage)
section.columns[1].add(.left, textObject: PDFSimpleText(text: "Info", style: self.h2Style))
section.columns[1].add(.left, space: 2.0)
section.columns[1].add(attributedText: item.description)
section.columns[1].add(attributedText: item.number)
section.columns[1].add(attributedText: item.name)
section.columns[1].add(attributedText: item.shortName)
return section
}
Thanks
PDFGroup would probably be the correct approach to keep the elements together.
Is there a reason why you are creating two columns but only adding content to the second one?
I will see what I can do with PDFGroup.
For the first column, I forgot a line in the example! :-)
section.columns[0].add(.center, image: itemImage)
Ah now it makes more sense :)
Yes please test it and let me know if it worked out.