I'm using CGContext.init(withUrl) to create a pdf context and doing some rendering inside that context. I was able to save the pdf in the location which will be available in the url. But in my case i will not have a location while creating the CGContext. So in my case i need a create a CGPDFContext without the location. I tried using the CGDataConsumer, but that also not working.
My Requirements
1. Have to create PDF file without the save location.
2. In certain time interval i have to save that pdf to the particular location
My Requirements
1. Have to create PDF file without the save location.
2. In certain time interval i have to save that pdf to the particular location
Now i'm using the below code and it's working properly
var mediaBox = CGRect(x: 0, y: 0, width: 1000, height: 1000)
let mutableData = CFDataCreateMutable(nil, 0)!
let dataConsumer = CGDataConsumer.init(data: mutableData)!
let context = CGContext.init(consumer: dataConsumer, mediaBox: &mediaBox, nil)
context?.beginPage(mediaBox: nil)
some drawing operations
context.endPage()
after this i'm getting the file location from the user and saving the pdf file that location
do {
try (mutableData as NSData).write(to: location, options: .atomic)
} catch {
print(error)
}
var mediaBox = CGRect(x: 0, y: 0, width: 1000, height: 1000)
let mutableData = CFDataCreateMutable(nil, 0)!
let dataConsumer = CGDataConsumer.init(data: mutableData)!
let context = CGContext.init(consumer: dataConsumer, mediaBox: &mediaBox, nil)
context?.beginPage(mediaBox: nil)
some drawing operations
context.endPage()
after this i'm getting the file location from the user and saving the pdf file that location
do {
try (mutableData as NSData).write(to: location, options: .atomic)
} catch {
print(error)
}