def add_metadata(pdf, metadata, variant, version, conformance, compress):
    """Add PDF stream of metadata.

    Described in ISO-32000-1:2008, 14.3.2.

    """
    header = b'<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'
    footer = b'<?xpacket end="r"?>'
    xml_data = metadata.generate_rdf_metadata(metadata, variant, version, conformance)
    stream_content = b'\n'.join((header, xml_data, footer))
    extra = {'Type': '/Metadata', 'Subtype': '/XML'}
    metadata = pydyf.Stream([stream_content], extra, compress)
    pdf.add_object(metadata)
    pdf.catalog['Metadata'] = metadata.reference
Add PDF stream of metadata.

Described in ISO-32000-1:2008, 14.3.2.
weasyprint/pdf/metadata.py