How we can edit PDFPage Text in IOS swift 4?

995 Views Asked by At

I just want to edit PDFPage text , user click on edit button a box will be shown on each textBox rect and when user touch on any box then its text will be start editing and user able to remove all text and replace it with new one.

Here is my pdf page and i am currently using PDFKit in swift 4.
For batter understanding.

Here is some reference Images of FoxitPDF Reader. Hopefully it will be helpful.
1

2

3

1

There are 1 best solutions below

0
On

I think as follows. First of all, you need to get all strings of the page you want to edit from a PDF file.

if let pdf = PDFDocument(url: url) {
    let pageCount = pdf.pageCount
    let documentContent = NSMutableAttributedString()

    guard let page = pdf.page(at: "certain page") else { continue }
    guard let pageContent = page.attributedString else { continue }
    documentContent.append(pageContent)
}

And then you should show them on TextField or TextView when clicking the edit Button. So I think you can edit or remove the text you want. Finally you need to save the changes. I guess you know how can create a PDF with text so I'll not write about it. Hope it helps.