Converting uiimageview to pdf - Swift

后端 未结 3 1750
旧时难觅i
旧时难觅i 2020-12-15 13:33

I am trying to create an iOS app using swift that will let the user either take a photo or choose an image from their gallery, and convert it to a pdf file that they are abl

3条回答
  •  太阳男子
    2020-12-15 14:28

    in swift 5 using PDFKit : First Import PDFKit

    tan use this array Extension :

    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
        }
    }
    
    

    and use this :

    let imageArray = [UIImage(named: "1")!,UIImage(named: "2")!] let yourPDF = imageArray.makePDF()

提交回复
热议问题