docusealco/docuseal · error · Pdfium::PdfiumError
Failed to remove page object
Error message
Failed to remove page object
What it means
Raised by remove_page_object when FPDFPage_RemoveObject returns 0: pdfium declined to detach the object from the page, which happens when the object is not owned by that page, was already removed, or the page's object list is in an unexpected state. It is reached from the redaction paths (remove_redacted_chars, remove_blank_text_objects, unwrap_form_objects) that collected object pointers before other edits may have invalidated them.
Source
Thrown at lib/pdfium.rb:1396
char[:origin_x], char[:origin_y]])
Pdfium.FPDFPageObj_SetMatrix(new_object, matrix_ptr)
Pdfium.FPDFPage_InsertObject(@page_ptr, new_object)
end
end
def reset_memoization
remove_instance_variable(:@text) if defined?(@text)
@text_nodes = nil
@text_objects = nil
@line_nodes = nil
@annotations = nil
@objects = nil
end
def remove_page_object(object_ptr)
raise PdfiumError, 'Failed to remove page object' if Pdfium.FPDFPage_RemoveObject(@page_ptr, object_ptr).zero?
Pdfium.FPDFPageObj_Destroy(object_ptr)
end
def draw_redaction_rects(rect_bounds)
rect_bounds.each do |left, bottom, right, top, color|
next if color == 'white'
rect_object = Pdfium.FPDFPageObj_CreateNewRect(left, bottom, right - left, top - bottom)
raise PdfiumError, 'Failed to create redaction rect' if rect_object.null?
Pdfium.FPDFPageObj_SetFillColor(rect_object, 0, 0, 0, 255)
Pdfium.FPDFPath_SetDrawMode(rect_object, 1, 0)
Pdfium.FPDFPage_InsertObject(@page_ptr, rect_object)
end
end
View on GitHub (pinned to 004a22c1c8)
Solutions
- Re-open the original document and apply the redaction in a single pass
- Merge overlapping/adjacent redaction rects for the same region before calling redact
- Update libpdfium
- If patching call sites, skip already-removed objects instead of failing the page
Example fix
# before rects = raw_rects # overlapping rects hit the same text objects twice page.redact(rects) # after - merge overlaps first to avoid double-removal of objects merged = merge_overlaps(raw_rects) page.redact(merged)
Defensive patterns
Strategy: fallback
Try / catch
begin
page.redact(rects)
rescue Pdfium::PdfiumError => e
raise unless e.message == 'Failed to remove page object'
merged = merge_overlapping_rects(rects)
Pdfium::Document.open_bytes(@original_bytes) { |d| d.get_page(page.page_index).redact(merged) }
end Prevention
- Merge overlapping redaction rects before calling redact so objects are not targeted twice
- Apply all redactions to a page in one pass; do not re-redact an edited page object
- Retry from original bytes when object-level edits fail midway
When it happens
Trigger: An object pointer collected in an earlier pass is removed again after the page changed; objects shared or cloned across pages after form unwrapping; a stale pointer following a failed FPDFPage_GenerateContent.
Common situations: Redacting pages where one text object overlaps multiple redaction rects; multi-step edits where earlier steps already restructured the object list.
Related errors
- Failed to unwrap form object
- Failed to get image matrix
- Failed to generate page content
- Failed to load text page
- Failed to create redaction rect
AI-assisted analysis of docusealco/docuseal@004a22c1c8 (2026-08-21).
Data as JSON: /api/errors/a208985f5f2828a1.
Report an issue: GitHub.