2016-11-18 59 views
0

現在我可以用下面的代碼生成一個PDF生成可搜索的PDF。問題是,生成的PDF是不可搜索還是其文本可複製。 (就像整個PDF是一個圖像)。如何使用SWIFT

有沒有一種方法來創建一個有文字可複製/搜索使用的是iOS(SWIFT)一個PDF?生成的PDF我的代碼

部分:

let pdfFrame:CGRect = CGRect(x: 0, y: 0, width: sourceView.contentSize.width, height: sourceView.contentSize.height); 

UIGraphicsBeginPDFContextToFile(dataFilename, pdfFrame, nil); 
UIGraphicsBeginPDFPageWithInfo(pdfFrame, nil); 

sourceView.contentOffset = CGPoint.zero; 
sourceView.frame = pdfFrame; 
let pdfContext : CGContext = UIGraphicsGetCurrentContext()!; 
sourceView.layer.render(in: pdfContext); 

UIGraphicsEndPDFContext(); 

回答

1

爲了生成PDF是搜索,你需要創建一個包含文本的PDF文件。您的PDF只能使用圖像創建。您不能使用render(in:)。無論您想要在PDF中使用哪種文本,都需要將其繪製到PDF上下文中。一個例子見How to draw text in PDF context in Swift?

+0

謝謝。我會盡力而爲,如果有效,請投票。 – rsc