Is there any way to achieve correct copying of text from pdf so that the line order is correct as on the original page. I am trying to copy text from a pdf file using PdfKit. But the text is copied sometimes (rarely enough) but with errors. Can anyone tell me why this is happening and how to avoid it.
func searchPDF() {
guard let path = Bundle.main.path(forResource: "Sample0102 (1)", ofType: "pdf") else {
print("PDF file not found")
return
}
// Create a URL object from the path
let url = URL(fileURLWithPath: path)
// Create a PDF document object from the URL
guard let pdfDocument = PDFDocument(url: url) else {
print("Could not create PDF document")
return
}
for i in 0 ..< pdfDocument.pageCount {
guard let pdfPage = pdfDocument.page(at: i) else {
continue
}
guard let pageText = pdfPage.string else {
continue
}
print (pageText)
}
}