xcode - NSImages to PDFs and merge them in Swift -
i have array nsimages in it. want convert nsimage pdf. so, can show me how in swift.
if possible, guys show me how merge pdfs 1 , output well? thank much.
here rough steps create pdf document images, should started.
use pdfkit (import quartz) framework.
// create empty pdf document let pdfdocument = pdfdocument() // load or create nsimage let image = nsimage(....) // create pdf page instance image let pdfpage = pdfpage(image: image!) // insert pdf page document pdfdocument.insert(pdfpage!, at: 0) // raw data of pdf document let data = pdfdocument.datarepresentation() // url save data let url = url(fileurlwithpath: "/path/to/your/pdf") // save data url try! data!.write(to: url)
you may need tinker page's bounds , image size's exact pdf page sizes need.
you can use other pdfdocument/pdfpage api insert, remove , reorder pages.
Comments
Post a Comment