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 = []

      begin

View on GitHub (pinned to 004a22c1c8)

Solutions

  1. Re-open the original document and retry the redact once; transient serialization failures do occur
  2. Update libpdfium; GenerateContent regressions and fixes are frequent
  3. Reduce per-page edit complexity: redact fewer regions per pass
  4. 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

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


AI-assisted analysis of docusealco/docuseal@004a22c1c8 (2026-08-21). Data as JSON: /api/errors/7b4489cd753f7b3d. Report an issue: GitHub.