From 4cd227481ace8bf029c7aaccf4c6575201e9862a Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 23 May 2001 22:14:08 +0000 Subject: [PATCH] Added the ability to add images if the python imaging library is installed svn: r50 --- gramps/src/PdfDoc.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gramps/src/PdfDoc.py b/gramps/src/PdfDoc.py index 44b3804d5..bfd2a6bdc 100644 --- a/gramps/src/PdfDoc.py +++ b/gramps/src/PdfDoc.py @@ -21,7 +21,7 @@ from TextDoc import * import reportlab.platypus.tables -from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak +from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak, Image from reportlab.rl_config import defaultPageSize from reportlab.lib.units import cm from reportlab.lib.colors import Color @@ -29,6 +29,12 @@ from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY import reportlab.lib.styles +try: + import PIL.Image + no_pil = 0 +except: + no_pil = 1 + def page_def(canvas,doc): canvas.saveState() canvas.restoreState() @@ -102,11 +108,14 @@ class PdfDoc(TextDoc): self.current_para = self.pdfstyles[style_name] self.my_para = self.style_list[style_name] self.text = "" + self.image = 0 def end_paragraph(self): - if self.in_table == 0: + if self.in_table == 0 and self.image == 0: self.story.append(Paragraph(self.text,self.current_para)) - self.story.append(Spacer(1,0.5*cm)) + self.story.append(Spacer(1,0.25*cm)) + else: + self.image = 0 def start_bold(self): self.text = self.text + '' @@ -135,7 +144,7 @@ class PdfDoc(TextDoc): colWidths=self.cur_table_cols, style=ts) self.story.append(tbl) - self.story.append(Spacer(1,0.5*cm)) + self.story.append(Spacer(1,0.25*cm)) self.in_table = 0 def start_row(self): @@ -194,6 +203,19 @@ class PdfDoc(TextDoc): self.col = self.col + self.span + def add_photo(self,name,x,y): + if no_pil == 0: + im = PIL.Image.open(name) + + nx,ny = im.size + scale = float(y)/float(nx) + act_width = int(nx * scale) + act_height = int(ny * scale) + + self.story.append(Image(name,act_width*0.5,act_height*0.5)) + self.story.append(Spacer(1,0.25*cm)) + self.image = 1 + def horizontal_line(self): pass