TPPDF icon indicating copy to clipboard operation
TPPDF copied to clipboard

Is there a way to keep a section as whole and not split between 2 pages?

Open icarus31 opened this issue 1 year ago • 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

icarus31 avatar Feb 18 '24 01:02 icarus31

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?

philprime avatar Apr 29 '24 06:04 philprime

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

icarus31 avatar Apr 29 '24 11:04 icarus31

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?

philprime avatar May 03 '24 13:05 philprime

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)

icarus31 avatar May 03 '24 15:05 icarus31

Ah now it makes more sense :)

Yes please test it and let me know if it worked out.

philprime avatar May 12 '24 14:05 philprime