Skip to content

Commit

Permalink
Added justification to document.add_text
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina7479 committed Jul 22, 2014
1 parent 5a367c2 commit 5352911
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pypdflite/pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,24 @@ def print_available_fonts(self):
print PDFTTFont.available_fonts()

# Writing
def add_text(self, text, cursor=None):
def add_text(self, text, cursor=None, justification=None):
""" Input text, short or long. Writes in order, within the defined page boundaries. Sequential add_text commands will print without
additional whitespace. """
if cursor is None:
cursor = self.page.cursor

text = re.sub("\s\s+" , " ", text)

if justification is None:
justification = self.justification

if '\n' in text:
text_list = text.split('\n')
for text in text_list:
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, self.justification, self.double_spacing)
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, justification, self.double_spacing)
self.add_newline()
else:
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, self.justification, self.double_spacing)
PDFText(self.session, self.page, text, self.font, self.text_color, cursor, justification, self.double_spacing)

def draw_text(self, *args, **kwargs):
self.add_text(*args, **kwargs)
Expand Down

0 comments on commit 5352911

Please sign in to comment.