FPDF_LoadPage returns NULL meaning

235 views
Skip to first unread message

Markoce

unread,
Jun 7, 2022, 2:01:27 PM6/7/22
to pdfium
We recently ran into a case where calling FPDF_LoadPage returned NULL. What are some ways we can interpret this? Also, is it valid to FPDF_GetLastError when that function returns NULL? Many functions explicitly say to call FPDF_GetLastError if there was an issue, and this one does not, so I am assuming the error code would me meaningless if we did?

We are sure we gave a page index that is in bounds as it is a 1 page PDF and we passed in 0.. We also already checked if the Document object being passed in is NULL.

geisserml

unread,
Jun 7, 2022, 5:07:12 PM6/7/22
to pdfium
There is the error code FPDF_ERR_PAGE ("Page not found or content error") [1], so I would assume a meaningful return value of FPDF_GetLastError() in this case.
If possible, could you please share the document in question? It sounds like an interesting test case.

Lei Zhang

unread,
Jun 7, 2022, 5:09:31 PM6/7/22
to Markoce, pdfium
Some PDFs contain bad pages. e.g. 3 page document with valid pages 1
and 3, but page 2 points at a non-existent object. In which case,
FPDF_LoadPage() would return NULL for page 2.

On Tue, Jun 7, 2022 at 11:04 AM Markoce <abacefabm...@gmail.com> wrote:
>
> We recently ran into a case where calling FPDF_LoadPage returned NULL. What are some ways we can interpret this? Also, is it valid to FPDF_GetLastError when that function returns NULL? Many functions explicitly say to call FPDF_GetLastError if there was an issue, and this one does not, so I am assuming the error code would me meaningless if we did?
>
> We are sure we gave a page index that is in bounds as it is a 1 page PDF and we passed in 0.. We also already checked if the Document object being passed in is NULL.
>
> --
> 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/2e55524e-f393-4571-8b0f-2db645ae4c0an%40googlegroups.com.

Bupo Zhuang

unread,
Jun 24, 2022, 3:38:10 AM6/24/22
to pdfium
I had the same problem, FPDF_LoadPage returns NULL but FPDF_GetLastError return success.  what's the meaning?

Lei Zhang

unread,
Jun 24, 2022, 1:15:18 PM6/24/22
to Bupo Zhuang, pdfium
Same answer as before. Assuming the input parameters are correct, a
NULL return value means the page failed to load, as defined in the
FPDF_LoadPage() documentation.

IIRC, FPDF_GetLastError() only works for the document loading APIs,
and not in the general case for any arbitrary API.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/f581a9d8-98d7-4771-8a6e-1db6836fb9fbn%40googlegroups.com.

geisserml

unread,
Jun 24, 2022, 4:41:27 PM6/24/22
to pdf...@googlegroups.com
The outdated Foxit documentation still mentions FPDF_GetLastError() in
FPDF_LoadPage(). Does this mean the error handling behaviour has changed
throughout the history of PDFium?

Lei Zhang

unread,
Jun 24, 2022, 4:55:14 PM6/24/22
to geisserml, pdf...@googlegroups.com
Not much has changed throughout the history of PDFium w.r.t.
FPDF_GetLastError(). One can sync PDFium back to 2014, examine the
code, and see FPDF_GetLastError() behaves similar to the way it does
today. The Foxit documentation is simply incorrect when it talks about
FPDF_GetLastError().
> --
> 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/95abfc91-c171-a4cb-995f-4c016003c52e%40gmail.com.
Reply all
Reply to author
Forward
0 new messages