Skip to content

Instantly share code, notes, and snippets.

@frutik
Created July 19, 2012 13:47
Show Gist options
  • Save frutik/3144038 to your computer and use it in GitHub Desktop.
Save frutik/3144038 to your computer and use it in GitHub Desktop.
How to create cyrillic pdf using python
import trml2pdf
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
enc = 'UTF-8'
pdfmetrics.registerFont(TTFont('DejaVuSans', 'DejaVuSans.ttf',enc))
pdfmetrics.registerFont(TTFont('DejaVuSans-Bold', 'DejaVuSans-Bold.ttf',enc))
open('/opt/kasta/test.pdf', 'w').write(trml2pdf.parseString(file('doc.rml','r').read()))
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="example_4.pdf">
<template>
<pageTemplate id="main">
<pageGraphics>
<image file="pict/1.png" x="0" y="0" width="550"/>
<setFont name="DejaVuSans" size="16"/>
<drawString x="100" y="700">Using RML with a templating system.</drawString>
</pageGraphics>
<fill color="black"/>
<frame id="first" x1="110mm" y1="190mm" width="80mm" height="80mm"/>
<frame id="second" x1="27mm" y1="139mm" width="163mm" height="42mm"/>
<frame id="trois" x1="27mm" y1="37mm" width="75mm" height="90mm"/>
<frame id="quatre" x1="112mm" y1="96mm" width="82mm" height="34mm"/>
<frame id="cinq" x1="112mm" y1="36mm" width="82mm" height="37mm"/>
</pageTemplate>
</template>
<stylesheet>
<paraStyle name="bigurl" fontName="DejaVuSans" fontSize="12" spaceBefore="0.5cm" textColor="red"/>
</stylesheet>
<story>
<para style="bigurl">тест тест тест</para>
</story>
</document>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment