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

PUBLIC VARS

PUBLIC INITIALIZERS

Layout

  • 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

Lines

  • 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

Image

  • 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

Text

Table

List

Layout

  • 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