{"record":{"id":"7b4489cd753f7b3d","repo":"docusealco/docuseal","slug":"failed-to-generate-page-content","errorCode":null,"errorMessage":"Failed to generate page content","messagePattern":"Failed to generate page content","errorType":"exception","errorClass":"Pdfium::PdfiumError","httpStatus":null,"severity":"error","filePath":"lib/pdfium.rb","lineNumber":1164,"sourceCode":"      ensure_not_closed!\n\n      flatten\n      rotate\n\n      rect_bounds = rects.map do |rect|\n        left = rect['x'].to_f * width\n        top = height - (rect['y'].to_f * height)\n\n        [left, top - (rect['h'].to_f * height), left + (rect['w'].to_f * width), top, rect['color']]\n      end\n\n      unwrap_form_objects(rect_bounds)\n\n      remove_redacted_chars(rect_bounds)\n      redact_image_objects(rect_bounds, &image_processor) if image_processor\n      draw_redaction_rects(rect_bounds)\n\n      raise PdfiumError, 'Failed to generate page content' if Pdfium.FPDFPage_GenerateContent(@page_ptr).zero?\n\n      remove_blank_text_objects\n\n      @document.add_presave_hook(:cleanup) { @document.cleanup }\n\n      reset_memoization\n\n      nil\n    end\n\n    def remove_blank_text_objects\n      text_page = Pdfium.FPDFText_LoadPage(@page_ptr)\n\n      return if text_page.null?\n\n      blanks = []\n\n      begin","sourceCodeStart":1146,"sourceCodeEnd":1182,"githubUrl":"https://github.com/docusealco/docuseal/blob/004a22c1c88109c7ba0b567df011a8cb13894001/lib/pdfium.rb#L1146-L1182","documentation":"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.","triggerScenarios":"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.","commonSituations":"Redaction features on AcroForm/XFA-heavy forms and Word-exported PDFs; older libpdfium builds; documents previously processed by other tools.","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"],"exampleFix":"# before\ndef redact!(doc, rects)\n  doc.get_page(0).redact(rects)\nend\n\n# after\nbegin\n  doc.get_page(0).redact(rects)\nrescue Pdfium::PdfiumError\n  Pdfium::Document.open_bytes(@original_bytes) { |d| d.get_page(0).redact(rects) }\nend","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  page.redact(rects)\nrescue Pdfium::PdfiumError => e\n  raise unless e.message == 'Failed to generate page content'\n  Pdfium::Document.open_bytes(@original_bytes) do |doc| # clean retry from source\n    doc.get_page(page.page_index).redact(rects)\n  end\nend","preventionTips":["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"],"tags":["pdfium","redaction","content-generation","ruby"],"backgroundTag":"pdf-content-generation-failed","analyzedSha":"004a22c1c88109c7ba0b567df011a8cb13894001","analyzedAt":"2026-08-21T13:38:23.343Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}