Как установить защищенные паролем страницы в WeasyPrint PDF Builder?

Я хочу установить Защищенные паролем страницы в программеWeasyPrint PDF Builder.

Я генерирую PDF с помощью Weasyprint в Django и хочу, чтобы пароль был зашифрован после загрузки PDF файла.

** Вот код для генерации PDF файла.**


def build_pdf(request,html_content, header_html=None, footer_html=None):

    def get_page_body(boxes):
        for box in boxes:
            if box.element_tag == "body":
                return box

            return get_page_body(box.all_children())

    def get_page_and_body(html, css):
        if html is None:
            return None
        html = weasyprint.HTML(
            string=html,
            base_url=getattr(settings, "WEASYPRINT_BASEURL", None),
            url_fetcher=django_url_fetcher,
        )
        css += "@page { margin 0 !important; }"
        document = html.render(stylesheets=[weasyprint.CSS(string=css)])

        document_page = document.pages[0]
        document_body = get_page_body(document_page._page_box.all_children())
        return (
            document_page,
            document_body.copy_with_children(document_body.all_children()),
        )

    def preprocess_html(html, context):
        for key, value in context.items():
            html = html.replace(f"{{{{ {key} }}}}", str(value))            
        return html

    document = weasyprint.HTML(
        string=html_content,
        base_url=request.build_absolute_uri(),
        # base_url=getattr(settings, "WEASYPRINT_BASEURL", None),
        url_fetcher=django_url_fetcher,
    ).render()
            
    return document.write_pdf()

может ли кто-нибудь помочь мне?

Вернуться на верх