PDFDocument(data: myPdfDoc.dataRepresentation()) does not reproduce original PDF

I encounter a weird bug using PDFKit's PDFDocument.

I have an app with a PDFView and the user can drag & drop a PDF on it. On this event, I save the data representation (NSData) in my core-data structure

myCoreDataObject.pdfdata = myPDFView.dataRepresentation()

Later, the user can select the core data object to display the PDF, which calls

myPDFView.setDocument(PDFDocument(data: myCoreDataObject.pdfdata))

The PDF is correctly displayed in the PDFView BUT when the user selects text in it, copy-pastes it in another editor, the selection is made of empty(blank) characters ! Which was not the case with the original dragged-and-dropped PDF.

So my question is: WHY this code:

PDFDocument(data: myPdfDoc.dataRepresentation())

does not return the exact same PDF ?

IMPORTANT NOTE: this only happens with OCR'd PDF that have been through ABBY FineReader OCR.

Replies

yes it does

That is a very interesting answer, thank you. Yes indeed, it should, but it does not with that particular set of PDF.


I found a workaround by calling dataRepresentation() before doing anything. Then any consequent call on the document will work properly.


I had the same type of bug with selectionForLineAtPoint not working properly unless I would perform some method call before that.