Created
July 19, 2012 13:47
-
-
Save frutik/3144038 to your computer and use it in GitHub Desktop.
How to create cyrillic pdf using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Trml2pdf library - https://github.com/roadhead/trml2pdf
You can download fonts here - http://dejavu-fonts.org/wiki/Download
Rml guide - http://www.reportlab.com/docs/rml2pdf-userguide.pdf, http://www.reportlab.com/docs/rml-for-idiots.pdf