{% assert view_object.custom_html2pdf_template is defined %}

<div
  html2pdf-preloader
  class="main"
>
      <div
        html2pdf
        class="content"
      >
        {#-
          These go to the Front page templates:
          {% include "components/node_field/document_title/index.jinja" %}
          {% include "components/node_field/document_meta/index.jinja" %}
        -#}

        {% include "screens/document/pdf/toc.jinja" %}

        {#-
          To make the abstract and TOC appear on different pages,
          it should be set in the config like this:

          data-forced-page-break-selector='.free_text'
        -#}

        {%- for node, _ in view_object.document_content_iterator() %}

        {%- if node.is_requirement() %}
          {%- set sdoc_entity = node -%}
          {# {%- if node.is_text_node() %}
            {% include "components/text_node/pdf.jinja" %}
          {% else %} #}
            {% include "components/node_content/index_extends_readonly.jinja" %}
          {# {% endif %} #}

        {%- elif node.is_section() %}
          {# needed for self.local_anchor_cache: #}
          {%- set section = node %}
          {# needed for template: #}
          {%- set sdoc_entity = node -%}
          {% include "components/section/pdf.jinja" %}
        {%- endif %}

        {%- endfor %}

      </div>
</div>

{% if view_object.custom_html2pdf_template is none %}
{%- include "screens/document/pdf/template/frontpage.jinja" -%}
{%- include "screens/document/pdf/template/header.jinja" -%}
{%- include "screens/document/pdf/template/footer.jinja" -%}
{% else %}
  {{ view_object.custom_html2pdf_template.render(view_object=view_object) | safe }}
{% endif %}
