我有一个包含一些NS
Images的数组.
我主要想将NSImage转换为PDF.所以,任何人都可以告诉我如何在 Swift中做到这一点.
我主要想将NSImage转换为PDF.所以,任何人都可以告诉我如何在 Swift中做到这一点.
如果可能的话,你们能告诉我如何将PDF合并成一个并输出吗?
非常感谢.
解决方法
以下是从图像创建PDF文档的一些粗略步骤,这应该可以帮助您入门.
使用PDFKit(导入Quartz)框架.
// Create an empty PDF document let pdfDocument = PDFDocument() // Load or create your NSImage let image = NSImage(....) // Create a PDF page instance from your image let pdfPage = PDFPage(image: image!) // Insert the PDF page into your document pdfDocument.insert(pdfPage!,at: 0) // Get the raw data of your PDF document let data = pdfDocument.dataRepresentation() // The url to save the data to let url = URL(fileURLWithPath: "/Path/To/Your/PDF") // Save the data to the url try! data!.write(to: url)
您可能需要修改页面的边界和图像大小以获得所需的精确PDF页面大小.
您可以使用其他PDFDocument/PDFPage API来插入,删除和重新排序页面.