SimplePDF
SimplePDF copied to clipboard
How to add multiple pages?
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.
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.
@LarsGvB can you give some extra details or sample of code please?
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.
I really don't know why the backtick markdown won't work properly here...
Sorry I don't Understand.. Are you clearly Understand my question..
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.
But I not used the tables only Images and text contents in pdf, please can you give details about this.
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.
Please can you recommend for another framework?
Sorry I didnt test other frameworks for this.
have you found any solution ?
@Saravana181187 40