class HexaPDF::Type::Page

def contents=(data)

or by creating a new one if no content stream exists.
This is done by deleting all but the first content stream and reusing this content stream;

Replaces the contents of the page with the given string.
def contents=(data)
  first, *rest = self[:Contents]
  rest.each {|stream| document.delete(stream) }
  if first
    self[:Contents] = first
    document.deref(first).stream = data
  else
    self[:Contents] = document.add({Filter: :FlateDecode}, stream: data)
  end
end