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

How to add multiple pages? #26

Open
Saravana181187 opened this issue Mar 15, 2018 · 12 comments
Open

How to add multiple pages? #26

Saravana181187 opened this issue Mar 15, 2018 · 12 comments

Comments

@Saravana181187
Copy link

In my application the contents are exceeds more then one page means it overlaps at bottom of the page so I want to add multiple pages dynamically but unable to do that, please help me to find out the scenario.

@LarsGvB
Copy link

LarsGvB commented Mar 15, 2018

You can calculate with A4Papersize.height from the example how much you can fit on one page. I‘m using this for example to calculate how many tablerows I can fit on one page and save the overlapping ones to draw them later on the next page.

@Saravana181187
Copy link
Author

@LarsGvB can you give some extra details or sample of code please?

@LarsGvB
Copy link

LarsGvB commented Mar 15, 2018

Here is my code sample I use for tables:
`var extraPageNeeded = false
var extraRowHeights = CGFloat
var extraData = [NSMutableAttributedString]
let maxHeight = A4paperSize.height - pageHeaderFont.pointSize - (pageMargin * 2)
var numberOfRowsThatFit = 0
let rowHeightsToUse = rowHeights

// count the rows that fit on the page
while numberOfRowsThatFit < rowHeightsToUse.count && rowHeightsToUse.dropLast(rowHeightsToUse.count-numberOfRowsThatFit).reduce(0, +) <= maxHeight{
numberOfRowsThatFit += 1
}
numberOfRowsThatFit -= 1
let numberOfRowsThatDontFit = dataArray.count-numberOfRowsThatFit
let sumOfRowHeights = rowHeights.reduce(0, +)
// Check if additional page is needed
if sumOfRowHeights >= maxHeight{
extraPageNeeded = true

                // Save rows that don't fit
                extraRowHeights = [rowHeights.first!] + Array(rowHeights.dropFirst(numberOfRowsThatFit)) as [CGFloat]
                extraData = [dataArray.first!] + Array(dataArray.dropFirst(numberOfRowsThatFit)) as [[NSMutableAttributedString]]
                extraTables.append([extraRowHeights, numberOfRowsThatDontFit+1, extraData])
                
                // draw data that fits
                dataArray = Array(dataArray.dropLast(numberOfRowsThatDontFit)) as [[NSMutableAttributedString]]
                rowHeights = Array(rowHeights.dropLast(numberOfRowsThatDontFit)) as [CGFloat]
                rowCount = numberOfRowsThatFit

}
`
Later in code I draw the extraTables-Data.
Hope it is understandable and helps a little.

@LarsGvB
Copy link

LarsGvB commented Mar 15, 2018

I really don't know why the backtick markdown won't work properly here...

@Saravana181187
Copy link
Author

Sorry I don't Understand.. Are you clearly Understand my question..

@LarsGvB
Copy link

LarsGvB commented Mar 19, 2018

You want to know how to have content that exceed the size of one page splitted on multiple pages, right?

I showed my example of calculating where to split the data array if you have tables that don't fit.
The general approach is to use the pagesize and the pointsizes of your data to calculate how much fits on one page.

I don't have something implemented for all types of content. I only needed it in my application for the tables.

@Saravana181187
Copy link
Author

But I not used the tables only Images and text contents in pdf, please can you give details about this.

@LarsGvB
Copy link

LarsGvB commented Mar 19, 2018

I didnt do it for images or text, but I guess you can use the same approach. My first idea would be to have a variable that stores the currently used size and use % A4PaperSize to calculate when to add a beginNewPage().
Use the pointSizes of the fonts of the text and the height of the images.
I hope you get the idea. I‘m currently too busy with my own project to try it myself. If this appears to much coding adjustments for your needs I‘d recommend looking for another Framework that fits your needs better in this case.

@Saravana181187
Copy link
Author

Please can you recommend for another framework?

@LarsGvB
Copy link

LarsGvB commented Mar 20, 2018

Sorry I didnt test other frameworks for this.

@hitesh-shukla
Copy link

have you found any solution ?

@shashi-iitr
Copy link

shashi-iitr commented Aug 1, 2019

@Saravana181187
40

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

No branches or pull requests

4 participants