PDF Parsing with SWIFT

I want to parse a PDF that has no images, only text. I’m trying to find pieces of text. For example to search the string “Name:” and be able to read the characters after “:”.

I’m already able to open a PDF, get the number of pages, and to loop on them. The problem is when I want to use functions like CGPDFDictionaryGetStream or CGPDFStreamCopyData, because they use pointers. I have not found much info on the internet for swift programmers.

  • Digitally sign a pdf document in iOS
  • Generate table in PDF
  • How to Merge PDF file with Annotation
  • How to parse array from description in Swift 4?
  • Displaying PDF documents on iPad - Color Problems
  • iOS: Create PDF from UIView
  • Maybe the easiest way would be to parse all the content to an NSString. Then I could do the rest.

    Here my code:

    // Get existing Pdf reference
    let pdf = CGPDFDocumentCreateWithURL(NSURL(fileURLWithPath: path))
    let pageCount = CGPDFDocumentGetNumberOfPages(pdf);
    for index in 1...pageCount {
        let myPage = CGPDFDocumentGetPage(pdf, index)
        //Search somehow the string "Name:" to get whats written next