docusealco/docuseal · error · Pdfium::PdfiumError
Failed to generate page content
Error message
Failed to generate page content
What it means
Raised at the end of Page#redact when FPDFPage_GenerateContent returns 0 after form unwrapping, character removal, image redaction, and rect drawing. There is no check_last_error; a zero return means pdfium could not serialize the modified page. By this point the page is already partially edited (forms unwrapped, objects removed), so the in-memory document must be treated as dirty and re-opened rather than saved.
Source
Thrown at lib/pdfium.rb:1164
ensure_not_closed!
flatten
rotate
rect_bounds = rects.map do |rect|
left = rect['x'].to_f * width
top = height - (rect['y'].to_f * height)
[left, top - (rect['h'].to_f * height), left + (rect['w'].to_f * width), top, rect['color']]
end
unwrap_form_objects(rect_bounds)
remove_redacted_chars(rect_bounds)
redact_image_objects(rect_bounds, &image_processor) if image_processor
draw_redaction_rects(rect_bounds)
raise PdfiumError, 'Failed to generate page content' if Pdfium.FPDFPage_GenerateContent(@page_ptr).zero?
remove_blank_text_objects
@document.add_presave_hook(:cleanup) { @document.cleanup }
reset_memoization
nil
end
def remove_blank_text_objects
text_page = Pdfium.FPDFText_LoadPage(@page_ptr)
return if text_page.null?
blanks = []
beginView on GitHub (pinned to 004a22c1c8)
Solutions
- Re-open the original document and retry the redact once; transient serialization failures do occur
- Update libpdfium; GenerateContent regressions and fixes are frequent
- Reduce per-page edit complexity: redact fewer regions per pass
- Fall back to a draw-only redaction (opaque rects, no character removal) for the problem page
Example fix
# before
def redact!(doc, rects)
doc.get_page(0).redact(rects)
end
# after
begin
doc.get_page(0).redact(rects)
rescue Pdfium::PdfiumError
Pdfium::Document.open_bytes(@original_bytes) { |d| d.get_page(0).redact(rects) }
end Defensive patterns
Strategy: retry
Try / catch
begin
page.redact(rects)
rescue Pdfium::PdfiumError => e
raise unless e.message == 'Failed to generate page content'
Pdfium::Document.open_bytes(@original_bytes) do |doc| # clean retry from source
doc.get_page(page.page_index).redact(rects)
end
end Prevention
- Keep the original bytes around until redact+save succeeds, so you can retry from a clean state
- Never save a document after a redact raised midway; pages are partially edited
- Pin a known-good libpdfium version and test redaction against a corpus of real-world PDFs
When it happens
Trigger: redact on pages with complex content streams or cross-reference streams; re-redacting an already heavily edited page; PDFs using content features the pdfium build's serializer cannot round-trip.
Common situations: Redaction features on AcroForm/XFA-heavy forms and Word-exported PDFs; older libpdfium builds; documents previously processed by other tools.
Related errors
- Failed to load text page
- Failed to unwrap form object
- Failed to remove page object
- Failed to create redaction rect
- Failed to get image matrix
AI-assisted analysis of docusealco/docuseal@004a22c1c8 (2026-08-21).
Data as JSON: /api/errors/7b4489cd753f7b3d.
Report an issue: GitHub.