2016-11-08 40 views

回答

1

下面是从图像创建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来插入,删除和重新排序页面。

相关问题