PDFGroup
public class PDFGroup
Object used to dynamically add multiple elements to a document, but calculate them as one.
This way it is possible to add e.g. multiple PDFText elements and if the calculations require a page break, it can be disabled.
Additionally groups allow to set either an UIKit.UIColor / AppKit.NSColor as the backgroundColor
or even create a complex PDFDynamicGeometryShape which adapts to the group frame.
Example:
The following example will create a large text with multiple indentation levels. By setting allowsBreaks to false,
it won’t break the text, but move it to the next page in full.
let group = PDFGroup(
allowsBreaks: false,
backgroundColor: .green,
padding: UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 180)
)
for i in 0..<10 {
group.set(font: UIFont.systemFont(ofSize: 25))
group.set(indentation: 30 * CGFloat(i % 5), left: true)
group.set(indentation: 30 * CGFloat(i % 3), left: false)
group.add(text: "Text \(i)-\(i)-\(i)-\(i)-\(i)")
}
document.add(group: group)
See PDFGroupObject/draw(generator:container:in:) for internal implementation details
-
Flag to control if the group should allow page breaks inside, or if it should be moved to the next page in full.
Declaration
Swift
public var allowsBreaks: Bool -
Filling background color in the frame of the group
Will be overlayed by
backgroundImageandbackgroundShapeDeclaration
Swift
public var backgroundColor: Color? -
Outline style used if
backgroundColoris configured.Setting this value without
backgroundColorwill not have any effect.Declaration
Swift
public var outline: PDFLineStyle -
Filling background image in the frame of the group
Will overlay
backgroundColorand overlayed bybackgroundShapeDeclaration
Swift
public var backgroundImage: PDFImage? -
Filling background shape in the frame of the group
Will be overlay
backgroundColorandbackgroundImageDeclaration
Swift
public var backgroundShape: PDFDynamicGeometryShape? -
Inside padding of content to the edge
Useful to add a spacing between the content and the
outlineDeclaration
Swift
public var padding: EdgeInsets
-
Creates a new instance of
PDFGroupwith default configurationDeclaration
Swift
public init( allowsBreaks: Bool = false, backgroundColor: Color? = nil, backgroundImage: PDFImage? = nil, backgroundShape: PDFDynamicGeometryShape? = nil, outline: PDFLineStyle = .none, padding: EdgeInsets = .zero )
-
Adds a empty space in the given container, between the previous and the next element
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, space: CGFloat)Parameters
containerContainer where the space will be set
spaceSpace distance in points
-
Adds a horizontal line spearator to the given container. The line starts at the left indentation and ends at the right indentation. Customize by adjusting parameter
style.Declaration
Swift
func addLineSeparator(_ container: PDFGroupContainer = PDFGroupContainer.left, style: PDFLineStyle)Parameters
containerContainer where the space will be set
styleStyle of line
-
Adds an image to the given container.
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, image: PDFImage)Parameters
containerContainer where the space will be set
imageImage object
-
Adds an image row to the given container. This image row will fill the full available width between left indentation and right indentation.
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, imagesInRow: [PDFImage], spacing: CGFloat = 5.0)Parameters
containerContainer where the space will be set
imagesArray of images, from left to right
spacingHorizontal distance between images
-
Shorthand function to add a String text to the given container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, text: String, lineSpacing: CGFloat = 1.0)Parameters
containerContainer where the space will be set
imagesArray of images, from left to right
spacingHorizontal distance between images
-
Adds an text object to the given container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, textObject: PDFSimpleText)Parameters
containerContainer where the space will be set
textObjectSimple text object
-
Shorthand function to add a attributed String text to the given container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, attributedText: NSAttributedString)Parameters
containerContainer where the space will be set
textAn attributed string
-
Adds an attributed text object to the given container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, attributedTextObject: PDFAttributedText)Parameters
containerContainer where the space will be set
textObjectAttributed text object
-
Set font in given container. This text color will be used when adding a
PDFSimpleTextDeclaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, font: Font)Parameters
containerContainer where the font will be set
fontFont of text
-
Reset text color in given container to default.
Declaration
Swift
func resetFont(_ container: PDFGroupContainer = PDFGroupContainer.left)Parameters
containerContainer whose text color will be reset
-
Set text color in given container. This text color will be used when adding a
PDFSimpleTextDeclaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, textColor: Color)Parameters
containerContainer where the text color will be set
colorColor of the text
-
Reset text color in given container to default.
Declaration
Swift
func resetTextColor(_ container: PDFGroupContainer = PDFGroupContainer.left)Parameters
containerContainer whose text color will be reset
-
Adds a table object to the document in the defined container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, table: PDFTable)Parameters
containerContainer where the table will be added
tableAn instance of
PDFTable
-
Adds a list object to the document in the defined container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, list: PDFList)Parameters
containerContainer where the list will be added
tableAn instance of
PDFList
-
Change the indentation in a container, use the parameter
leftto define from which side.Declaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, indentation: CGFloat, left: Bool)Parameters
containerContainer whose indentation should be changed
indentPoints from the side
leftIf
truethen the left side indentation is set, else the right indentation is set -
Change the absolute top offset in a container
Declaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, absoluteOffset: CGFloat)Parameters
containerContainer whose current absolute offset should be changed
offsetPoints from the top
View on GitHub
Install in Dash