2017-09-26 215 views
1

我實際上試圖在PDF上使用PDFKit註釋來繪製ink/freedraw註釋,但無法繪製註釋。使用PDFKIt創建PDF註釋iOS 11

在由apple提供的墨跡註釋中,有一種方法爲註釋添加Bezier路徑。

// Add or remove paths from the annotation. 
// Path points are specified in annotation space. 
// Used by annotations type(s): /Ink. 
open func add(_ path: UIBezierPath) 

即使添加了路徑,也不會在PDF上繪製註釋。 非常感謝您提供所有寶貴的答案。

+0

是否可以幫到我?我正在使用pdf套件,我需要運行編輯器來創建pdf。如果您有任何信息,如果可能的話,請通過您的代碼或幫助我在這個問題https://stackoverflow.com/questions/48609287/how-to-create-a-pdf-from-image-which-taken-by- camera-with-pdfkit –

+0

你好@nedaDerakhshesh其實我們是在PDFKit上做POC,由於缺乏適當的文檔,我們停止了這個工作。 –

回答

2

我不確定您是否有UIBezierPathPDFAnnotation的問題,但這裏是一個工作示例。

@IBOutlet weak var pdfView: PDFView! 

func addInkAnnotation() { 
    let rect = CGRect(x: 100.0, y: 100.0, width: 100.0, height: 20.0) 
    let annotation = PDFAnnotation(bounds: rect, forType: .ink, withProperties: nil) 
    annotation.backgroundColor = .blue 

    let pathRect = CGRect(x: 0.0, y: 0.0, width: 10.0, height: 10.0) 
    let path = UIBezierPath(rect: pathRect) 
    annotation.add(path) 

    // Add annotation to the first page 
    pdfView.document?.page(at: 0)?.addAnnotation(annotation) 
} 
+0

Rebacz我試圖執行這個,但沒有工作,你可以詳細說明 – Codicil

+0

'override func viewDidLoad(){super.viewDidLoad(); pdfView.document = pdfFile; addInkAnnotation()}' 就是這樣。 –

+0

對不起,我的無知,但你如何創建PDFView與PDFView屬性的出口,因爲用我的方法,我分配PDFView作爲運行文件的子視圖不註釋/不感應觸摸的筆 – Codicil