{"record":{"id":"dbb9558b84ced36d","repo":"docusealco/docuseal","slug":"page-is-closed","errorCode":null,"errorMessage":"Page is closed.","messagePattern":"Page is closed\\.","errorType":"exception","errorClass":"Pdfium::PdfiumError","httpStatus":null,"severity":"error","filePath":"lib/pdfium.rb","lineNumber":1016,"sourceCode":"      Pdfium.FPDFPage_FixFormFields(form_handle, @page_ptr)\n    end\n\n    def load_page_view\n      return if @page_view || form_handle.null?\n\n      Pdfium.FORM_OnAfterLoadPage(@page_ptr, form_handle)\n\n      @page_view = true\n    end\n\n    def closed?\n      @closed\n    end\n\n    delegate :form_handle, to: :@document\n\n    def ensure_not_closed!\n      raise PdfiumError, 'Page is closed.' if closed?\n\n      @document.ensure_not_closed!\n    end\n\n    def render_to_bitmap(width: nil, height: nil, scale: nil, background_color: 0xFFFFFFFF,\n                         flags: FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT | FPDF_REVERSE_BYTE_ORDER)\n      ensure_not_closed!\n\n      render_width, render_height = calculate_render_dimensions(width, height, scale)\n\n      bitmap_ptr = Pdfium.FPDFBitmap_Create(render_width, render_height, 1)\n\n      if bitmap_ptr.null?\n        Pdfium.check_last_error('Failed to create bitmap (potential pre-existing error)')\n\n        raise PdfiumError, 'Failed to create bitmap (FPDFBitmap_Create returned NULL)'\n      end\n","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/docusealco/docuseal/blob/004a22c1c88109c7ba0b567df011a8cb13894001/lib/pdfium.rb#L998-L1034","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nPdfium::Document.open_file(path) { |d| @page = d.get_page(0) }\n@page.text # raises Page is closed.\n\n# after\nPdfium::Document.open_file(path) do |doc|\n  @text = doc.get_page(0).text\nend","handlingStrategy":"validation","validationCode":"def page_usable?(page)\n  !page.closed? && !page.document.closed?\nend\n\npage = doc.get_page(idx) unless page_usable?(page)","typeGuard":null,"tryCatchPattern":"begin\n  page.render_to_bitmap\nrescue Pdfium::PdfiumError => e\n  raise unless e.message == 'Page is closed.'\n  Pdfium::Document.open_file(@path) { |d| d.get_page(page.page_index).render_to_bitmap }\nend","preventionTips":["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"],"tags":["pdfium","lifecycle","use-after-free","ruby"],"backgroundTag":"use-after-close","analyzedSha":"004a22c1c88109c7ba0b567df011a8cb13894001","analyzedAt":"2026-08-21T13:38:23.343Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}