<commit_before>==============================================
template2pdf: Converts tRML template to PDF
==============================================

**IMPORTANT: Kay support will be dropped.**

Great thanks to:
* The !ReportLab Project, for providing handy PDF interface to Python: http://www.reportlab.com/
* <NAME> of OpenERP, the original author of trml2pdf code.
* <NAME>, owner of !GitHub trml2pdf master: http://github.com/roadhead/trml2pdf/
* <NAME>, for early mention of trml2pdf in Japan: http://takaki-web.media-as.org/blog/ 

Usage
======

Writing tRML with template markups
-------------------------------------

<!DOCTYPE document SYSTEM "rml.dtd">
{% load pdf_tags %}
<document filename="{{ pdf_name }}">
  {% block template %}
  <template pagesize="({% block pagesize %}595, 841{% endblock %})" 
	    showBoundary="0">
    {% block template_content %}
    <pageTemplate id="main">
      {% block page_graphics %}
      <pageGraphics>
	{% block header %}
	{% endblock header %}
	{% block footer %}
	{% endblock footer %}
      </pageGraphics>
      {% endblock page_graphics %}
      {% block frame %}
      <frame id="content"
	     x1="{{ content_x1|default:"40" }}"
	     y1="{{ content_y1|default:"60" }}"
	     width="{{ content_width|default:"515" }}"
	     height="{{ content_height|default:"710" }}"/>
      {% endblock frame %}
      {% block extra_frames %}
      {% endblock extra_frames %}
    </pageTemplate>
    {% endblock template_content %}
  </template>
  {% endblock template %}
  {% block stylesheet %}
  <stylesheet>
    {% block styles %}
    <paraStyle name="Normal"
	       fontName="{% firstof normal_font_name font_name "Serif" %}"
	       fontSize="{% firstof normal_font_size font_size|default:"9" %}"
	       textColor="{% firstof normal_text_color text_color "black" %}"
	       wordWrap="CJK"
	       />
    {% endblock styles %}
    {% block extra_styles %}
    {% endblock extra_styles %}
  </stylesheet>
  {% endblock stylesheet %}
  {% block story %}
  <story>
    {% block story_content %}
    {% block content %}
    <para style="Normal">
      This is main content
    </para>
    {% endblock content %}
    {% endblock story_content %}
  </story>
  {% endblock story %}
</document>


Note:
* As normal Django templates, inheritance, filters, tags are available.
* Unfortunately tRML does not support cross references.

Rendering in a view
----------------------

# coding: utf-8

from template2pdf.dj import direct_to_pdf

def myview(request, template_name='somewhere/yourtemplate.rml'):
    params = {}
    # ... populate params in your order.
    return direct_to_pdf(request, template_name, params)

Hints:
* Setting Content-Disposition will tell your browser to download content as a file, instead of opening in it.<commit_msg>Code block indents.<commit_after>==============================================
template2pdf: Converts tRML template to PDF
==============================================

**IMPORTANT: Kay support will be dropped.**

Great thanks to:
* The !ReportLab Project, for providing handy PDF interface to Python: http://www.reportlab.com/
* <NAME> of OpenERP, the original author of trml2pdf code.
* <NAME>, owner of !GitHub trml2pdf master: http://github.com/roadhead/trml2pdf/
* <NAME>, for early mention of trml2pdf in Japan: http://takaki-web.media-as.org/blog/ 

Usage
======

Writing tRML with template markups
-------------------------------------

::
  <!DOCTYPE document SYSTEM "rml.dtd">
  {% load pdf_tags %}
  <document filename="{{ pdf_name }}">
    {% block template %}
    <template pagesize="({% block pagesize %}595, 841{% endblock %})" 
          showBoundary="0">
      {% block template_content %}
      <pageTemplate id="main">
        {% block page_graphics %}
        <pageGraphics>
      {% block header %}
      {% endblock header %}
      {% block footer %}
      {% endblock footer %}
        </pageGraphics>
        {% endblock page_graphics %}
        {% block frame %}
        <frame id="content"
           x1="{{ content_x1|default:"40" }}"
           y1="{{ content_y1|default:"60" }}"
           width="{{ content_width|default:"515" }}"
           height="{{ content_height|default:"710" }}"/>
        {% endblock frame %}
        {% block extra_frames %}
        {% endblock extra_frames %}
      </pageTemplate>
      {% endblock template_content %}
    </template>
    {% endblock template %}
    {% block stylesheet %}
    <stylesheet>
      {% block styles %}
      <paraStyle name="Normal"
             fontName="{% firstof normal_font_name font_name "Serif" %}"
             fontSize="{% firstof normal_font_size font_size|default:"9" %}"
             textColor="{% firstof normal_text_color text_color "black" %}"
             wordWrap="CJK"
             />
      {% endblock styles %}
      {% block extra_styles %}
      {% endblock extra_styles %}
    </stylesheet>
    {% endblock stylesheet %}
    {% block story %}
    <story>
      {% block story_content %}
      {% block content %}
      <para style="Normal">
        This is main content
      </para>
      {% endblock content %}
      {% endblock story_content %}
    </story>
    {% endblock story %}
  </document>


Note:
* As normal Django templates, inheritance, filters, tags are available.
* Unfortunately tRML does not support cross references.

Rendering in a view
----------------------

::
  # coding: utf-8

  from template2pdf.dj import direct_to_pdf

  def myview(request, template_name='somewhere/yourtemplate.rml'):
      params = {}
      # ... populate params in your order.
      return direct_to_pdf(request, template_name, params)

Hints:
* Setting Content-Disposition will tell your browser to download content as a file, instead of opening in it.
{'fraction_non_alphanumeric': 0.17987486965589156, 'fraction_numerical': 0.01007994438651373, 'mean_word_length': 2.8937753721244928, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7000475', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1601, 'n_words': 461}