docusealco/docuseal · error · Pdfium::PdfiumError
Failed to load text page #{page_index}, pointer is NULL.
Error message
Failed to load text page #{page_index}, pointer is NULL. What it means
Raised by Page#text when FPDFText_LoadPage returns NULL for the loaded page. check_last_error runs first and raises the error-code variant when PDFium recorded one, so this plain message means the text layer could not be built without a recorded code, typically a content stream pdfium cannot parse. A scanned PDF without OCR is not a failure (char_count of 0 returns an empty string), so this error signals actual structural damage.
Source
Thrown at lib/pdfium.rb:1063
bitmap_data = buffer_ptr.read_bytes(stride * render_height)
[bitmap_data, render_width, render_height]
ensure
Pdfium.FPDFBitmap_Destroy(bitmap_ptr) if bitmap_ptr && !bitmap_ptr.null?
end
def text
return @text if @text
ensure_not_closed!
text_page = Pdfium.FPDFText_LoadPage(page_ptr)
if text_page.null?
Pdfium.check_last_error("Failed to load text page #{page_index}")
raise PdfiumError, "Failed to load text page #{page_index}, pointer is NULL."
end
char_count = Pdfium.FPDFText_CountChars(text_page)
return @text = '' if char_count.zero?
buffer_char_capacity = char_count + 1
buffer = FFI::MemoryPointer.new(:uint16, buffer_char_capacity)
chars_written = Pdfium.FPDFText_GetText(text_page, 0, buffer_char_capacity, buffer)
if chars_written <= 0
Pdfium.check_last_error("Failed to extract text from page #{page_index}")
return @text = ''
end
View on GitHub (pinned to 004a22c1c8)
Solutions
- Confirm other pages extract fine to isolate a single bad page, and treat that page as having no text
- Repair the file externally (qpdf --decrypt or ghostscript re-distill) and retry
- Rescue per page and continue the job rather than failing the whole document
- Update libpdfium; text-loading fixes ship in most releases
Example fix
# before
text = doc.pages.map(&:text).join
# after
text = doc.pages.filter_map do |page|
begin
page.text
rescue Pdfium::PdfiumError
'' # skip unparseable page
end
end.join Defensive patterns
Strategy: fallback
Try / catch
text = begin page.text rescue Pdfium::PdfiumError '' # unparseable page: no text rather than failed job end
Prevention
- Make text extraction per-page resilient; one damaged page should not kill the document job
- Run qpdf/ghostscript repair on uploads that fail text loading
- Keep libpdfium current
When it happens
Trigger: Calling page.text on a page whose content stream is corrupt; documents that only partially loaded; pages damaged by earlier failed edit operations on the same document object.
Common situations: Search/indexing pipelines over user uploads; text extraction from PDFs produced by broken generators; files that survived partial transfers.
Related errors
- Failed to load text page
- Failed to load page #{page_index}, pointer is NULL.
- Failed to create new document
- Failed to load document from file '#{file_path}', pointer is
- Failed to load document from memory, pointer is NULL.
AI-assisted analysis of docusealco/docuseal@004a22c1c8 (2026-08-21).
Data as JSON: /api/errors/4618a7c6218b5118.
Report an issue: GitHub.