Use the PDFView / PDFKit Tutorial of
https://www.raywenderlich.com/4023941-creating-a-pdf-in-swift-with-pdfkit
After diving in into the topic and some calculations based in the PDF documentation, I ended up with the magic number: let cm = CGFloat(28.346)
, resulting in:
let cm = CGFloat(28.346) // 72.0 / 2.54, Resolution divided by conversion factor inch -> cm
let a4Width = CGFloat(21.0) // A4 width in cm
let a4Height = CGFloat(29.7) // A4 height in cm
let a4Paper = CGRect(x: 0, y: 0, width: cm * a4Width, height: cm * a4Height)
It comes from the resolution of 72.0
, mentioned in the tutorial, divided by the conversion factor from inch to cm, which is 2.54: 72.0 / 2.54 = 28.346
. So if you calculating in inch, you can just use 72.0 multiplied by the length in inch.