简体   繁体   中英

Swift - Array of PDF pages to NSData

I am working on a Mac OS X PDF splitter program.

A PDF is loaded by the user, then some pages are selected to create a new PDF file, only with those pages.

I am using pdfThumbnailView.selectedPages() to select the pages, which return an array of PDF pages that correspond to the thumbnails selected in the thumbnail view.

Now I want to turn this into a NSData object, in order to build a new PDF with PDFDocument(data *data*: NSData!)

I tried to use NSKeyedArchiver , but my array is not compliant to NSCoding , making the program crash.

Does anyone have a good alternative to this ?

Thank you for your help.

For those who are going to see this, here is the solution I found: I used the func insertPage(page: PDFPage!, atIndex index: Int) method of PDFDocument to build a brand new PDF doc, in a for-in loop.

No need to use serialization, which was a bit overkill for what I wanted to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM