如何实现pdf编辑器 [英] how to implement pdf editor
本文介绍了如何实现pdf编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个应用程序,正在使用pdfkit
,它应该能够读取和编辑pdf文件.我发现iOS的编辑器本身就像下面的图片一样
I am working on an application and I am using pdfkit
which I should have the ability to read pdf files and edit them. I found that iOS has an editor like the image below it self
有什么方法可以在我的应用程序中实现类似的功能?我应该搜索什么?
is there any way to implement something like this one in my application? what should I searched for?
感谢任何帮助.谢谢
推荐答案
func createAndEditPDF() {
let pdfURL = NSURL(fileURLWithPath: self.selectedFile.fileURL); // URL of the existing PDF
if let pdf:CGPDFDocument = CGPDFDocument(pdfURL as CFURL) { // Create a PDF Document
let _newURL = "\(documentFolderPath)/\(self.selectedFile.name)"; // New URL to save editable PDF
let _url = NSURL(fileURLWithPath: _newURL)
var _mediaBox:CGRect = CGRect(x: 0, y: 0, width: pageWidth, height: pageHeight); // mediabox which will set the height and width of page
let _writeContext = CGContext(_url, mediaBox: &_mediaBox, nil) // get the context
//Run a loop to the number of pages you want
for i in 0..<self.pages.count
{
if let _page = pdf.page(at: self.pages[i]) { // get the page number
var _pageRect:CGRect = page.getBoxRect(CGPDFBox.mediaBox) // get the page rect
_writeContext!.beginPage(mediaBox: &_pageRect); // begin new page with given page rect
_writeContext!.drawPDFPage(_page); // draw content in page
_writeContext!.endPage(); // end the current page
}
}
}
}
这篇关于如何实现pdf编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文