Crash when call FPDF_LoadPage function asynchronously

93 views
Skip to first unread message

Daniel Hu

unread,
Mar 1, 2024, 2:05:58 AMMar 1
to pdfium
Hello,

I want to get all annotations on every page, it's too slow and block the UI.
I modify to call FPDF_LoadPage function asynchronously which cause EXC_BAD_ACCESS crash.

sudo code:
let count = pageCount

let dispatchGroup = DispatchGroup()

for idx in 0..<count {
DispatchQueue.global().async(group: dispatchGroup) {
let pdfPage = FPDF_LoadPage((FPDF_DOCUMENT)self->document.data, idx)
let count = FPDFPage_GetAnnotCount(pdfPage)
print("\(count")
}
}

dispatchGroup.notify(queue: .main) {
    print("All tasks completed!")
}

Did pdfium support multiple thread? Is there any example about how to call FPDF_LoadPage function asynchronously?

Thank you.

K. Moon

unread,
Mar 1, 2024, 9:40:52 AMMar 1
to Daniel Hu, pdfium
PDFium does not support multiple threads. Even if it did, it's unlikely it would support multiple simultaneous calls to a single document.

--
You received this message because you are subscribed to the Google Groups "pdfium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/4daba74e-b14e-4de3-bba3-fb2c7eae938dn%40googlegroups.com.

DJRecipe

unread,
Mar 4, 2024, 5:38:55 AMMar 4
to K. Moon, Daniel Hu, pdfium
My advice is to load pages on demand. There are only a few situations which require multiple pages to be loaded ahead of time (e.g. changing a form field value which exists on multiple pages).

In general I'd advise to just load pages once you need to access them. (If you are definitely always accessing all of the pages then you are a bit out of luck)

Reply all
Reply to author
Forward
0 new messages