Writes the PDF data into ``file_``. Note that ``file_`` can actually be a
    Django Response object as well.

    This function may be used as a helper that can be used to save a PDF file
    to a file (or anything else outside of a request/response cycle), eg::

    :param str html: A rendered HTML.
    :param file file_: A file like object (or a Response) where to output
        the rendered PDF.

def render_pdf(
    template,
    file_,
    url_fetcher=staticfiles_url_fetcher,
    context=None,
):
    """
    Writes the PDF data into ``file_``. Note that ``file_`` can actually be a
    Django Response object as well.

    This function may be used as a helper that can be used to save a PDF file
    to a file (or anything else outside of a request/response cycle), eg::

    :param str html: A rendered HTML.
    :param file file_: A file like object (or a Response) where to output
        the rendered PDF.
    """
    context = context or {}

    html = get_template(template).render(context)
    HTML(
        string=html,
        base_url='not-used://',
        url_fetcher=url_fetcher,
    ).write_pdf(
        target=file_,
    )