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
backgroundImage
andbackgroundShape
Declaration
Swift
public var backgroundColor: Color?
-
Outline style used if
backgroundColor
is configured.Setting this value without
backgroundColor
will not have any effect.Declaration
Swift
public var outline: PDFLineStyle
-
Filling background image in the frame of the group
Will overlay
backgroundColor
and overlayed bybackgroundShape
Declaration
Swift
public var backgroundImage: PDFImage?
-
Filling background shape in the frame of the group
Will be overlay
backgroundColor
andbackgroundImage
Declaration
Swift
public var backgroundShape: PDFDynamicGeometryShape?
-
Inside padding of content to the edge
Useful to add a spacing between the content and the
outline
Declaration
Swift
public var padding: EdgeInsets
-
Creates a new instance of
PDFGroup
with 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
container
Container where the space will be set
space
Space 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
container
Container where the space will be set
style
Style of line
-
Adds an image to the given container.
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, image: PDFImage)
Parameters
container
Container where the space will be set
image
Image 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
container
Container where the space will be set
images
Array of images, from left to right
spacing
Horizontal 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
container
Container where the space will be set
images
Array of images, from left to right
spacing
Horizontal distance between images
-
Adds an text object to the given container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, textObject: PDFSimpleText)
Parameters
container
Container where the space will be set
textObject
Simple 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
container
Container where the space will be set
text
An attributed string
-
Adds an attributed text object to the given container
Declaration
Swift
func add(_ container: PDFGroupContainer = PDFGroupContainer.left, attributedTextObject: PDFAttributedText)
Parameters
container
Container where the space will be set
textObject
Attributed text object
-
Set font in given container. This text color will be used when adding a
PDFSimpleText
Declaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, font: Font)
Parameters
container
Container where the font will be set
font
Font of text
-
Reset text color in given container to default.
Declaration
Swift
func resetFont(_ container: PDFGroupContainer = PDFGroupContainer.left)
Parameters
container
Container whose text color will be reset
-
Set text color in given container. This text color will be used when adding a
PDFSimpleText
Declaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, textColor: Color)
Parameters
container
Container where the text color will be set
color
Color of the text
-
Reset text color in given container to default.
Declaration
Swift
func resetTextColor(_ container: PDFGroupContainer = PDFGroupContainer.left)
Parameters
container
Container 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
container
Container where the table will be added
table
An 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
container
Container where the list will be added
table
An instance of
PDFList
-
Change the indentation in a container, use the parameter
left
to define from which side.Declaration
Swift
func set(_ container: PDFGroupContainer = PDFGroupContainer.left, indentation: CGFloat, left: Bool)
Parameters
container
Container whose indentation should be changed
indent
Points from the side
left
If
true
then 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
container
Container whose current absolute offset should be changed
offset
Points from the top