2016-11-08 41 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來插入,刪除和重新排序頁面。

相關問題