docusealco/docuseal · error · Pdfium::PdfiumError
Page is closed.
Error message
Page is closed.
What it means
Guard raised by Page#ensure_not_closed! before page operations such as render_to_bitmap, text, and annotations. A page becomes closed when page.close is called or when its document closes (Document#close closes every cached page), so later use would dereference a dead native handle; the guard turns that into a Ruby exception. It also delegates to the document's closed check, so a closed document surfaces as this error when access goes through a page.
Source
Thrown at lib/pdfium.rb:1016
Pdfium.FPDFPage_FixFormFields(form_handle, @page_ptr)
end
def load_page_view
return if @page_view || form_handle.null?
Pdfium.FORM_OnAfterLoadPage(@page_ptr, form_handle)
@page_view = true
end
def closed?
@closed
end
delegate :form_handle, to: :@document
def ensure_not_closed!
raise PdfiumError, 'Page is closed.' if closed?
@document.ensure_not_closed!
end
def render_to_bitmap(width: nil, height: nil, scale: nil, background_color: 0xFFFFFFFF,
flags: FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT | FPDF_REVERSE_BYTE_ORDER)
ensure_not_closed!
render_width, render_height = calculate_render_dimensions(width, height, scale)
bitmap_ptr = Pdfium.FPDFBitmap_Create(render_width, render_height, 1)
if bitmap_ptr.null?
Pdfium.check_last_error('Failed to create bitmap (potential pre-existing error)')
raise PdfiumError, 'Failed to create bitmap (FPDFBitmap_Create returned NULL)'
end
View on GitHub (pinned to 004a22c1c8)
Solutions
- Do all page work inside the document's open block
- Check page.closed? and page.document.closed? before reuse
- When a retry needs the page again, re-open the document and re-fetch pages
Example fix
# before
Pdfium::Document.open_file(path) { |d| @page = d.get_page(0) }
@page.text # raises Page is closed.
# after
Pdfium::Document.open_file(path) do |doc|
@text = doc.get_page(0).text
end Defensive patterns
Strategy: validation
Validate before calling
def page_usable?(page) !page.closed? && !page.document.closed? end page = doc.get_page(idx) unless page_usable?(page)
Try / catch
begin
page.render_to_bitmap
rescue Pdfium::PdfiumError => e
raise unless e.message == 'Page is closed.'
Pdfium::Document.open_file(@path) { |d| d.get_page(page.page_index).render_to_bitmap }
end Prevention
- Scope all page work inside the owning document's open block
- Do not cache Page objects in long-lived collections (ivars, memoized helpers)
- Design retries to re-open the document, not to reuse stale pages
When it happens
Trigger: Rendering or extracting text from a page after the Document.open block ended; calling page methods after doc.close; retry loops that reuse Page objects from a previous, already-closed iteration.
Common situations: Thumbnail/preview jobs that store Page objects beyond the document lifetime; view code receiving pages instead of rendered output; async pipelines that close the doc while a queued page task still runs.
Related errors
- Document is closed.
- Failed to create new document
- Failed to load document from file '#{file_path}', pointer is
- Failed to load document from memory, pointer is NULL.
- Failed to load document from IO, pointer is NULL.
AI-assisted analysis of docusealco/docuseal@004a22c1c8 (2026-08-21).
Data as JSON: /api/errors/dbb9558b84ced36d.
Report an issue: GitHub.