Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
icarus31 opened this issue Feb 18, 2024 · 5 comments
Open
Labels

Comments

@icarus31
Copy link

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

@philprime
Copy link
Member

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?

@icarus31
Copy link
Author

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

@philprime
Copy link
Member

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?

@icarus31
Copy link
Author

icarus31 commented May 3, 2024

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)

@philprime
Copy link
Member

Ah now it makes more sense :)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants