I want to render a pdf page into an ui.Image without passing via a (WK)WebView because the draw_snapshot of a webview only works if it is presented.
Thus, I want to use this kind of objectivec code:
'''
func drawPDFfromURL(url: URL) -> UIImage? {
guard let document = CGPDFDocument(url as CFURL) else { return nil }
guard let page = document.page(at: 1) else { return nil }
let pageRect = page.getBoxRect(.mediaBox)
let renderer = UIGraphicsImageRenderer(size: pageRect.size)
let img = renderer.image { ctx in
UIColor.white.set()
ctx.fill(pageRect)
ctx.cgContext.translateBy(x: 0.0, y: pageRect.size.height)
ctx.cgContext.scaleBy(x: 1.0, y: -1.0)
ctx.cgContext.drawPDFPage(page)
}
return img
}
But I already meet a problem with the first line 😢 with the CFURLRef.
Can a guru help me to convert a string url ("file://.....") into this CFURLRef.
I think and hope that next lines would be easier to convert.
Thanks a lot