I'd like to change the background color of a pdf with apples PDFKit framework in Swift, but it doesn't work. It's not a problem to create some controls like a text or image and then use it but I want to change the color of the document itself. Does anyone have any idea or solution?
let renderer = UIGraphicsPDFRenderer(bounds: pageRect, format: format)
let data = renderer.pdfData { (context) in
context.beginPage()
let attributes = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12),
NSAttributedString.Key.backgroundColor : UIColor.green
]
let text = "My pdf"
text.draw(in: CGRect(x: 0, y: 0, width: 200, height: 20), withAttributes: attributes)
//?
UIColor.blue.setFill()
UIColor.blue.setStroke()
//?
context.cgContext.setFillColor(cyan: 1.0, magenta: 1.0, yellow: 0.6, black: 1.0, alpha: 1.0)
}
return data