Swift UIImage convert as PDFDocument with PDFKit

106 views Asked by At

In my app i want to make PDFDocument from array of images, i use code below for this purpose, but my app crashes because of memory runs out, i used autoreleasepool but that doesn't help. What should i do?

import UIKit
import PDFKit


extension Array where Element: UIImage {
    
      func makePDF()-> PDFDocument? {
        let pdfDocument = PDFDocument()
        for (index,image) in self.enumerated() {
            let pdfPage = PDFPage(image: image)
            pdfDocument.insert(pdfPage!, at: index)
        }
        return pdfDocument
    }
}
0

There are 0 answers