Skip to content

Instantly share code, notes, and snippets.

@ockham
Created November 7, 2013 21:30
Show Gist options
  • Save ockham/7362154 to your computer and use it in GitHub Desktop.
Save ockham/7362154 to your computer and use it in GitHub Desktop.
diff --git a/gourmet/plugins/import_export/pdf_plugin/pdf_exporter.py b/gourmet/plugins/import_export/pdf_plugin/pdf_exporter.py
index e9fb2c1..f77cc7c 100644
--- a/gourmet/plugins/import_export/pdf_plugin/pdf_exporter.py
+++ b/gourmet/plugins/import_export/pdf_plugin/pdf_exporter.py
@@ -4,6 +4,8 @@ from reportlab.lib.units import inch,mm
import reportlab.platypus as platypus
import reportlab.lib.pagesizes as pagesizes
import reportlab.lib.styles as styles
+from reportlab.pdfbase import pdfmetrics
+from reportlab.pdfbase.ttfonts import TTFont
from gettext import gettext as _
from gettext import ngettext
from gourmet import convert
@@ -227,6 +229,10 @@ class PdfWriter:
self.doc.frame_width = frames[0].width
self.doc.frame_height = frames[0].height
self.styleSheet = styles.getSampleStyleSheet()
+
+ pdfmetrics.registerFont(TTFont('FreeSans', "/usr/share/fonts/truetype/freefont/FreeSans.ttf"))
+ self.styleSheet.add(styles.ParagraphStyle(name='MyStyle', fontName='FreeSans', fontSize=12, leading=12))
+
perc_scale = float(base_font_size)/self.styleSheet['Normal'].fontSize
if perc_scale!=1.0:
self.scale_stylesheet(perc_scale)
@@ -327,7 +333,7 @@ class PdfWriter:
xmltxt = '<para %s>%s</para>'%(attributes,txt)
else:
xmltxt = '<para>%s</para>'%txt
- if not style: style = self.styleSheet['Normal']
+ if not style: style = self.styleSheet['MyStyle']
try:
if PASS_REPORTLAB_UNICODE:
return platypus.Paragraph(unicode(xmltxt),style)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment