Changing from landscape to portrait orientation in ReportLab.

3773
0
03-11-2013 02:02 PM
WinnKetchum
New Contributor III
For all of those who may use Reportlab,

I have a newbie question (should be simple to answer) that has been bugging me for the past day or so and after pouring over all online posts related to reportlab still can't be figured out.  All I am trying to do is switch from landscape to portrait orientation in the same document.  This will allow me to create a table of features (including links to the pictures of these within the table) and then put in the pictures so they can be linked to.

Here is the code I have come up with so far to facilitate what should be a straight forward process:
[INDENT]from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, landscape
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Frame, Table, TableStyle, NextPageTemplate, PageTemplate, BaseDocTemplate
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus.flowables import Flowable, PageBreak
from pyPdf import PdfFileReader, PdfFileWriter
import glob, os
from reportlab.lib.pagesizes import letter, A4

doc = BaseDocTemplate("M:\GIS Mapping Services\Promotional\Automated Reports\PDF_ReportLab\NextPageExample.pdf",showBoundary=1,pagesize=landscape(letter))
elements = []
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='normal', fontSize=6, leading = 7, alignment=TA_LEFT))

ptemplate = PageTemplate(id='portrait', pagesize=portrait(letter))
elements.append(Paragraph("Table is here.",styles["normal"]))
elements.append(NextPageTemplate('portrait'))
elements.append(PageBreak())
elements.append(Paragraph("Pictures are to be placed here.",styles["normal"]))

doc.build(elements)
del elements
[/INDENT]
If you have any tips or would like to help me out with this can you please be specific and show me exactly what I am doing wrong or include a working example that goes from start to finish without any coding missing. 

Thank you in advance for your help,

Winn
Tags (2)
0 Kudos
0 Replies